Changing line item properties on cart in Shopify - shopify

Is it possible to change line item properties after they have been added to the cart? (Either via a normal form submission, or via AJAX?)
I've tried a POST to /cart/change with a "properties[MyProperty]" key, but no luck so far. This is coupled with the line parameter to denote the unique line item.
Any ideas? Or is it just a straight 'no'?

Using Shopify's API you can't use cart/change.js to change the properties of a line item. The reason is that cart/change.js uses 'properties' to find the line item you want. The API documentation omits this. Here is an example:
When I make a POST to cart/add.js with the following url encoded parameters:
quantity=9403&id=278440178&properties%5Bmy-property%5D=property%20BAR
The response will include,
"properties":{"my-property":"property BAR"}
When I go on to make a POST to cart/change.js to change the property from BAR to FOO,
id=278440178&properties%5Bmy-property%5D=property%20FOO
Then the response will include,
"properties":{"my-property":"property BAR"}
That is, I was unable to change the line item property this way. You may suspect that this is because there is some trick to the cart/change.js API, but this is not the case.
Notice, when I try to remove a line item by making a POST to cart/change.js and specifying quantity=0, like this:
quantity=0&id=278440178&properties%5Bmy-property%5D=property%20FOO
With the property property FOO being one that does not belong to any item (my cart only has an item with property BAR right now), the item is not removed from the cart. If on the other hand I do this:
POST: quantity=0&id=278440178&properties%5Bmy-property%5D=property%20BAR
The item is removed as normal.
Conclusion: in cart/change.js, shopify uses line-item properties in the same way it uses 'id', that is, to find the line item whose quantity you want to change. Just in the same way that you can't use cart/change.js to change the id of a line item, you can't use it to change the properties of one.

Related

How delete Item from ArrayList in Firestore using Koltin

I want to delete one item from the animeId. For example, if I need to remove the animeId[5] or I want to remove the item that the value is equal 5114, how can I do that? I alredy learned how I remove item like the entire animeIdbut not just one item.
Here's an print how the database is organized:
For updating some fields of a document, use the update() method.
If you want to remove a specific item from an Arraylist, you can use a call to:
.update("arrayfield", FieldValue.arrayRemove("itemtoremove"))
For example if you have an arraylist that contains three items as “abc”, “efg”, “xyz”.
And if you want to remove specific item called “efg” from an arraylist you should use a call to:
.update("arrayfield", FieldValue.arrayRemove("efg"))
Please also take a look at this Stackoverflow Link which explains clearly on
how to remove specific items from the array list in the firestore using kotlin.

How to get one product to modify information in the cart in Shopify?

If a customer clicks a certain button in my Shopify store, I'd like to be able to add information to my cart using Liquid (or whatever is needed). This information can be as simple as a string. The customer won't see this information, but it will be used to modify the look of the cart page. I can happily parse it/handle it as a string, if that's my only option, but so far I can't get any information to be sent. I have tried modifying cart.note using a {% capture %} block, but that never ended up modifying anything permanently. I also am not sure how to change line_item properties, but that might do it as well.
You can add input fields with the name properties[some-prop-name] to your product form, which would include the required linking data
For example, adding the following input to your product form would add a line-item property to your product as you add it:
<input type="checkbox" name="properties[_add_to_box]" value="{{ box_identifier }}" />
If you want to dynamically update line-item properties to add/rearrange items in boxes post-hoc you can do so using AJAX requests targeting the /cart/change.js endpoint
Here's an example of such a command, which you would run upon the user changing the appropriate input element:
/* Assuming we have a variable named cart (containing the cart JSON) and the the 0-based index for the item we want to update */
var line = index + 1; //Shopify uses 1-based indexing for line-items
var qty = cart.items[index].quantity;
jQuery.ajax({
url:'/cart/change.js',
type:'post',
dataType:'json',
data:{
line: line, /* Line to edit: REQUIRED */
quantity: qty, /* 'New' quantity - If omitted, the line will change to quantity 1! */
properties:{
/*
This properties object will replace any existing properties object on the line-item, so be sure to include everything, not just what you're changing!
Properties with keys that are prepended with an underscore (_) are hidden in Shopify's checkout page.
*/
_box_id: 'box01',
'Congratulatory Message':'Hooray! You did it!'
}
},
success:function(cart){
console.log('Success!', cart)
},
error:function(err){
alert('Something went wrong!', err)
}
})
Hopefully this helps you get your feature in!
You can store that data in the line item properties.
Get customization information for products with line item properties
You can collect customization information for products using line item properties. Line item properties are custom form fields that you can add to the product page, allowing customers to make choices or add information about a product. For example, if you offer product engraving, then you can use line item properties to let customers enter the text that they want engraved on the product.
Then you can access the line item properties from your liquid template.

