當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Mage_Catalog_Model_Product_Option::_afterSave方法代碼示例

本文整理匯總了PHP中Mage_Catalog_Model_Product_Option::_afterSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP Mage_Catalog_Model_Product_Option::_afterSave方法的具體用法?PHP Mage_Catalog_Model_Product_Option::_afterSave怎麽用?PHP Mage_Catalog_Model_Product_Option::_afterSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mage_Catalog_Model_Product_Option的用法示例。


在下文中一共展示了Mage_Catalog_Model_Product_Option::_afterSave方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _afterSave

 protected function _afterSave()
 {
     if (!Mage::helper('customoptions')->isEnabled() || Mage::app()->getRequest()->getControllerName() != 'catalog_product' && Mage::app()->getRequest()->getControllerName() != 'adminhtml_catalog_product') {
         return parent::_afterSave();
     }
     $optionId = $this->getData('option_id');
     $defaultArray = $this->getData('default') ? $this->getData('default') : array();
     $tablePrefix = (string) Mage::getConfig()->getTablePrefix();
     $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
     $helper = Mage::helper('customoptions');
     $storeId = $this->getProduct()->getStoreId();
     if (is_array($this->getData('values'))) {
         $values = array();
         foreach ($this->getData('values') as $key => $value) {
             if (isset($value['option_type_id'])) {
                 if (isset($value['dependent_ids']) && $value['dependent_ids'] != '') {
                     $dependentIds = array();
                     $dependentIdsTmp = explode(',', $value['dependent_ids']);
                     foreach ($dependentIdsTmp as $d_id) {
                         if ($this->decodeViewIGI($d_id) > 0) {
                             $dependentIds[] = $this->decodeViewIGI($d_id);
                         }
                     }
                     $value['dependent_ids'] = implode(',', $dependentIds);
                 }
                 $value['sku'] = trim($value['sku']);
                 // prepare customoptions_qty
                 $customoptionsQty = '';
                 if (isset($value['customoptions_qty']) && (!$helper->isSkuQtyLinkingEnabled() || $helper->getProductIdBySku($value['sku']) == 0)) {
                     $customoptionsQty = strtolower(trim($value['customoptions_qty']));
                     if (substr($customoptionsQty, 0, 1) != 'x' && substr($customoptionsQty, 0, 1) != 'i' && substr($customoptionsQty, 0, 1) != 'l' && !is_numeric($customoptionsQty)) {
                         $customoptionsQty = '';
                     }
                     if (is_numeric($customoptionsQty)) {
                         $customoptionsQty = intval($customoptionsQty);
                     }
                     if (substr($customoptionsQty, 0, 1) == 'i') {
                         $customoptionsQty = $this->decodeViewIGI($customoptionsQty);
                     }
                 }
                 $optionValue = array('option_id' => $optionId, 'sku' => $value['sku'], 'sort_order' => $value['sort_order'], 'customoptions_qty' => $customoptionsQty, 'default' => array_search($key, $defaultArray) !== false ? 1 : 0, 'in_group_id' => $value['in_group_id']);
                 if (isset($value['dependent_ids'])) {
                     $optionValue['dependent_ids'] = $value['dependent_ids'];
                 }
                 if (isset($value['weight'])) {
                     $optionValue['weight'] = $value['weight'];
                 }
                 if (isset($value['cost'])) {
                     $optionValue['cost'] = $value['cost'];
                 }
                 $optionTypePriceId = 0;
                 if ($helper->isSkuNameLinkingEnabled() && (!isset($value['scope']['title']) || $value['scope']['title'] != 1) && (!isset($value['title']) || $value['title'] == '') && $value['sku']) {
                     $value['title'] = $helper->getProductNameBySku($value['sku'], $storeId);
                 }
                 if (isset($value['option_type_id']) && $value['option_type_id'] > 0) {
                     $optionTypeId = $value['option_type_id'];
                     if ($value['is_delete'] == '1') {
                         $connection->delete($tablePrefix . 'catalog_product_option_type_value', 'option_type_id = ' . $optionTypeId);
                         $helper->deleteOptionFile(null, $optionId, $optionTypeId);
                     } else {
                         $connection->update($tablePrefix . 'catalog_product_option_type_value', $optionValue, 'option_type_id = ' . $optionTypeId);
                         // update or insert price
                         $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_price', array('option_type_price_id'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                         $optionTypePriceId = $isUpdate = $connection->fetchOne($select);
                         if (isset($value['price']) && isset($value['price_type'])) {
                             $priceValue = array('price' => $value['price'], 'price_type' => $value['price_type']);
                             if ($isUpdate) {
                                 $connection->update($tablePrefix . 'catalog_product_option_type_price', $priceValue, 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                             } else {
                                 $priceValue['option_type_id'] = $optionTypeId;
                                 $priceValue['store_id'] = $storeId;
                                 $connection->insert($tablePrefix . 'catalog_product_option_type_price', $priceValue);
                                 $optionTypePriceId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_price');
                             }
                         } elseif (isset($value['scope']['price']) && $value['scope']['price'] == 1 && $isUpdate && $storeId > 0) {
                             $connection->delete($tablePrefix . 'catalog_product_option_type_price', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                             $optionTypePriceId = -1;
                         }
                         // update or insert title
                         if ($storeId > 0) {
                             $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_title', array('COUNT(*)'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                             $isUpdate = $connection->fetchOne($select);
                         } else {
                             $isUpdate = 1;
                         }
                         if (isset($value['title'])) {
                             if ($isUpdate) {
                                 $connection->update($tablePrefix . 'catalog_product_option_type_title', array('title' => $value['title']), 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                             } else {
                                 $connection->insert($tablePrefix . 'catalog_product_option_type_title', array('option_type_id' => $optionTypeId, 'store_id' => $storeId, 'title' => $value['title']));
                             }
                         } elseif (isset($value['scope']['title']) && $value['scope']['title'] == 1 && $isUpdate && $storeId > 0) {
                             $connection->delete($tablePrefix . 'catalog_product_option_type_title', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                         }
                         // update or insert description
                         if (isset($value['description']) || isset($value['scope']['description'])) {
                             $select = $connection->select()->from($tablePrefix . 'custom_options_option_type_description', array('COUNT(*)'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId);
                             $isUpdate = $connection->fetchOne($select);
                         }
                         if (isset($value['description']) && $value['description'] != '') {
//.........這裏部分代碼省略.........
開發者ID:xiaoguizhidao,項目名稱:cupboardglasspipes.ecomitize.com,代碼行數:101,代碼來源:Option.php


注:本文中的Mage_Catalog_Model_Product_Option::_afterSave方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。