A Magento-Bug, that circulates in the Magento forums on and StackOverflow for some years, is that tier prices do not work properly together with bundle products. Over time there was some improvement but as for today (Magento CE 1.9) the following still does not work:
- Associated products with tier prices and qty > 1 in the bundle
- “Price as configured” display on bundle products with tier prices
There are some suggestions found on the web but more questions than answers, so I created a (hopefully) complete solution without core hacks and with only minimally invasive class rewrites. Until Magento gets it solved itself, you can use this module to enable bundles with tier prices:
SGH_BundleTierPrices (tested in Magento CE 1.8 and Magento CE 1.9)
Which changes were made in detail and how, I will explain here:
Bugfixes
Price Calculation
The problem: in bundle options that have tier prices themselves the tier prices in the bundle are not applied correctly.
To blame is Mage_Bundle_Model_Product_Price::getSelectionFinalTotalPrice()
:
if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) { $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1); }
Here the configured selection quantity $selectionQty
is used for tier price calculation but the quantity of the bundle itself is ignored. By the way, the parameter of getFinalPrice()
is only used for tier price calculation, the method always returns a unit price.
The corrected line looks as follows:
if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) { $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty * max(1, $bundleQty) : 1); }
I.e. if the quantity of the bundle $bundleQty
is known, it will be multiplied.
To save the price correctly not only in the bundle but also in the selection itself, we have to trigger a recalculation of their final price as well because at least in some cases it is already calculcated (wrong) at this point. To achieve this, I added the following lines at the beginning of the method:
if ($takeTierPrice) { $selectionProduct->setFinalPrice(null); }
Price Display in Frontend
The problem: The dynamic price display “Price as configured” does not work with tier prices.
To blame is Mage_Catalog_Model_Product_Type_Price::getTierPrice()
, the method returns an array with tier price informations. The array keys are strings in the form {customer group}-{quantity}
, generated in Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract::preparePriceData()
. When this array is printed as JSON for the dynamic price display it becomes an object, due to the string keys. But the JavaScript expects an array and tries to iterate over numeric indices.
Thus we have to achieve that getTierPrice()
returns a numeric indexed array. I did not dare to touch the backend model, however the getTierPrice()
method is not used anywhere, where the string keys would be relevant as far as I can see. So the rewrite looks as follows:
public function getTierPrice($qty = null, $product) { $tierPrice = parent::getTierPrice($qty, $product); if (is_array($tierPrice)) { return array_values($tierPrice); } return $tierPrice; }
Installation of the Extension
With Composer
"require": { "sgh/bundletierprices": "dev-master", } "repositories": [ { "type": "git", "url": "https://github.com/sgh-it/bundletierprices.git" } ]
Manually
- Download Source Code
- Copy
app
into the Magento installation directory (no files are overwritten, just added)
Hallo Herr Schmengler,
vielen dank für die super “Extension”. Folgende Frage jedoch noch, ist es auch möglich wenn man in die “Total”-Menge z.B. 20 einträgt, dass dann entsprechend neben den “Singleproducts” nicht der “normale” Einzelpreis steht, sondern auch direkt der richtige Staffelpreis für 20 Stk dort steht?
Ist dies verständlich 🙂 Über eine Antwort würde ich mich sehr freuen
Hallo Herr Boender,
für diese Preise ist leider keine automatische Aktualisierung vorgesehen, das wird durch meinen Bugfix entsprechend auch nicht abgedeckt. Mit zusätzlicher eigener JavaScript-Entwicklung sollte es aber möglich sein, da die Daten ja nun korrekt im JSON-Objekt vorbereitet sind.
Thanks for this!
It works fine on 1.9.1 and it is exactly what i needed.
Frenchman in France
Thank you Fabian for producing this extension. I have installed it but am not getting the price to update dynamically. Would it be possible to contact you to troubleshoot this? I have budget to do this.
Hey Fabian!
This extension you’ve written is EXACTLY what I am looking for! However after installing, nothing appears to have changed. The items are showing the correct tier price next to the items, however when clicking them, the configured price just stays at $0.00, and you aren’t able to Add to Cart the selected options either. Any idea what could be going on? You can see what is going on in this image: http://i64.tinypic.com/de0djp.jpg .. Any insight would be greatly appreciated! Thanks!
Apologies on the broken link, http://imgur.com/BsMU7p2 will work. 🙂
Sounds like a JavaScript error. I am not actively maintaining the extension anymore, but I’ll answer your mail 🙂