【发布时间】:2016-12-23 13:54:52
【问题描述】:
您好,对于 Magento 网站,我需要在购物车中加载自定义属性。
我使用 getmodel 函数来加载项目。但我不知道如何加载属性。也许我没有正确配置属性。我已经为产品列表启用了是。 de 属性代码是“staffel_percentage”。它只是一个普通的字符串
另外,当我更改每个产品的价格时,它不会更改小计,这可能是因为我们已经更改了网站其余部分的产品价格?
也许它在事件中?我使用这个事件:controller_action_layout_render_before。
这是我在观察者中使用的代码
$cart = Mage::getModel('checkout/cart')->getQuote(); // Gets the collection of checkout
foreach ($cart->getAllItems() as $item) { // adds all items to $item and does the following code for each item
if ($item->getParentItem()) { // If items is part of a parent
$item = $item->getParentItem(); // Get parentItem;
}
//echo 'ID: '.$item->getProductId().'<br />';
$percentage = 80;// init first percentage
$quantity = $item->getQty(); //quantity
//$staffelstring = loadattribute//loads attribute
//gives the right percentage per quantity
//$staffelarray = explode(';', ^);
//foreach($staffelarray as $staffels){
//$stafel = explode(':', $staffels);
//if($quantity >= $stafel[0]){
//$percentage = $Stafel[1];
//}
//}
$currency = Mage::app()->getStore()->getCurrentCurrencyRate(); // Currencyrate that is used currently
$specialPrice = (($this->CalculatePrice($item) * $currency)* $percentage) / 100; //New prices we want to give the products
if ($specialPrice > 0) { // Check if price isnt lower then 0
$item->setCustomPrice($specialPrice); //Custom Price will have our new price
$item->setOriginalCustomPrice($specialPrice); //Original Custom price will have our new price, if there was a custom price before
$item->getProduct()->setIsSuperMode(true); //set custom prices against the quote item
}
}
【问题讨论】: