1

我的价格是例如 10,00 € 这个价格是 100 g 客户可以在数量字段中添加任何 g 例如 300

magento 现在有 3000 的小计,还可以,但不适合我这里的需要。

我需要做:如果设置了价格和数量,获取小计/价格数量,设置新的小计

我可以在哪里进行修改?

非常感谢!丹尼斯

编辑 和观察者的第三次尝试(不工作 atm,没有错误,没有任何反应):

    class Xyz_Catalog_Model_Price_Observer
    {
        public function __construct()
        {
        }

        public function apply_quantity_order($observer)
        {
        $order = $observer->getEvent()->getOrder();

        $pricequantity = $order->getPricequantity();

        if($pricequantity != ''){
            $old_sub_total = $order->getTotals();
            $new_sub_total = $old_sub_total / 100;
            $order->setTotals($new_sub_total);
        } else {}

        return $this;
        }
        public function apply_quantity_quote($observer)
        {
        $quote = $observer->getEvent()->getQuote();

        $pricequantity = $quote->getPricequantity();

        if($pricequantity != ''){
            $old_sub_total = $quote->getTotals();
            $new_sub_total = $old_sub_total / 100;
            $quote->setTotals($new_sub_total);
        } else {}

        return $this;
        }
    }

XML:

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <xyzcatalog>
             <class>Xyz_Catalog_Model</class>
        </xyzcatalog>
    </models>
    <events>
      <sales_order_save_after>
        <observers>
          <xyz_catalog_price_observer>
            <class>Xyz_Catalog_Model_Price_Observer</class>
            <method>apply_quantity_order</method>
          </xyz_catalog_price_observer>
        </observers>
      </sales_order_save_after>
      <sales_quote_save_after>
        <observers>
          <xyz_catalog_price_observer>
            <class>Xyz_Catalog_Model_Price_Observer</class>
            <method>apply_quantity_quote</method>
          </xyz_catalog_price_observer>
        </observers>
      </sales_quote_save_after>
    </events>
  </global>
</config>
4

2 回答 2

1

看看@以编程方式将产品添加到购物车并更改价格

public function applyDiscount(Varien_Event_Observer $observer)
{
    /* @var $item Mage_Sales_Model_Quote_Item */
    $item = $observer->getQuoteItem();
    if ($item->getParentItem()) {
        $item = $item->getParentItem();
    }

    // calc special price
    $percentDiscount = 5;
    $specialPrice = $item->getOriginalPrice() -  $percentDiscount;

    // Make sure we don't have a negative
    if ($specialPrice > 0) {
        $item->setCustomPrice($specialPrice);
        $item->setOriginalCustomPrice($specialPrice);
        $item->getProduct()->setIsSuperMode(true);
    }
}
于 2014-06-04T18:14:51.513 回答
1

我建议不要覆盖小计计算功能,而是尝试事件 - sales_quote_save_after 和 sales_order_save_after。

您可以通过观察者方法获取报价和销售额

$observer->getEvent()->getOrder() //for order
$observer->getEvent()->getQuote() //for quote

然后相应地修改小计。

编辑:这可能只是提示您如何修改小计。

Edit2:您必须在配置中添加事件观察者,如下所示:

<sales_order_save_after>
    <observers>
        <yourext>
            <class>yourext/observer</class>
            <method>observerMethod</method>
        </yourext>
    </observers>
</sales_order_save_after>

有关详细信息,请查看使用事件/观察者自定义 Magento

于 2014-06-04T16:01:26.777 回答