对于我的magento,我有两个脚本将描述复制到另一个storeview。
脚本1。将store 1和2的描述复制/合并到storeview 6
<?php
require_once 'abstract.php';
class Mage_Shell_DescMerge extends Mage_Shell_Abstract
{
const STORE_ID_1 = 1; // Replace this with correct value
const STORE_ID_2 = 2; // Replace this with correct value
const STORE_DESTINATION = 6; // Replace this with correct value
public function run()
{
$catalogResourceModel = Mage::getResourceModel('catalog/product');
$catalogAction = Mage::getSingleton('catalog/product_action');
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product) {
$productId = $product->getId();
if($product->getId() >= 29932)
{
echo "Updating product $productId'n";
$descrStore1 = $catalogResourceModel
->getAttributeRawValue($productId, 'description', static::STORE_ID_1);
$descrStore2 = $catalogResourceModel
->getAttributeRawValue($productId, 'description', static::STORE_ID_2);
$attrs = array(
'description' => $descrStore1.'<br />'.$descrStore2,
);
$catalogAction
->updateAttributes(array($productId), $attrs, static::STORE_DESTINATION);
}
else {}
}
}
}
$shell = new Mage_Shell_DescMerge();
$shell->run();
然后我有一个单独的文件,将描述从storeview 2复制到storeview 3。
<?php
require_once 'abstract.php';
class Mage_Shell_DescMerge extends Mage_Shell_Abstract
{
const STORE_ID_2 = 2; // Replace this with correct value
const STORE_DESTINATION = 3; // Replace this with correct value
public function run()
{
$catalogResourceModel = Mage::getResourceModel('catalog/product');
$catalogAction = Mage::getSingleton('catalog/product_action');
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product) {
$productId = $product->getId();
if($product->getId() >= 29932)
{
echo "Updating product $productId'n";
$descrStore2 = $catalogResourceModel
->getAttributeRawValue($productId, 'description', static::STORE_ID_2);
$attrs = array(
'description' => $descrStore2,
);
$catalogAction
->updateAttributes(array($productId), $attrs, static::STORE_DESTINATION);
}
else {}
}
}
}
$shell = new Mage_Shell_DescMerge();
$shell->run();
我每隔几天就运行这些脚本。我怎么能把这2个脚本合并成一个。这应该更有效率....
传递一个带有run方法的数组,并使用它来代替static::STORE_ID_*,另外static::STORE_DESTINATION需要与run方法的另一个参数一起传递。另一个注意事项-您需要在static::STORE_ID_*