I'm in the midsts of deploying and I am trying to override the product save by giving certain attributes fixed data using Magento's observer and events, but the problem, is that I have this all working on the local which I have been developing in, but when I upload to the server and try to run through the observer doesn't seem to fire at all. I based the code below on this tutorial: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
I have two files which I use to achieve this in /app/code/local.
/app/code/local/Leafcutter/Catalog/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());
}
}
I've tried to output some text to test as well but nothing get put into the logs, So I am thinking the event is not being fired. I have the exact plugins installed so I'm not sure if there would be conflicts between plugins on the live version.
What other possibilities could cause this problem if the code above might not really be the problem?
Thanks guys.
Sorry about taking you time guys. But in the end it was one of the values i was setting for setSpecialShippingGroup that I wrongly defined. But thanks for taking the time. :)