在搜索了很长时间并且未能从法师核心文件中提取解决方案后,我创建了一个与属性相同的status
属性。我将该属性命名为Archive
(是/否)。这个新属性将证明产品是否停产。
Atlast,我只过滤与此新属性相关的所有产品列表、产品详细信息和主页Archive
。
我计划编写一个 MVC 操作,它将更改所有产品status
,enabled
同时触发产品的Archive
as yes status = disabled
。我很快就会在这里分享代码。
代码:
编写一个虚拟控制器,在调用 url 时运行以下代码:
public function updateproductsAction() {
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->addAttributeToFilter('entity_id', array('gt' => 0)); // This line should be removed to affect all the configurable products. (to avoid execution time-out)
echo 'Total are ' . count($collectionConfigurable) . '<br/>';
$i = 1;
foreach($collectionConfigurable as $p) {
$product = Mage::getModel('catalog/product')->load($p->getId());
$product->save();
echo $i++ . ') The product Id with ' . $p->getId() . " is done...." . "<br/>"; // if the execution time-out occurs, note down the last product id and change the value above in addAttributeToFilter. so the execution runs from the last stopped product.
}
}