本文整理汇总了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'] != '') {
//.........这里部分代码省略.........