Magento custom price on Quote Item is ignored? - magento

I want to be able to change price on Quote Items to be different than on Products, based on several Tutorials I have used this code:
$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quote->save();
After that when I get to cart it shows normal prices, not custom price. I have checked Quote Items in cart and they have correct customPrice, but it seems to be ignored. Do I have to activate something else to make this custom prices to take effect?
PS:
Magento v1.7

OK, so I found the problem, somehow it didnt get saved in my script. Not sure why, but I have rewritten my code into 2 functions, 1 for adding product, the other for changing price.
So this code is all that is necessary:
$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quoteItem->save();
No need to save quote, just quoteItem.

Should be an easy fix: If I'm not mistaken you are trying to save the price of a quote item, but you save the quote instead. You need to save the quote item itself as well.
$quoteItem->setCustomPrice($price);
$quoteItem->setOriginalCustomPrice($price);
$quoteItem->getProduct()->setIsSuperMode(true);
$quoteItem->save();
$quote->save();

Related

Shopify Script for Fixed Discount of a set price based on tags

Using Shopify Scripts :::
I am trying to achieve the below but getting issue. Could you please let me know how to do this.
$25 off a purchase of $125 or more from the "sale" section. These products have a tag "sale" and are also in a collection "sale" based on that tag.
Looking forward for your quick response.
Great Thanks
If you examine the documentation for Shopify Scripts you'll notice that there is no support for auditing the line item for tags. So you should try the other approach which is proven, and works well.
Look for an item with a compare at price. If you find one, then that typically means the item is on sale. So you can rig your logic to look for items with a compare at price, and if they have one, then determine if the cart has exceeded the $125 in value, and if so, apply your discount.
I can't give you the exact code as I don't know the structure of your code. But this is what you need to do.
Wherever a product can be added to the cart assign a JavaScript function to check if the product is of "Sale" collection. If yes, add an attribute cart.attributes.something.something and keep changing it as and when required.
When the checkout mechanism is present in the page, and if your conditions satisfy the Sale discount, take then to /checkout?DISCOUNT=<CODE> and click of checkout. It'll automatically apply the discount.

Magento quote items modify sku

I need to change SKU on quoteitems and I do it like this:
foreach($items as $item){
$item->setSku($newSku);
$item->save();
}
But magento always resets SKUs into their original values. Is there some easy way to change it, like superMode on prices? Or if not, then where can I find methods to rewrite, so that they ignore my custom SKUs?
Tried looking for it, but even if I remove cart init and save from index action, they still reset somewhere.
I need it to work in Magento 1.7-1.8
Ok, so I didnt feel like waiting and found it.
You can find it in Mage_Sales_Model_Quote_Item and there in function setProduct. This function is run every time the cart is shown and it resets the data from Product to Item.
Not sure if now my data will get through whole checkout process, will update the answer if not.
EDIT
This has solved only cart, will need to find also function for order. Will update when I get it.
EDIT
In the end, I don't advise you to do this. But if you need it then, the way to do it is to create observe on event sales_order_save_after and modify sku of order items. This seems to work everywhere, only in email after checkout it doesn't work, there you have to modify email. Also I use this only on configurable products.
I do the same thing on my project using sales_quote_collect_totals_after
Just change quote item SKU as you want using this event.

special price - how to remove in mass?

I hase set some special price, with a start date, and no end date.
Now I want to remove all the special price.
so no discount.
I went to the catalog view, I select ALL products, and clicked on "change attributes".
I've check the "updated" checkbox beside start date, and special price.
then I click apply.
I can see the special price disappeared, but... on the front end, I can still see the promotion!
How is it possible?
Now note that If I select a product on the backoffice, and If I click on "save" (without editing anything) then it works on the front end!!
Of course I re-indexed everything and cleared the cache.
I have 20k products so I cannot select all products one by one to click on "save"
thaks for your help
Rod
I use magmi for this. Most bulk operations are possible here. You'll definitely need this if you say you have 20k+ products.
Outside of this solution, you'll probably have to do stuff manually, write a script to manage the mass update, or write a direct SQL statement to update this. I'd post a query here but it can be too varied because of Magento's EAV system.

Magento: Shopping cart price rule gets applied, but discount not subtracted from subtotal