Shopify: Filtering collections by custom filter

I'm new with liquid and ruby, but I would like to create a custom filter in a collection, to filter by metafields. I already have:
A dropdown in the collection.liquid, with the values I would like to filter for.
When selecting a filter, it goes to a link like: https://myshop.myshopify.com/collections/my-collection/my-filter . Basically it is like the tags, but with my filter instead
However, since it is a custom filter and not a tag, I get no results. I'm wondering where is the query that displays all the products (or filters) is in the code. I know that it depends on the theme, but I'm using the default theme: launchpad-star.
Not sure if I could do it this way or with a link like: https://myshop.myshopify.com/collections/my-collection?filter_by=my-filter , in which case, I would also need where should the logic go.
I've looked at the forums already and found two closed tickets with no responses: https://ecommerce.shopify.com/c/ecommerce-design/t/using-metafields-to-create-filter-drop-downs-in-collection-liquid-187513 and https://ecommerce.shopify.com/c/ecommerce-design/t/using-metafields-to-create-filter-drop-downs-in-collection-liquid-134401 .
Thanks in advance
Probably not the best solution, but this is what I did to solve the problem:
I changed to the second option of the url, so when a user selects an option in the combobox, it is sent to a URL like: myshop.myshopify.com/collections/my-collection?filter_by=my-filter
In product-grid-item.liquid, I'm getting the metafield value of the product and displaying it as a class, and hide all the products as default. In the collection.liquid I read with javascript the value of the parameter (filter_by) and remove the "hide" class of the products with the value of the filter_by as class, so it gets displayed.
I feel that it is not very clean, but it is working as expected. Problems with this solution:
* Not displaying all the products and then filtering them
* I need to display all the products to avoid pagination, which could be a big problem if I have a lot of products.
If anyone could post a better solution, welcome!.

Yii: CMenu items for different module

I'd like to make a menu in Layout which the items are linked to other different module.
e.g:
Item "Product" linked to an action in Product Module, item "Service" linked to an action in Service Module.
It won't work when I set the 'url'=>('product/<controllerID>/<actionID>') and 'url'=>('service/<controllerID>/<actionID>') because once we're in Product module and click the menu "Service", the URL become
index.php?r=product/service/<controllerID>/<actionID>
instead of
index.php?r=service/<controllerID>/<actionID>
and it will be 404 error. (for sure, because the Service Module isn't inside Product Module but the URL makes it looks like that).
Any solution for this?
Check the createUrl() documentation :
the URL route. This should be in the format of 'ControllerID/ActionID'. If the ControllerID is not present, the current controller ID will be prefixed to the route. If the route is empty, it is assumed to be the current action. If the controller belongs to a module, the module ID will be prefixed to the route. (If you do not want the module ID prefix, the route should start with a slash '/'.)
That last line tells us everything. Best thing to do for you is start all the routes with a / :
'url'=>array('/<moduleID>/<controllerID>/<actionID>')
Check this
'url'=>$this->createUrl('/<moduleId>/<controllerID>/<actionID>')

Content Organizer Rule Creation Issue

I am using the Content Organizer feature to move documents of a specific content type into a specific folder in a document library in the same site. I created a content organizaer rule with a property setting that uses the property testcolumn. Testcolumn is a site column defined as a lookup to column on a custom List, testlist, and then added to a site content type. The items in this list are displayed in the Value dropdown list and I can select the specific value I want to use for this rule.
The problem is that I can create and save rules provided that there are no more than 19 items in the testlist list. When I have 20 items in the testlist, it looks like the rule was saved by the UI. If I open the rule and go to edit it, the Value for the testcolumn property is (None). If I look at the item in powershell, the Value property is equal to '0' and not the ID of the item I saved in the UI. If I delete a record in the testlist so that the total number of items drops below 20, I can save the rule without issue. I have tried different combinaitions of items in the list in case it was a text issue, but when I have 20 items or more in the list, the rule is not saved.
I have looked at the ULS logs and it states the "Routing Engine: UpdateRule() has successfully updated the rule, rule.Name=TestRule1" when I save the rule.
Thanks for your help.
The answer is partially listed here. Looks like the page renders the control differently if the number of items is 20 or greater. The content organizer rule creation page does not handle this change and does not show any error when saving the information.
I was able to get around this limitation in the UI by adding the rules through code during my feature creation event. A link to creating rules through code is here.