How can I add discount to a product based on javascript variable value in shopify? - e-commerce

In Shopify, I want add the discount to product based on js variable. This discount should be considered in checkout? Can I achieve that??

It's not possible to alter the price of a line item in a cart. You can only update the product variant's price.
See this similar question: Shopify API CARTS - Changing line_item line_price for price Override
Is it possible to use Shopify's built in Discounts in your situation?

Related

Recalculate discounts in prestashop cart

I'm working on prestashop shop where are used coupon with % discounts. We don't want to use coupons on products on sale but still want to buy products on sale and normal products in the same cart. I want to recalculate discounts in cart and order to apply only on non-sale products. I need help which file I should edit or where add functions to do it.
You should create a module that adds dedicated cart rules or customer-related specific prices on the products you are interested in when customer changes his cart or validate the order.
There are plenty of native Prestashop hooks you can use for that so you don't need tweaking with the core.
Keep in mind that there are a lot of "advanced cart rules" modules out there, so consider having a look before reinventing the wheel.

Add shopify surcharge fee with variant product

I am creating a Shopify app so that user can add surcharge fee to the cart (custom fee). The custom fee will based on the total weight of the cart. To do that I create a product with many variants. For example, if the custom fee is 10eu then I add the product with variant 10eu to the cart.
I faced up with one issue. Shopify limits 100 variants for a product so my app will stop working after creating 100 variants. How can I clean up variants or how can I fix the issue?

How to bundle product in shopify?

I tried to develop a Shopify application and I needed to bundle some products and sell those together with the special discount values.
There are some apps like product-bundle but I need bundling product in my app.
I tried to create one product similar to them and after the purchase completed I delete it but I think it's not a good solution because this product will be shown to shop and other customers can purchase that while I want to offer this product to a certain customer only.
In another way, I tried to use Shopify discount but can't satisfy my need or maybe I can't find true ways.
How can I do that?
There are multiple ways in which you can handle this.
1) Create a product itself:
Create a single product indicating a combination of your desired multiple products and combination of your price.
When the customer adds all the related products, detect it from cart webhook and update the cart of the customer by removing such products and adding the single product(i.e combination of all products).
2) Create a discount code: Create a discount code with your desired discount amount for each combo. Detect the products in the cart by cart webhook, if combo products found automatically apply the coupon to the cart.

Test Prices In Shopify Using Optimizely

I'm looking to test prices in shopify using Optimizely.
I tried to change the price on the product page itself (which is just text) and increased the price by 5%. When I add the product to the shopping cart, the price of the product was still the regular price.
I realize there is probably a liquid variable which contains the price of any particular product, which I could alter in Optimizely's code editor to simply increase by 5%.
I think I can do this by using:
{{ product.price | times:1.05 | money }},
but I'm not sure how to implement in the optimizely editor, or whether this is the correct route to go.
Everything in Shopify to do with prices leads you to variants. So, in this case you could set up another variant with the different price, then have Optimizely show or hide as appropriate.
As optimizely runs on the client side, this is not currently possible on shopify (if it were people would be able to change your prices in their console)

Shopify Update Cart Total Price On The Fly

I am trying to update the cart total price on the fly. I have tried the shopify cart change or update processes but that seems to be not supporting the price update.
Any one knows any way of doing that ?
Any kind of help will be appreciable.
The only way to update the subtotals and total price in the cart is to change the quantity of a variant already in the cart. Remove one, you will obviously get a new price. Add one, you'll obviously get a new price. You can either do a conventional form submit to handle that, or use the Ajax API to change quantities, and then ask for the updated cart and manually update your pricing.