对于Magento网上商店,我必须更改层级列表中的百分比。 例如:所以如果你买一个,你支付105%,2 103%等。 逻辑和所有工作,但当我对Magento说:“嘿制造产品x价格y”你的价格没有得到更新。
这是观察者的代码:
$cart = Mage::getModel('checkout/session');
foreach ($cart->getQuote()->getAllItems() as $item) {
if ($item->getParentItem()) {
$item = $item->getParentItem();
}
//loads more attributes for the rpoduct
$product = Mage::getModel('catalog/product')->load($item->getProductId());
//gets the string for all percentages example: 1:105;2:103
$staffeltext = $product['staffel_percentage'];
$percentage = 105;// init standard percentage
$quantity = $item->getQty();
$staffelarray = explode(';', $staffeltext);
foreach($staffelarray as $staffels) {
$stafel = explode(':', $staffels);
if($quantity >= $stafel[0]) {
$percentage = $stafel[1];
}
}
echo $percentage . " ";
$currency = Mage::app()->getStore()->getCurrentCurrencyRate();
$specialPrice = (($this->CalculatePrice($item) * $currency)* $percentage) / 100;
echo $specialPrice;
$specialPrice = number_format($specialPrice, 2);
$item->setCustomPrice($specialPrice);
$item->setOriginalCustomPrice($specialPrice);
$item->getProduct()->setIsSuperMode(true);
这是我目前使用的事件:
<checkout_cart_product_update_after>