Magento Product data in Mage::getSingleton('catalog/product') not clearing if product id not available in database
Eg:
Product ID - 586 (Poduct present)
Product ID - 999 (Product not present in Magento)
Not Working:
$productModel = Mage::getSingleton('catalog/product');
$_product=$productModel->load('586');
echo $_product->getId()."<br>";
$productModels = Mage::getSingleton('catalog/product');
$_products=$productModels->load('999');
echo $_products->getId()."<br>";
Output:
586
586
Working:
$productModel = Mage::getSingleton('catalog/product');
$_product=$productModel->load('999');
echo $_product->getId()."<br>";
$productModels = Mage::getSingleton('catalog/product');
$_products=$productModels->load('586');
echo $_products->getId()."<br>";
Output:
586
Anyone please help!..
You can use Mage::getModel() instead of Mage::getSingleton().
<?php
$productModel = Mage::getModel('catalog/product');
$_product=$productModel->load('586');
echo $_product->getId()."<br>";
$productModels = Mage::getModel('catalog/product');
$_products=$productModels->load('999');
echo $_products->getId()."<br>";
?>
Output
586
Model create new instance when Singleton use original instance.
您可以清除之间的实例。
$_product->clearInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.