【发布时间】:2014-12-10 00:49:16
【问题描述】:
在尝试修复捆绑包价格同时保留增值税计算后,我下一次尝试解决此问题是对捆绑包应用折扣以将其减少到固定金额。
<?php
class XXX_Fixedbundlediscount_Model_Observer
{
public function setDiscount($observer)
{
Mage::log('settingDiscount');
$quote = $observer->getEvent()->getQuote();
$quoteid = $quote->getId();
if ($quoteid) {
foreach ($quote->getAllItems() as $item) {
$product = $item->getProduct();
$fixed_price_attribute = (float)Mage::getResourceModel('catalog/product')->getAttributeRawValue($product->getId(), 'giftset_fixed_price', Mage::app()->getStore()->getStoreId());
if ($product->getTypeId() !== Mage_Catalog_Model_Product_Type::TYPE_BUNDLE || !$fixed_price_attribute) {
continue;
}
$lineTotal = (float)$item->getPriceInclTax();
$item->setBaseDiscountAmount(0);
$item->setDiscountAmount(0);
if ($lineTotal > $fixed_price_attribute) {
$item->setDiscountAmount(-($lineTotal - $fixed_price_attribute));
$item->setDiscountDescription('Gift Set');
$item->setBaseDiscountAmount(-($lineTotal - $fixed_price_attribute))->save();
Mage::log('xxxx');
}
Mage::log($fixed_price_attribute);
Mage::log($lineTotal);
Mage::log(($fixed_price_attribute > $lineTotal) ? 'Yes' : 'No');
}
}
}
}
我在捆绑产品上设置了一个自定义属性,用于指定固定成本。从上面可以看出,想法是检测到这一点,计算捆绑的成本并将属性值之间的差值作为折扣添加。
不幸的是,它没有像以往那样增加任何折扣......
任何人都可以提出任何可能有用的建议吗?
谢谢
Gav
【问题讨论】:
标签: magento module magento-1.9