0
對於我的magento,我有兩個腳本將描述複製到另一個storeview。從商店1和2如何將這兩個php腳本合併爲一個
腳本1. 拷貝/合併的描述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();
然後我有一個separte文件從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個腳本合併爲一個。這應該是更有效....
我的PHP知識沒有達到那麼遠。你能幫助我嗎? – Ronny
對不起,現在沒有太多時間 –