2016-09-22 92 views
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個腳本合併爲一個。這應該是更有效....

回答

0

通過與運行方法的數組,並使用它,而不是靜態:: STORE_ID_的*亦靜:: STORE_DESTINATION需要運行方法的另一個參數來傳遞。另一個需要注意的 - 你需要適當地改變$ ATTRS [「說明」]變量靜:: STORE_ID_的基礎上*

+0

我的PHP知識沒有達到那麼遠。你能幫助我嗎? – Ronny

+0

對不起,現在沒有太多時間 –