Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 以编程方式按存储方式更新自定义选项_Magento - Fatal编程技术网

Magento 以编程方式按存储方式更新自定义选项

Magento 以编程方式按存储方式更新自定义选项,magento,Magento,在保存产品事件后使用observer.php添加/编辑任何产品时,以编程方式按存储方式更新自定义选项 i、 e。 我的magento项目中有两个商店 批发商 零售商 现在,我想添加单个产品,并以不同的价格在两家商店中展示。所以,我使用了带有自定义选项的简单产品 产品名称:T恤 Wholesaler Store ------------------------ Red : 50 Green : 60 Blue : 70 Retailer Store ------------------- Red

在保存产品事件后使用observer.php添加/编辑任何产品时,以编程方式按存储方式更新自定义选项

i、 e。 我的magento项目中有两个商店

  • 批发商
  • 零售商
  • 现在,我想添加单个产品,并以不同的价格在两家商店中展示。所以,我使用了带有自定义选项的简单产品

    产品名称:T恤

    Wholesaler Store
    ------------------------
    Red : 50
    Green : 60
    Blue : 70
    
    Retailer Store
    -------------------
    Red : 150
    Green : 160
    Blue : 170
    

    现在,如果我想在批发商商店增加10卢比和20卢比。在零售商商店中,我们如何继续进行。

    我的问题“以编程方式更新自定义选项值商店智能”得到了解决方案

    第1步: 创建名为Addweb\u Customtabs.xml文件的模块文件 app/etc/module/Addweb\u 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>
    
        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>
    
    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);
                            }
                        }
                    }
                }
            }
        }
    }