[英]How can i Merge these two php scripts into one
對於我的magento,我有2個腳本將說明復制到其他storeview。
腳本1.將描述從商店1和2復制/合並到商店視圖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();
我每隔幾天運行一次這些腳本。 我如何將這兩個腳本合並為一個。 哪個應該更有效....
用run方法傳遞一個數組,並使用它代替static :: STORE_ID_ *,而static :: STORE_DESTINATION也需要傳遞run方法的另一個參數。 另一個注意事項-您需要在static :: STORE_ID_ *的基礎上正確更改$ attrs ['description']變量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.