I can not understand please help. In his module I use catalog_controller_product_init event
config.xml
<frontend>
<catalog_controller_product_init>
<observers>
<ZM_Digi_stock_price_update>
<class>ZM_Digi_Model_Observer</class>
<method>updateProduct</method>
<type>singleton</type>
</ZM_Digi_stock_price_update>
</observers>
</catalog_controller_product_init>
</frontend>
observer.php
public function updateProduct($observer)
{
$product = $observer->getProduct();
if (Mage::helper('digi')->getAtributeSet($product) == 'Digi') {
Mage::getSingleton('digi/digi')->updateStockStatus($product);
Mage::getSingleton('digi/digi')->updatePrice($product);
}
}
Digi.php (model)
public function updateStockStatus($product)
{
$product_digid = Mage::helper('digi')->getProductDigiId($product);
$digi_stock = Mage::helper('digi')->getInstock($product_digid);
$stock_item = Mage::getModel('cataloginventory/stock_item')->assignProduct($product);
$store_stock = $stock_item->getIsInStock();
if ($store_stock != $digi_stock) {
if ($digi_stock == 0) {
$stock_item->setQty(0);
$stock_item->setIsInStock(0);
$stock_item->save();
} else {
$stock_item->setQty(1);
$stock_item->setIsInStock(1);
$stock_item->save();
}
}
}
public function updatePrice($product)
{
$store_price = $product->getFinalPrice();
$digi_price = Mage::getModel('digi/digi')->digiPrice($product);
if ($store_price != $digi_price) {
if ($digi_price != ''){
$product->setPrice($digi_price);
$product->getResource()->saveAttribute($product, 'price');
} else{
$product->setPrice(0);
$product->getResource()->saveAttribute($product, 'price');
}
}
}
Model update availability and prices of products.
This code is a good work out in the admin area, but on the site update prices and availability in two stages. 1 page loading. Record the new values (see the oldest) 2 page loading. We see the new values.
I understand the matter in the boot sequence
I tried using catalog_controller_product_init_before event but this event does not contain any information on the product ...
I want to ask how it is possible to implement, and update, and display in one page load?