1

私は展開の最中であり、Magento のオブザーバーとイベントを使用して特定の属性に固定データを与えることで、製品の保存をオーバーライドしようとしていますが、問題は、私が開発しているローカルでこれをすべて作業していることです。しかし、サーバーにアップロードしてオブザーバーを実行しようとすると、まったく起動しないようです。このチュートリアルに基づいて以下のコードを作成しました: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

これを実現するために使用する 2 つのファイルが /app/code/local にあります。

/アプリ/コード/ローカル/リーフカッター/カタログ/etc/config.xml

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <leafcuttercatalog>
             <class>Leafcutter_Catalog_Model</class>
        </leafcuttercatalog>
    </models>
    <events>
      <catalog_product_save_before>
        <observers>
          <leaf_cutter_catalog_productautoinsert_observer>
            <type>singleton</type>
            <class>Leafcutter_Catalog_Model_ProductAutoInsert_Observer</class>
            <method>catalog_product_save_before</method>
          </leaf_cutter_catalog_productautoinsert_observer>
        </observers>
      </catalog_product_save_before>
    </events>
  </global>
</config>

/app/code/local/Leafcutter/Catalog/Model/ProductAutoInsert/Observer.php

class Leafcutter_Catalog_Model_ProductAutoInsert_Observer {

public function __construct(){}

/**
 * catalog_product_save_before() is called before the product in the model is about to be saved. In this
 * case, we want to override the saving mechanism and force the product to save certain preset data onto the product.
 * @param $observer
 * @return Leafcutter_Catalog_Model_ProductAutoInsert_Observer
 */
public function catalog_product_save_before($observer){
    Mage::log('Going to observer');
    $event = $observer->getEvent();
    $product = $event->getProduct();

    if($product->getWantitnow()){
        Mage::log('Product is want it now');

        $this->_checkAndSave($product, WANT_IT_NOW_SHIPPING_GROUP, WANT_IT_NOW_DELIVERIES_RETURNS);
    } else {
        Mage::log('Product is in warehouse');
        $this->_checkAndSave($product, IN_WAREHOUSE_SHIPPING_GROUP, IN_WAREHOUSE_DELIVERIES_RETURNS);
    }

    return $this;

}

/**
 * _checkAndSave() checks to ensure that the product has the appropriate delivery and returns text as well
 * @param $product - The product object in question
 * @param $specialShippingGroupId - The Special Shipping Group value that needs to be set.
 * @param $deliveriesReturnsText - The Deliveries and Returns text that needs to be set.
 * @return void
 */
private function _checkAndSave($product, $specialShippingGroupId, $deliveriesReturnsText){
    if($product->getDeliveriesAndReturns()!= $deliveriesReturnsText){
        $product->setDeliveriesAndReturns($deliveriesReturnsText);
    }

    if($product->getSpecialShippingGroup() != $specialShippingGroupId){
        $product->setSpecialShippingGroup($specialShippingGroupId);
    }

    Mage::log('_checkAndSave: outputting deliveries and returns' . $product->getDeliveriesAndReturns());
    Mage::log('_checkAndSave: outputting deliveries and returns' . $product->getGetSpecialShippingGroup());

}

}

テストするテキストも出力しようとしましたが、何もログに記録されないため、イベントが発生していないと考えています。正確なプラグインがインストールされているため、ライブ バージョンでプラグイン間で競合が発生するかどうかはわかりません。

上記のコードが実際に問題ではない場合、この問題を引き起こす可能性のある他の可能性は何ですか?

みんなありがとう。

4

4 に答える 4

6

app/etc/modules/Leafcutter_Catalog.xml を追加しましたか?

<?xml version="1.0"?>
<config>
    <modules>
        <Leafcutter_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </Leafcutter_Catalog>
    </modules>
</config>

/アプリ/コード/ローカル/リーフカッター/カタログ/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Leafcutter_Catalog>
        <version>1.1</version>
    </Leafcutter_Catalog>
  </modules>
  <global>
    <models>
        <leafcuttercatalog>
             <class>Leafcutter_Catalog_Model</class>
        </leafcuttercatalog>
    </models>
    <events>
        <catalog_product_save_before>
            <observers>
                <leafcuttercatalog>
                    <type>singleton</type>
                    <class>catalog/productautoinsert_observer</class>
                    <method>catalog_product_save_before</method>
                </leafcuttercatalog>
            </observers>
        </catalog_product_save_before>
      </events>
  </global>
</config>
于 2012-12-18T20:07:06.497 に答える
1

1つの可能性は、ローカルコードブ​​ランチがオンになっていないか、ファイルシステムの大文字と小文字の区別に違いがあることです。

于 2012-12-18T19:31:08.980 に答える
1

このイベント「catalog_product_prepare_save」を使用すると機能します。使用しているイベントは現在廃止されている可能性があります。上記のものはうまくいきますが、わかりません。

于 2012-12-19T09:55:37.980 に答える
0

お時間を割いてごめんなさい。しかし、結局、私が誤って定義したのは、setSpecialShippingGroupに設定していた値の1つでした。しかし、時間を割いていただきありがとうございます。:)

于 2012-12-19T03:53:16.183 に答える