I have created a shopping cart price rule in my Magento store (version 1.4.1.1), and it seems to get applied without issue on the frontend, but the discount isn't actually reflected in the subtotal or final total. The original item price is $45.00, and the discount should be $35.00, making the final price $10.00. Here are some screenshots of the setup. (Sorry, because I'm a new user it won't let me post images directly in this posting.)
http://imgur.com/a/hdYDb
Main rule page
Actions page
Cart showing that promotional code was applied
Reviewing order (last step before submitting order)
This particular item has some custom options set, which set the pricing for four individual options. The price for the product is $0.00, and then each option has it's own price (I didn't set this part up, so I'm not sure if I'm missing something from here too). Here's a screenshot of the product custom options page: http://imgur.com/uO9HG
Any thoughts? I'm fairly new to Magento, so it's possible I'm just missing something obvious. Thanks in advance for any help or guidance!
I actually JUST figured out what was going wrong, or at least, I figured out a solution, though not sure exactly why this was affecting the shopping cart price rules. You're right that I wasn't even able to get a simple price rule to work - it simply wasn't working no matter how I changed the rule. Anyway, while working on another issue, I realized that I was missing the Subtotal/Grand Total box on the front-end of the shopping cart (I installed a clean copy of version 1.4.1.1 on my localhost, which is when I noticed it was missing from my live site). When I re-enabled the Subtotal/Grand Total box, the rules started working again. (I suppose now that Magento has a place on the front-end to show the discount, it actually applies it, whereas before it would just do nothing.)
So, to re-enable the subtotal/grand total box, in the back end, I went to System > Configuration > Advanced > Enable the Mage_Tax module. Again, not sure why it was disabled in the first place, and I'm not sure if this affects anything else on the site, but it's been up for awhile now and I haven't noticed anything awry. Here's a screen capture of it working: http://i.stack.imgur.com/kjl6S.png
I think the problem comes from using SKUs with your custom options combined with restricting your price rule to the product SKU. Magento combines them using a hyphen - place a test order to see if this is the problem.
The SKU in a test order I made comes out something like this;
[ORIGINAL_PRODUCT_SKU]-[CUSTOM_OPTION_SKU]
At least, that's the result I'm getting from version 1.5.0.1
The quickest solution I could find was to match the rule on the product url key rather than SKU. It isn't the most intuitive solution, but since you wouldn't change the URL on the product (I hope), it will work where SKU's with custom options fail.
In version 1.4, the URL key should be available to choose instead of SKU already. So you can just select url key instead of sku and insert your product's correct url key in your shopping cart price rule. Just replace "SKU is ..." with "URL key is ..." inserting the correct url key for your product.
In version 1.5 I had to enable "Use for Promo Rule Conditions" on the url_key attribute like this;
Log in to Magento admin area
Navigate to Catalog > Attributes > Manage Attributes
Locate the Atrtibute Code "url_key" and click to edit it
Change "Use for Promo Rule Conditions" to Yes
Save the changes
you may need to reindex the Product Flat Data index at this point
Then I could use it in my price rule.
Had this same exact problem on CE 1.9 running PHP7, applying the Inchoo "PHP 7 compatibility extension for Magento 1" solved the issue!
https://github.com/Inchoo/Inchoo_PHP7

Magento: adding catalog price rules to options of a bundle

I've looking around and couldn't find how to do this.
I'd like to be able to set a catalog price rule for a specific option of a bundled product. Basically I want to set the price of any selection from option1 to be $0 in that bundle (but keep the price the same for that product if someone just adds the product to their cart from outside of the bundle). is there a way to do this that i'm missing?
The second approach I was thinking was to set the price to $0 of all those selections for that option (i saw a post on here on how to do something like that programatically) although without testing that that works, it seems like it wouldn't.
any ideas would be welcome.
This is something that Magento does not do by default. Additionally, beware of trying to change this through cleverness, as Magento has significant validation for prices once items are added to the cart (e.g. it will try to recalibrate them to the database on every page load). It sounds like trying to restructure the flow so that you aren't trying to use the shopping cart rules might be the best bet here. Would it be possible to use some other mechanism to give discounts, like a coupon code?

Resources