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


PHP Mage_Catalog_Model_Product_Option::getValueInstance方法代碼示例

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


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

示例1: duplicate

 /**
  * Duplicate custom options for product
  *
  * @param Mage_Catalog_Model_Product_Option $object
  * @param int $oldProductId
  * @param int $newProductId
  * @return Mage_Catalog_Model_Product_Option
  */
 public function duplicate(Mage_Catalog_Model_Product_Option $object, $oldProductId, $newProductId)
 {
     $write = $this->_getWriteAdapter();
     $read = $this->_getReadAdapter();
     $optionsCond = array();
     $optionsData = array();
     // read and prepare original product options
     $select = $read->select()->from($this->getTable('catalog/product_option'))->where('product_id=?', $oldProductId);
     $query = $read->query($select);
     while ($row = $query->fetch()) {
         $optionsData[$row['option_id']] = $row;
         $optionsData[$row['option_id']]['product_id'] = $newProductId;
         unset($optionsData[$row['option_id']]['option_id']);
     }
     // insert options to duplicated product
     foreach ($optionsData as $oId => $data) {
         $write->insert($this->getMainTable(), $data);
         $optionsCond[$oId] = $write->lastInsertId();
     }
     // copy options prefs
     foreach ($optionsCond as $oldOptionId => $newOptionId) {
         // title
         $table = $this->getTable('catalog/product_option_title');
         $sql = 'REPLACE INTO `' . $table . '` ' . 'SELECT NULL, ' . $newOptionId . ', `store_id`, `title`' . 'FROM `' . $table . '` WHERE `option_id`=' . $oldOptionId;
         $this->_getWriteAdapter()->query($sql);
         // price
         $table = $this->getTable('catalog/product_option_price');
         $sql = 'REPLACE INTO `' . $table . '` ' . 'SELECT NULL, ' . $newOptionId . ', `store_id`, `price`, `price_type`' . 'FROM `' . $table . '` WHERE `option_id`=' . $oldOptionId;
         $this->_getWriteAdapter()->query($sql);
         // description
         $table = $this->getTable('customoptiondescription/product_option_description');
         $sql = 'REPLACE INTO `' . $table . '` ' . 'SELECT NULL, ' . $newOptionId . ', `store_id`, `description`' . 'FROM `' . $table . '` WHERE `option_id`=' . $oldOptionId;
         $this->_getWriteAdapter()->query($sql);
         $object->getValueInstance()->duplicate($oldOptionId, $newOptionId);
     }
     return $object;
 }
開發者ID:xiaoguizhidao,項目名稱:BumblebeeSite,代碼行數:45,代碼來源:Option.php

示例2: duplicate

 /**
  * Duplicate custom options for product
  *
  * @param Mage_Catalog_Model_Product_Option $object
  * @param int $oldProductId
  * @param int $newProductId
  * @return Mage_Catalog_Model_Product_Option
  */
 public function duplicate(Mage_Catalog_Model_Product_Option $object, $oldProductId, $newProductId)
 {
     $write = $this->_getWriteAdapter();
     $read = $this->_getReadAdapter();
     $optionsCond = array();
     $optionsData = array();
     // read and prepare original product options
     $select = $read->select()->from($this->getTable('catalog/product_option'))->where('product_id = ?', $oldProductId);
     $query = $read->query($select);
     while ($row = $query->fetch()) {
         $optionsData[$row['option_id']] = $row;
         $optionsData[$row['option_id']]['product_id'] = $newProductId;
         unset($optionsData[$row['option_id']]['option_id']);
     }
     // insert options to duplicated product
     foreach ($optionsData as $oId => $data) {
         $write->insert($this->getMainTable(), $data);
         $optionsCond[$oId] = $write->lastInsertId($this->getMainTable());
     }
     // copy options prefs
     foreach ($optionsCond as $oldOptionId => $newOptionId) {
         // title
         $table = $this->getTable('catalog/product_option_title');
         $select = $this->_getReadAdapter()->select()->from($table, array(new Zend_Db_Expr($newOptionId), 'store_id', 'title'))->where('option_id = ?', $oldOptionId);
         $insertSelect = $write->insertFromSelect($select, $table, array('option_id', 'store_id', 'title'), Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
         $write->query($insertSelect);
         // price
         $table = $this->getTable('catalog/product_option_price');
         $select = $read->select()->from($table, array(new Zend_Db_Expr($newOptionId), 'store_id', 'price', 'price_type'))->where('option_id = ?', $oldOptionId);
         $insertSelect = $write->insertFromSelect($select, $table, array('option_id', 'store_id', 'price', 'price_type'), Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
         $write->query($insertSelect);
         $object->getValueInstance()->duplicate($oldOptionId, $newOptionId);
     }
     return $object;
 }
開發者ID:cewolf2002,項目名稱:magento,代碼行數:43,代碼來源:Option.php


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