2015-04-16 1 views
-1

Программного Update Настраиваемого магазин Wise, а любой продукт Add/Edit Использования observer.php после сохранения события по продуктуПрограммного Update Настраиваемого магазина Wise

т.е. У меня есть два магазина в моем проекте Magento

  1. Оптовой продаже
  2. Retailer

Теперь я хочу добавить один продукт и вывести его в оба магазина с различными пр лед. Итак, я использовал Simple Product с пользовательским вариантом.

Имя продукта: T-Shirt

Wholesaler Store 
------------------------ 
Red : 50 
Green : 60 
Blue : 70 

Retailer Store 
------------------- 
Red : 150 
Green : 160 
Blue : 170 

Теперь, если я хочу, чтобы добавить 10RS в Оптовик магазине и 20RS. в магазине розничной торговли, то как мы можем продолжить работу над ним.

ответ

0

Я получил решение для моего вопроса «Программного Update Настраиваемого значения магазина мудр»

Шаг - 1: Создать файл модуль по имени Addweb_Customtabs.xml файлу приложение/и т.д./модуля/Addweb_Customtabs.xml

Here is my Addweb_Customtabs.xml file code 

    <?xml version="1.0"?> 
    <config> 
     <modules> 
      <Addweb_Customtabs> 
       <active>false</active> 
       <codePool>local</codePool> 
      </Addweb_Customtabs> 
     </modules> 
    </config> 

Шаг - 2: Создать config.xml файл приложения/код/​​местные/AddWeb/Customtabs/и т.д./config.xml

Here is my config.xml file code 

    <?xml version="1.0"?> 
    <config> 
     <modules> 
      <Addweb_CustomTabs> 
       <version>0.1.0</version> 
      </Addweb_CustomTabs> 
     </modules> 
     <adminhtml> 
      <events> 
       <catalog_product_prepare_save> 
       <observers> 
        <Addweb_save_product_data> 
         <type>singleton</type> 
         <class>customtabs/observer</class> 
         <method>saveProductTabData</method> 
        </Addweb_save_product_data> 
       </observers> 
       </catalog_product_prepare_save> 
      </events> 
     </adminhtml> 
    </config> 

Шаг - 3: Создать файл Observer.php приложение/код/​​местные/AddWeb/Customtabs/Модель/Observer.php

Here is my Observer.php file code 

public function saveProductTabData(Varien_Event_Observer $observer) {  

     $product = $observer->getEvent()->getProduct(); 
     $websites = Mage::app()->getWebsites(); 
     foreach ($websites as $_eachWebsite) { 
     $_websiteId = $_eachWebsite->getWebsiteId();     
     $website = Mage::app()->getWebsite($website_id);     
     $website->getDefaultGroup(); 

     $websiteObj = new Mage_Core_Model_Website(); 
     $websiteObj->load($_websiteId); 

     $storeIds = $websiteObj->getStoreIds(); 
     if (count($storeIds)) { 
      foreach ($storeIds as $storeId) { 
       $store_code = Mage::getModel('core/store')->load($storeId)->getCode(); 

       $priceTable = 'catalog_product_option_type_price'; 
       $options = $product->getProductOptions(); 
       foreach ($options as $option) { 
        $values = $option->getValues(); 
        foreach($values as $value) { 
         switch($object->getTitle()) { 
          case "Red": 
           $oldPrice = $object->getPrice(); 
           if($storeId == 1) {    // Assuming that Store ID : 1 for Retailer & 2 for Wholesaler 
            $newPrice = $oldPrice + 10; 
           } 
           else if($storeId == 2) { 
            $newPrice = $oldPrice + 20; 
           } 
           break; 
          case "Green": 
           $oldPrice = $object->getPrice(); 
           if($storeId == 1) { 
            $newPrice = $oldPrice + 10; 
           } 
           else if($storeId == 2) { 
            $newPrice = $oldPrice + 20; 
           } 
           break; 
          case "Blue": 
           $oldPrice = $object->getPrice(); 
           if($storeId == 1) { 
            $newPrice = $oldPrice + 10; 
           } 
           else if($storeId == 2) { 
            $newPrice = $oldPrice + 20; 
           } 
           break; 
         } 

         $select = $this->_getReadAdapter()->select() 
           ->from($priceTable, 'option_type_id') 
           ->where('option_type_id = ?', (int)$object->getId()) 
           ->where('store_id = ?', (int)$storeId); 
          $optionTypeId = $this->_getReadAdapter()->fetchOne($select); 

         if ($optionTypeId) { 
          $bind = array(
           'price'   => $newPrice, 
           'price_type' => $priceType 
          ); 
          $where = array(
           'option_type_id = ?' => (int)$optionTypeId, 
           'store_id = ?'   => (int)$storeId 
          ); 

          $this->_getWriteAdapter()->update($priceTable, $bind, $where); 
         } 
         else { 
          $bind = array(
           'option_type_id' => (int)$object->getId(), 
           'store_id'   => (int)$storeId, 
           'price'    => $newPrice, 
           'price_type'  => $priceType 
          ); 

          $this->_getWriteAdapter()->insert($priceTable, $bind); 
         } 
        } 
       } 
      } 
     } 
    } 
} 
Смежные вопросы