2010-08-16 27 views
9

2 người quan sát của tôi đang quan sát sự kiện sales_order_shipment_save_before tương tự. ModuleA là cái tôi đã tạo đầu tiên và sau đó tôi đã tạo ModuleBMagento - 2 hoặc nhiều người quan sát trên cùng một sự kiện

Hiện tại, chỉ người quan sát được gọi và không ModuleA.

Vui lòng cho tôi biết cách tôi có thể giải quyết vấn đề này và cả hai nhà quan sát đều được gọi.

ModuleA

<?xml version="1.0"?> 
<config> 
    <global> 
     <models> 
      <shipmentsave> 
       <class>My_Shipmentsave_Model</class> 
      </shipmentsave> 
     </models> 
    </global> 
    <adminhtml> 
     <events> 
      <sales_order_shipment_save_before> 
       <observers> 
        <shipmentsave> 
         <type>singleton</type> 
         <class>shipmentsave/observer</class> 
         <method>salesOrderShipmentSaveBefore</method> 
        </shipmentsave> 
       </observers> 
      </sales_order_shipment_save_before> 
     </events> 
    </adminhtml> 
</config> 

Observer.php

<?php 

    class My_Shipmentsave_Model_Observer 
{ 
    public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer) 
    { 
     $shipment = $observer->getEvent()->getShipment(); 
     return; 
    } 
} 

ModuleB

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
    <My_Bshipment> 
     <version>0.1.0</version> 
    </My_Bshipment> 
    </modules> 
    <admin> 
    <routers> 
     <bshipment> 
    <use>admin</use> 
    <args> 
     <module>My_Bshipment</module> 
        <frontName>bshipment</frontName> 
    </args> 
     </bshipment> 
    </routers> 
    </admin> 
    <adminhtml> 
    <events> 
     <sales_order_shipment_save_before> 
     <observers> 
      <shipmentsave> 
      <type>singleton</type> 
      <class>bshipment/observer</class> 
      <method>salesOrderShipmentSaveBefore</method> 
      </shipmentsave> 
     </observers> 
     </sales_order_shipment_save_before> 
    </events> 
    </adminhtml> 
    <global> 
    <models> 
     <bshipment> 
    <class>My_Bshipment_Model</class> 
     </bshipment> 
    </models> 
    <resources>  
     <bshipment_setup> 
     <setup> 
      <module>My_Bshipment</module> 
     </setup> 
     <connection> 
      <use>core_setup</use> 
     </connection> 
     </bshipment_setup> 
     <bshipment_write> 
     <connection> 
      <use>core_write</use> 
     </connection> 
     </bshipment_write> 
     <bshipment_read> 
     <connection> 
      <use>core_read</use> 
     </connection> 
     </bshipment_read> 
    </resources> 
    <blocks> 
     <!-- adminhtml> 
     <rewrite> 
    <shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</shipment_view> 
     </rewrite> 
     </adminhtml--> 
     <adminhtml> 
    <rewrite> 
     <sales_order_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</sales_order_shipment_view> 
    </rewrite> 
    <rewrite> 
     <sales_shipment_grid>My_Bshipment_Block_Adminhtml_Shipment_Grid</sales_shipment_grid> 
    </rewrite> 
     </adminhtml>   
     <!-- udropship> 
     <rewrite> 
    <adminhtml_shipment_view>My_Bshipment_Block_Adminhtml_Shipment_View</adminhtml_shipment_view> 
     </rewrite> 
     </udropship--> 
    </blocks> 
    <helpers> 
     <bshipment> 
      <class>My_Bshipment_Helper</class> 
     </bshipment> 
    </helpers> 

    </global> 
</config> 

Observer.php

<?php 
class My_Bshipment_Model_Observer 
{ 
    public function salesOrderShipmentSaveBefore(Varien_Event_Observer $observer) 
    { 
     $shipment = $observer->getEvent()->getShipment(); 
    return; 
    } 
} 

Kính trọng, Saurabh

+1

Hãy đăng hai thông số quan sát viên của bạn (XML cấu hình). –

+0

Nhập xml và php – Saurabh

Trả lời

14

Không có thời gian để kiểm tra điều này, nhưng ở cái nhìn đầu tiên tôi muốn thử làm

<shipmentsave> 

riêng biệt cho mỗi mô-đun. Một cái gì đó như

<observers> 
     <shipmentsave> 
     <type>singleton</type> 
     <class>bshipment/observer</class> 
     <method>salesOrderShipmentSaveBefore</method> 
     </shipmentsave> 
    </observers> 

<observers> 
     <bshipmentsave> 
     <type>singleton</type> 
     <class>bshipment/observer</class> 
     <method>salesOrderShipmentSaveBefore</method> 
     </bshipmentsave> 
    </observers> 
+0

Đây chính là vấn đề. Bạn chỉ có thể có một phiên bản của một người quan sát có tên cho mỗi sự kiện. Mỗi người quan sát sẽ yêu cầu tên riêng của nó. Tiêu chuẩn của tôi là sử dụng tên mô-đun làm tên người quan sát. Vì vậy, trong trường hợp này. –

+0

@Alan Storm, hai năm sau câu trả lời của bạn, không được chấp nhận, nhưng nó có hoạt động không? Tôi đang đối mặt với cùng một vấn đề, 2 mô-đun khác nhau, cần phải nắm bắt cùng một sự kiện và mô-đun thứ hai không hoạt động. Nhưng nếu tôi hủy kích hoạt cái đầu tiên thì công trình thứ 2. – Yaroslav

+2

Câu trả lời này phải được chấp nhận. Vì tên người quan sát cần phải là duy nhất, 'shipmentsave' và' bshipmentsave' sẽ hoạt động. Nếu không, nút XML cuối cùng đọc sẽ chỉ ghi đè lên các quan sát viên trước đó có cùng tên. – musicliftsme

5

Mỗi người quan sát nên có một tên duy nhất. Trong mã, cả người quan sát đều có cùng tên. Vì vậy, hãy đặt tên duy nhất cho mỗi người quan sát.

0

Tôi nghĩ rằng bạn đang bỏ lỡ một số suy nghĩ, Bạn có thể gọi nhiều chức năng bằng cách sử dụng người quan sát cho một sự kiện. Nhưng đối với mỗi tên Event Observer Method phải khác nhau và cũng là Id của nó.

<events> 
    <sales_order_shipment_save_before> 
     <observers> 
      <shipmentsave> 
       <type>singleton</type> 
       <class>shipmentsave/observer</class> 
       <method>salesOrderShipmentSaveBefore</method> 
      </shipmentsave> 
     </observers> 
    </sales_order_shipment_save_before> 
</events> 

<events> 
    <sales_order_shipment_save_before> 
     <observers> 
      <shipmentsave> 
      <type>singleton</type> 
      <class>bshipment/observer</class> 
      <method>salesOrderShipmentSaveBefore</method> 
      </shipmentsave> 
     </observers> 
    </sales_order_shipment_save_before> 
</events> 

Bạn có thể thấy trong cả hai lô hàng id xml và phương thức bán hàngOrderShipmentSaveBefore giống nhau.

Chỉ cần thay đổi điều này và bạn đã hoàn tất.

Các vấn đề liên quan