1

私の価格は、たとえば 10,00 €です。この価格は 100 g です。お客様は、数量フィールドに任意の g を追加できます(例: 300)

magento の小計は 3000 になりました。問題ありませんが、ここでの私のニーズには合っていません。

私がしなければならないこと: 価格と数量が設定されている場合、小計/価格数量を取得し、新しい小計を設定します

これに対する変更をどこに置くことができますか?

どうもありがとうございました!デニス

編集 とオブザーバーの 3 回目の試行 (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

小計計算関数をオーバーライドするのではなく、イベント (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>

詳細については、Event/Observer を使用した Magento のカスタマイズを参照してください。

于 2014-06-04T16:01:26.777 に答える