Listing City required in osclass - city

I the osclass When I post listing, choosing a city is not required. How can I make it required ?
When I select city, it shows in the post, but I also can post listing without selection the city, but I want the city to be required.

You have two ways to do it:
1- Hook method
Using the pre_item_post (osclass < 3.3) or pre_item_add (osclass >=3.4).
osc_add_hook("pre_item_add", function($aItem) {
if($aItem["city"] !== "") {
osc_add_flash_error_message(_e("Please select a city", "your_theme"));
$this->redirectTo(osc_item_post_url());
}
});
2- Javascript method
Using jQuery Validate, like in Bender theme.
$('.form-horizontal').validate({
rules: {
region: {
required: true
},
city: {
required: true
}
},
messages: {
region: {
required: "Please select a region"
},
city: {
required: "Please select a city"
}
}
});

Related

How do I create a GraphQL appSubscriptionCreate mutation with the Ruby shopify_api gem?

When I copy the example below from https://help.shopify.com/en/api/guides/billing-api/implement-your-business-model#implement-the-appsu...:
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: { amount: 10.00, currencyCode: USD }
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
and run it via the "Shopify GraphiQL App", the mutation is successfully created.
I am not sure how to do it with Ruby and the shopify_api gem though (note that I am new to Ruby as well as GraphQL, so it's probably something very basic I am missing, but I have not been able to find the answer anywhere).
I attempted the following:
##client = ShopifyAPI::GraphQL.new
PAYMENT_MUTATION = ##client.parse <<-'GRAPHQL'
{
mutation {
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: {
amount: 10.00,
currencyCode: USD
}
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
}
GRAPHQL
def initialize
#result = ##client.query(PAYMENT_MUTATION)
end
def confirmationUrl
#result.data.appSubscriptionCreate.confirmationUrl
end
end
I get the following error though:
GraphQL::Client::ValidationError (Field 'mutation' doesn't exist on type 'QueryRoot'):
I tried skipping the mutation part, but then I just get the error:
GraphQL::Client::ValidationError (Field 'appSubscriptionCreate' doesn't exist on type 'QueryRoot'):
This led me to have a look at the GraphQL class of the shopify_api gem, hoping to find a "mutation" method to use instead of the "query" method, but there is none.
I cannot figure it out from the graphql-client gem that shopify_api is using either - there's no mutation examples in the readme.
What am I missing?
Thanks,
-Louise
Got the answer on the Shopify forum - I just have to remove the outer {} in PAYMENT_MUTATION.
PAYMENT_MUTATION = ##client.parse <<-'GRAPHQL'
mutation {
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: {
amount: 10.00,
currencyCode: USD
}
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
GRAPHQL

Creative and Objective Mismatch while creating Carousal Ad by using Marketing API

I'm creating Carousel Ad via marketing API. During the Ad creation Facebook through "Creative and Objective Mis-match" error. However, Campaign and Adset are successfully creating.
I have changed the objective as per Facebook documentation. I tried multiple combinations but got errors. e.g: "Billing event invalid for optimisation goal, Creative and Objective Mismatch, Invalid Creative for Objective"
Doc_link
res = ad_account.ads.create({
status: 'ACTIVE',
name: ' SDK',
adset_id: adset.id,
creative: {
object_story_spec: {
page_id: fb_page_id,
link_data: {
child_attachments: [
{
description: "$8.99",
image_hash: "1ea34798e1ba00ffaab318dc",
link: "www.facebook.com",
name: "Product 1",
video_id: "42920500794",
call_to_action: {
type: "LEARN_MORE",
value: {
link: "www.facebook.com"
}
}
},
{
description: "$9.99",
image_hash: "8299deb1e053f7601c4f99f44",
link: "www.facebook.com",
name: "Product 2",
video_id: "378442876",
call_to_action: {
type: "LEARN_MORE",
value: {
link: "www.facebook.com"
}
}
},
],
:link => "www.facebook.com",
},
}
}
})
I need to create a complete carousel ad by using marketing API.

How to fetch category name of a venue from result object of fouresquare venue search?

I am developing an ios app using phonegap in which I am using foursquare venue search api for listing all the near by venues.
This is the code I have used to list the name of all the near by venues.
$.getJSON('https://api.foursquare.com/v2/venues/search?ll='+pos+'&radius=10000&client_id=2POUFAUU4ZBJ2MTDOY3S2YHR2NIT52FYW0LUTPHBMNTJFJNQ&client_secret=YFDZI1YWV3ZI5S5SPM2DZJEQIEBPIDJ5XFZBWTIKIQZVQNYM&v=20120101&limit=60',
function(data) {
console.log(pos);
$.each(data.response.venues, function(i,venues){
content = '<li id="list-item"> <p><a href="#reviewPage" onClick="reviewPageAction(this)">' + venues.name + '</li>';
/*$(content).appendTo("#names");*/
$(content).appendTo("#mer");
});
});
And now my problem is , I want to display the category name with name of each venue. I have tried the following code
venues.categories.name
but it didn't work.
Is it possible to fetch the category name of each venue.?? Please help me!!
The Venues endpoint will return all the categories assigned to a venue. There can be multiple categories assigned to a venue, one of the categories will have a field "primary" that is set to true to indicate that it is the primary category.
Look for something like this in the result set:
categories: [
{
id: "4bf58dd8d48988d143941735",
name: "Breakfast Spot",
pluralName: "Breakfast Spots",
shortName: "Breakfast",
icon: {
prefix: "https://foursquare.com/img/categories_v2/food/breakfast_",
suffix: ".png"
},
primary: true
},
{
id: "4bf58dd8d48988d16a941735",
name: "Bakery",
pluralName: "Bakeries",
shortName: "Bakery",
icon: {
prefix: "https://foursquare.com/img/categories_v2/food/bakery_",
suffix: ".png"
},
}
}
]

KendoUI datasource: parseInt of filter value

I need to filter a Kendo datasource through the following filter item object:
filters: [
{
field: "FIELD",
operator: "lt",
value: "080"
}
]
That means, because of the way data are transmitted, I am trying to test a case like: "013" < "080".
But it does not work out of the box.
Is there a way to define a filter with something like a "parseInt" on the tested values?
Thank you!
Try defining FIELD as a number in model:
schema : {
model: {
fields: {
FIELD : { type: "number" }
}
}
},
If you do so, then FIELD is displayed as 13, 80,... If you want to display FIELD with leading 0, use the following in the column definition of the grid.
{ field: "FIELD", title: "Field", format: "{0:000}" }
Doing this FIELD is considered as a number even that it is displayed as 013, 080...
You should have something like:
var dataSource = new kendo.data.DataSource({
data : entries,
batch : true,
schema : {
model: {
fields: {
FIELD: { type: "number" }
}
}
}
});
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
columns : [
{ field: "FIELD", title: "Field", format: "{0:000}" }
],
filterable: true
}).data("kendoGrid");
If you want to try it, see it in JSFiddle here
EDIT: Updated code for using format instead of template as Mateo Piazza suggested

jQuery Validation error

I have been struggling with this jQuery Validation Plugin.
Here is the code:
<script type="text/javascript">
$(function() {
var validator = $('#signup').validate({
errorElement: 'span',
rules: {
username: {
required: true,
minlenght: 6
//remote: "check-username.php"
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
},
agree: "required"
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 6 characters"
//remote: "Somenoe have already chosen nick like this."
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
agree: "Please accept our policy"
}
});
var root = $("#wizard").scrollable({size: 1, clickable: false});
// some variables that we need
var api = root.scrollable();
$("#data").click(function() {
validator.form();
});
// validation logic is done inside the onBeforeSeek callback
api.onBeforeSeek(function(event, i) {
if($("#signup").valid() == false){
return false;
}else{
return true;
}
$("#status li").removeClass("active").eq(i).addClass("active");
});
//if tab is pressed on the next button seek to next page
root.find("button.next").keydown(function(e) {
if (e.keyCode == 9) {
// seeks to next tab by executing our validation routine
api.next();
e.preventDefault();
}
});
$('button.fin').click(function(){
parent.$.fn.fancybox.close()
});
});
</script>
And here is the error:
$.validator.methods[method] is undefined
/js/jquery-validate/jquery.validate.min.js
Line 15
I am completely confused... Maybe some kind of handler is needed?
I would be grateful for any kind of answer.
I think it is simply a typo:
minlenght: 6
should be
minlength: 6

Resources