2013-02-25 34 views
1

我有一個Magento 1.5.0.1安裝與3個不同的商店意見。在此過程中,有兩個商店不使用產品屬性的默認值。我試圖找到一種方法讓所有產品都使用所有商店的默認值,這樣客戶端只需要在一個地方進行更新。我發現this文章,但它似乎只適用於專門稱爲產品。任何人都可以解釋如何在我的情況下使用該代碼?或者建議新的代碼?設置所有商品默認值全部商店

+0

您有任何想法條目其他商店創建時。 – 2013-05-07 12:57:20

回答

6

我能得到這個工作的唯一辦法是通過MySQL的:

DELETE FROM `catalog_product_entity_text` where store_id != 0; 
DELETE FROM `catalog_product_entity_datetime` where store_id != 0; 
DELETE FROM `catalog_product_entity_decimal` where store_id != 0; 
DELETE FROM `catalog_product_entity_int` where store_id != 0; 
DELETE FROM `catalog_product_entity_varchar` where store_id != 0; 

以上將重置所有產品中使用默認值的所有屬性。

+0

這工作偉大的人感謝! – 2013-04-03 17:31:31

0

您應該使用Mage :: getSingleton('catalog/product_action')來更新連續的很多產品。

1°)得到你想要的產品的ID,對所有產品使用:

$ids = Mage::getModel('catalog/product')->getCollection()->getAllIds(); 

2°)使屬性的列表和值相關聯的 「假」

$attributes = array('name'=>false,'description'=>false,....) 

3°)拿起店內的ID列表改變,並將其設置在數組中太:

$stores = array(1,2,3); 

然後創建腳本:

foreach ($stores as $store_id) 
{ 
    Mage::getSingleton('catalog/product_action')->updateAttributes($ids, $attributes, $store_id); 
} 

將所有產品都更新(IDS)來設置屬性在STORE_ID默認(感謝「假」值)。

+0

好的,我在這裏創建了我的腳本文件:http://pastebin.com/yc9BY8XC和我上傳到我的magento根,製作可執行文件並運行它,但我得到錯誤。你能幫我弄清楚這個想法嗎? – 2013-03-04 19:38:48

+0

你可以嘗試只有一個屬性?你有什麼錯誤信息? – dagfr 2013-03-04 20:38:17

+0

我試圖從SSH會話中運行它,它給了我沒有任何意義的錯誤。然後,我使用網絡瀏覽器瀏覽文件,腳本似乎運行,因爲現在商店沒有在前端顯示任何產品。該腳本似乎清除了所有產品上的所有字段,但未檢查「使用默認值」框。有任何想法嗎?我的完整腳本在這裏:http://pastebin.com/fpv6qxGi – 2013-03-05 22:10:52

0

這將需要已設置的任何存儲值和合並那些到默認值的所有產品:

 <?php 
    $cat = mysql_connect("host", "user", "password") or die(mysql_error()); 
     mysql_select_db("database",$cat) or die(mysql_error()); 

     $types = array(
     'catalog_product_entity_text', 
     'catalog_product_entity_datetime', 
     'catalog_product_entity_decimal', 
    'catalog_product_entity_int', 
    'catalog_product_entity_varchar' 
    ); 

    foreach($types as $type){ 

    $result = mysql_query("select * from $type where store_id != 0",$cat) or die(mysql_error()); 

     while ($row = mysql_fetch_assoc($result)) { 

      if(!is_null($row['value'])){ 

       mysql_query("update $type set value = '".mysql_real_escape_string(stripslashes($row['value']))."' 
       where store_id = '0' 
       and entity_id = '".$row['entity_id']."' 
       and attribute_id = '".$row['attribute_id']."'",$cat) or die(mysql_error()); 
      } 

      mysql_query("delete from $type where value_id = '".$row['value_id']."'",$cat) or die(mysql_error()); 

     } 

    } 
?>