0
我創建了一個觀察者。 當它觸發時,會提取所有信息,但不會將數據插入到數據庫中。不能保存在事件觀察者
config.xml中
<config>
<global>
<models>
<connector_mysql4>
<class>Custom_Connector_Model_Mysql4</class>
<entities>
<taxordermap>
<table>tax_order_map</table>
</taxordermap>
</entities>
</connector_mysql4>
</models>
<events>
<sales_order_place_after>
<observers>
<orderGetShopVatSettings>
<class>Connector_Model_Observers_Order</class>
<method>setSetting</method>
</orderGetShopVatSettings>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
型號/ Taxordermap.php
<?php
class Connector_Model_Taxordermap extends Mage_Core_Model_Abstract{
/**
* consturctor
* Initializing the opject
*/
public function _construct(){
parent::_construct();
$this->_init('connector/taxordermap');
}
}
型號/ Mysql4/Taxordermap.php
<?php
class Connector_Model_Mysql4_Taxordermap extends Mage_Core_Model_Mysql4_Abstract{
/**
* Constructor
*/
protected function _construct(){
$this->_init('connector/actaxordermap','orderid');
}
}
和finaly
型號/ Mysql4/AcTaxordermap/COLLEC tion.php
<?php
class Connector_Model_Mysql4_Taxordermap_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
/**
* Constructor
*/
public function _construct(){
$this->_init('connector/actaxordermap');
}
}
最後但並非最不重要的:
型號/觀察員/ Order.php
<?php
class Connector_Model_Observers_Order{
public function setSetting(Varien_Event_Observer $observer){
$order = $observer->getEvent()->getOrder();
$orderid = $order->getId();
Mage::log("orderid: $orderid");
$shippingTax = (int)Connector_Model_System_Service::ShippingIncludesTax();
$tax = (int)Connector_Model_System_Service::priceIncludesTax();
Mage::log("tax: $tax");
Mage::log("shipping: $shippingTax");
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$model = Mage::getModel('connector/taxordermap');
$model->setOrderid($orderid);
$model->setTax($tax);
$model->setShipping($shippingTax);
Mage::log($model);
try{
$model->save();
}catch(Exception $e){
Mage::log("error: $e->getMessage();");
}
Mage::log($model);
}
}
這些都是信息我進入登錄
2014-03-12T14:53:29+00:00 DEBUG (7): orderid: 59
2014-03-12T14:53:29+00:00 DEBUG (7): tax: 0
2014-03-12T14:53:29+00:00 DEBUG (7): shipping: 1
2014-03-12T14:53:29+00:00 DEBUG (7): Connector_Model_Taxordermap Object
(
[_eventPrefix:protected] => core_abstract
[_eventObject:protected] => object
[_resourceName:protected] => connector/taxordermap
[_resource:protected] =>
[_resourceCollectionName:protected] => connector/taxordermap_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[orderid] => 59
[tax] => 0
[shipping] => 1
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
2014-03-12T14:53:29+00:00 DEBUG (7): Connector_Model_Taxordermap Object
(
[_eventPrefix:protected] => core_abstract
[_eventObject:protected] => object
[_resourceName:protected] => connector/taxordermap
[_resource:protected] =>
[_resourceCollectionName:protected] => connector/taxordermap_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[orderid] => 59
[tax] => 0
[shipping] => 1
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] => orderid
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
據我所見,數據已保存,但未出現在數據庫中。 它確實很簡單,不存儲,儘管它尾巴存儲它。