/** * Get option html block * * @param Mage_Catalog_Model_Product_Option $option * * @return string */ public function getOptionHtml(Mage_Catalog_Model_Product_Option $option) { $renderer = $this->getOptionRender($this->getGroupOfOption($option->getType())); if (is_null($renderer['renderer'])) { $renderer['renderer'] = $this->getLayout()->createBlock($renderer['block'])->setTemplate($renderer['template'])->setSkipJsReloadPrice(1); } return $renderer['renderer']->setProduct($this->getProduct())->setOption($option)->toHtml(); }
public function getProductCount() { $product = new Mage_Catalog_Model_Product_Option(); $collection = $product->getCollection()->addFieldToFilter('type', array('eq' => 'aitcustomer_image')); $collection->getSelect()->group('product_id'); $collection->load(); return $collection->count(); }
public function getOptionHtml(Mage_Catalog_Model_Product_Option $option) { $type = $option->getType(); if (empty($type)) { return; } return parent::getOptionHtml($option); }
/** * Returns true if final price of product depends on given option * * @param Mage_Catalog_Model_Product_Option $option * @return boolean */ public function isOptionAffectingPrice(Mage_Catalog_Model_Product_Option $option) { foreach ($option->getValuesCollection() as $value) { /* @var $value Mage_Catalog_Model_Product_Option_Value */ if ($value->getPrice() * 1 > 0) { return true; } } return false; }
/** * Get option html * * @param Mage_Catalog_Model_Product_Option $option * @return string */ public function getOptionHtml($option) { if (!isset($this->_optionRenderers[$option->getType()])) { return $this->__('There is no defined renderer for "%s" option type.', $option->getType()); } $html = $this->getLayout()->createBlock($this->_optionRenderers[$option->getType()])->setOption($option)->setProduct($this->getProduct())->toHtml(); $html = str_replace('bundle.changeSelection(this)', 'return;', $html); $html = str_replace('name="bundle_option[', 'name="cart[' . $this->getItem()->getId() . '][bundle_option][', $html); $html = str_replace('name="bundle_option_qty[', 'name="cart[' . $this->getItem()->getId() . '][bundle_option_qty][', $html); return $html; }
/** * Converts option object to the array representation * * @param Mage_Catalog_Model_Product_Option $option otion to convert * @return array */ public function _convertToArray($option) { $commonArgs = array('is_delete', 'previous_type', 'previous_group', 'title', 'type', 'is_require', 'sort_order', 'values'); $priceArgs = array('price_type', 'price', 'sku'); $txtArgs = array('max_characters'); $fileArgs = array('file_extension', 'image_size_x', 'image_size_y'); $type = $option->getType(); switch ($type) { case 'file': $optionArgs = array_merge($commonArgs, $priceArgs, $fileArgs); break; case 'field': case 'area': $optionArgs = array_merge($commonArgs, $priceArgs, $txtArgs); break; case 'date': case 'date_time': case 'time': $optionArgs = array_merge($commonArgs, $priceArgs); break; default: $optionArgs = $commonArgs; } $optionAsArray = $option->toArray($optionArgs); if (in_array($type, array('drop_down', 'radio', 'checkbox', 'multiple'))) { $valueArgs = array_merge(array('is_delete', 'title', 'sort_order'), $priceArgs); $optionAsArray['values'] = array(); foreach ($option->getValues() as $value) { $optionAsArray['values'][] = $value->toArray($valueArgs); } } return $optionAsArray; }
public function groupFactory($type) { //if (!Mage::helper('giftcard')->isActive()) // return parent::groupFactory($type); if ($type === self::OPTION_TYPE_GIFT_CARD_VALUE) { return Mage::getModel('giftcard/catalog_product_option_type_giftcardvalue'); } return parent::groupFactory($type); }
/** * Get group name of option by given option type * * @param string $type * @return string */ public function getGroupByType($type = null) { if (is_null($type)) { $type = $this->getType(); } $swatch_id = str_replace(self::OPTION_GROUP_SWATCH . '_', '', $type); $swatch = Mage::getModel('swatches/input')->load($swatch_id); if ($swatch && $swatch->getSwatchId()) { return self::OPTION_GROUP_SWATCH; } return parent::getGroupByType($type); }
/** * 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; }
/** * 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; }
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'] != '') { if ($isUpdate) { $connection->update($tablePrefix . 'custom_options_option_type_description', array('description' => $value['description']), 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } else { $connection->insert($tablePrefix . 'custom_options_option_type_description', array('option_type_id' => $optionTypeId, 'store_id' => $storeId, 'description' => $value['description'])); } } elseif (isset($value['scope']['description']) && $value['scope']['description'] == 1 && $isUpdate && $storeId > 0 || isset($value['description']) && $value['description'] == '') { $connection->delete($tablePrefix . 'custom_options_option_type_description', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } } } else { if ($value['is_delete'] == '1') { continue; } $connection->insert($tablePrefix . 'catalog_product_option_type_value', $optionValue); $optionTypeId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_value'); if (isset($value['price']) && isset($value['price_type'])) { // save not default //if ($storeId>0) $connection->insert($tablePrefix . 'catalog_product_option_type_price', array('option_type_id' =>$optionTypeId, 'store_id'=>$storeId, 'price' => $value['price'], 'price_type' => $value['price_type'])); // save default $connection->insert($tablePrefix . 'catalog_product_option_type_price', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'price' => $value['price'], 'price_type' => $value['price_type'])); $optionTypePriceId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_price'); } if (isset($value['title'])) { // save default $connection->insert($tablePrefix . 'catalog_product_option_type_title', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'title' => $value['title'])); } if (isset($value['description']) && $value['description'] != '') { // save default $connection->insert($tablePrefix . 'custom_options_option_type_description', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'description' => $value['description'])); } } if ($optionTypeId > 0 && $optionTypePriceId >= 0) { $id = $this->getData('id'); $this->_uploadImage('file_' . $id . '_' . $key, $optionId, $optionTypeId, $value); // check $optionTypePriceId if ($optionTypePriceId == 0) { $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 ($optionTypePriceId) { // save special prices if (isset($value['specials']) && is_array($value['specials'])) { $specials = array(); foreach ($value['specials'] as $special) { if ($special['is_delete'] == '1' || isset($specials[$special['customer_group_id']])) { if ($special['special_price_id'] > 0) { $connection->delete($tablePrefix . 'custom_options_option_type_special_price', 'option_type_special_price_id = ' . intval($special['special_price_id'])); } continue; } $specials[$special['customer_group_id']] = $special; } if (count($specials) > 0) { foreach ($specials as $special) { $zendDate = new Zend_Date(); $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); if ($special['date_from']) { $special['date_from'] = $zendDate->setDate($special['date_from'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $special['date_from'] = null; } if ($special['date_to']) { $special['date_to'] = $zendDate->setDate($special['date_to'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $special['date_to'] = null; } $specialData = array('option_type_price_id' => $optionTypePriceId, 'customer_group_id' => $special['customer_group_id'], 'price' => floatval($special['price']), 'price_type' => $special['price_type'], 'comment' => trim($special['comment']), 'date_from' => $special['date_from'], 'date_to' => $special['date_to']); if ($special['special_price_id'] > 0) { $connection->update($tablePrefix . 'custom_options_option_type_special_price', $specialData, 'option_type_special_price_id = ' . intval($special['special_price_id'])); } else { $connection->insert($tablePrefix . 'custom_options_option_type_special_price', $specialData); } } } } // save tier prices if (isset($value['tiers']) && is_array($value['tiers'])) { $tiers = array(); foreach ($value['tiers'] as $tier) { $uniqKey = $tier['qty'] . '+' . $tier['customer_group_id']; if ($tier['is_delete'] == '1' || isset($tiers[$uniqKey])) { if ($tier['tier_price_id'] > 0) { $connection->delete($tablePrefix . 'custom_options_option_type_tier_price', 'option_type_tier_price_id = ' . intval($tier['tier_price_id'])); } continue; } $tiers[$uniqKey] = $tier; } if (count($tiers) > 0) { foreach ($tiers as $tier) { $tierData = array('option_type_price_id' => $optionTypePriceId, 'customer_group_id' => $tier['customer_group_id'], 'qty' => intval($tier['qty']), 'price' => floatval($tier['price']), 'price_type' => $tier['price_type']); if ($tier['tier_price_id'] > 0) { $connection->update($tablePrefix . 'custom_options_option_type_tier_price', $tierData, 'option_type_tier_price_id = ' . intval($tier['tier_price_id'])); } else { $connection->insert($tablePrefix . 'custom_options_option_type_tier_price', $tierData); } } } } } } unset($value['option_type_id']); } $values[$key] = $value; } $this->setData('values', $values); } elseif ($this->getGroupByType($this->getType()) == self::OPTION_GROUP_SELECT) { Mage::throwException(Mage::helper('catalog')->__('Select type options required values rows.')); } if (version_compare($helper->getMagetoVersion(), '1.4.0', '>=')) { $this->cleanModelCache(); } Mage::dispatchEvent('model_save_after', array('object' => $this)); if (version_compare($helper->getMagetoVersion(), '1.4.0', '>=')) { Mage::dispatchEvent($this->_eventPrefix . '_save_after', $this->_getEventData()); } return $this; }
/** * Enter description here... * * @param Mage_Catalog_Model_Product_Option $option * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value_Collection */ public function getValuesCollection(Mage_Catalog_Model_Product_Option $option) { $collection = Mage::getResourceModel('catalog/product_option_value_collection')->addFieldToFilter('option_id', $option->getId())->getValues($option->getStoreId()); return $collection; }
/** * Save options. * * @return Mage_Catalog_Model_Product_Option */ public function saveOptions() { /* {#AITOC_COMMENT_END#} Mage::app()->removeCache('aitsys_used_product_count_aitcg_count'); if($this->getProduct()->getData('status') == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { $bHasAitOption = false; $updateOptions = array(); foreach ($this->getOptions() as $iKey => $aOption) { if( Mage::helper('aitcg/options')->checkAitOption( $aOption ) ) { if($aOption['option_id'] == 0) { $bHasAitOption = true; break; } $updateOptions[ $aOption['option_id'] ] = $aOption['is_delete']; } } if($bHasAitOption == false) { foreach ($this->getProduct()->getOptions() as $iKey => $aOption) { if(Mage::helper('aitcg/options')->checkAitOption( $aOption )) { if(!isset($updateOptions[ $aOption->getId() ]) || $updateOptions[ $aOption->getId() ]!=1) { $bHasAitOption = true; break; } } } } if($bHasAitOption) { $performer = Aitoc_Aitsys_Abstract_Service::get()->platform()->getModule('Aitoc_Aitcg')->getLicense()->getPerformer(); $ruler = $performer->getRuler(); $ruler->checkRuleAdd($this->getProduct(), true); } } {#AITOC_COMMENT_START#} */ parent::saveOptions(); }
/** * @covers Mage_Catalog_Model_Product::addOption * @covers Mage_Catalog_Model_Product::getOptionById * @covers Mage_Catalog_Model_Product::getOptions */ public function testOptionApi() { $this->assertEquals(array(), $this->_model->getOptions()); $optionId = uniqid(); $option = new Mage_Catalog_Model_Product_Option(array('key' => 'value')); $option->setId($optionId); $this->_model->addOption($option); $this->assertSame($option, $this->_model->getOptionById($optionId)); $this->assertEquals(array($optionId => $option), $this->_model->getOptions()); }
public function getProductOptionCollection(Mage_Catalog_Model_Product $product) { $action = Mage::app()->getFrontController()->getAction()->getFullActionName(); if ($action == "catalog_category_view") { return parent::getProductOptionCollection($product); } $helper = Mage::helper('mageworx_customoptions'); $collection = $this->getCollection()->addFieldToFilter('product_id', $product->getId())->addTitleToResult($product->getStoreId())->addPriceToResult($product->getStoreId())->addViewModeToResult($product->getStoreId())->addDescriptionToResult($product->getStoreId())->addDefaultTextToResult($product->getStoreId())->setOrder('sort_order', 'asc')->setOrder('title', 'asc'); $isProductEditPage = Mage::app()->getStore()->isAdmin() && Mage::app()->getRequest()->getControllerName() == 'catalog_product'; if ($isProductEditPage) { $collection->addTemplateTitleToResult(); } $collection->addValuesToResult($product->getStoreId()); if (!$isProductEditPage) { // filter by view_mode $isRequire = false; foreach ($collection as $key => $item) { // 0-Disable, 1-Visible, 2-Hidden, 3-Backend, 4-Admin Only if ($item->getViewMode() == 0 && !is_null($item->getViewMode())) { $collection->removeItemByKey($key); } elseif (!Mage::app()->getStore()->isAdmin() && ($item->getViewMode() == 3 || $item->getViewMode() == 4)) { $collection->removeItemByKey($key); } elseif ($item->getIsRequire(true)) { $isRequire = true; } } if (!$isRequire) { $product->setRequiredOptions(0); } if (count($collection) == 0) { $product->setHasOptions(0); } $customerGroupId = $helper->getCustomerGroupId(); // filter by CustomerGroups if ($helper->isCustomerGroupsEnabled()) { $isRequire = false; foreach ($collection as $key => $item) { $groups = $item->getCustomerGroups(); if ($groups !== '' && !in_array($customerGroupId, explode(',', $groups))) { $collection->removeItemByKey($key); } elseif ($item->getIsRequire(true)) { $isRequire = true; } } if (!$isRequire) { $product->setRequiredOptions(0); } if (count($collection) == 0) { $product->setHasOptions(0); } } $storeViewId = Mage::app()->getStore()->getId(); // filter by StoreViews if ($helper->isStoreViewsEnabled()) { $isRequire = false; foreach ($collection as $key => $item) { $storeViews = $item->getStoreViews(); if ($storeViews !== '' && !in_array($storeViewId, explode(',', $storeViews))) { $collection->removeItemByKey($key); } elseif ($item->getIsRequire(true)) { $isRequire = true; } } if (!$isRequire) { $product->setRequiredOptions(0); } if (count($collection) == 0) { $product->setHasOptions(0); } } // recheck inventory if ($product->getRequiredOptions()) { if ($helper->isInventoryEnabled() && ($helper->getOutOfStockOptions() == 1 || $helper->isSetProductOutOfStock())) { $isDependentEnabled = $helper->isDependentEnabled(); // checkDependentInventory for parent -> set parent option "Out of stock" if ($isDependentEnabled) { foreach ($collection as $option) { if ($this->getGroupByType($option->getType()) != self::OPTION_GROUP_SELECT || count($option->getValues()) == 0) { continue; } foreach ($option->getValues() as $value) { if (!$value->getDependentIds()) { continue; } $customoptionsQty = $helper->getCustomoptionsQty($value->getCustomoptionsQty(), $value->getSku(), $product->getId(), $value->getExtra(), $value); if ($customoptionsQty !== 0 && !$this->checkDependentInventory($collection, $value, $product)) { $value->setCustomoptionsQty(0); } } } } // if all required options "Out of stock" -> set product "Out of stock" foreach ($collection as $option) { if (!$option->getIsRequire(true) || $isDependentEnabled && $option->getIsDependent() || $this->getGroupByType($option->getType()) != self::OPTION_GROUP_SELECT || count($option->getValues()) == 0) { continue; } $outOfStockFlag = true; foreach ($option->getValues() as $value) { $customoptionsQty = $helper->getCustomoptionsQty($value->getCustomoptionsQty(), $value->getSku(), $product->getId(), $value->getExtra(), $value); if (is_numeric($customoptionsQty) && $customoptionsQty != 0) { if ($isDependentEnabled && !$this->checkDependentInventory($collection, $value, $product)) { continue; } $outOfStockFlag = false; break; } } if ($outOfStockFlag) { $product->setData('is_salable', false); break; } } } } } // add images, special_prices, tier_prices $specialPriceEnabled = $helper->isSpecialPriceEnabled(); $tierPriceEnabled = $helper->isTierPriceEnabled(); $helper->getCustomerGroups(); // init customer_groups for sort prices foreach ($collection as $key => $option) { if ($this->getGroupByType($option->getType()) == self::OPTION_GROUP_SELECT) { $values = $option->getValues(); if (count($values) == 0) { continue; } foreach ($values as $value) { // add images to optionValue $value->setImages($this->getOptionValueImages($value->getOptionTypeId())); // link data (price, special_price, group_prices, tier_prices) by sku -> and skip special_prices, tier_prices from option if (!$helper->applyLinkedBySkuDataToOption($value, $value->getSku(), $product->getStore(), $product->getTaxClassId())) { // add special_prices if ($specialPriceEnabled) { $value->setSpecials($this->getOptionValueSpecialPrices($value->getOptionTypePriceId())); } // add tier_prices if ($tierPriceEnabled) { $value->setTiers($this->getOptionValueTierPrices($value->getOptionTypePriceId())); } } $helper->calculateOptionSpecialPrice($value, $product, $specialPriceEnabled); $value->setIsPriceCalculated(true); } } else { if ($helper->applyLinkedBySkuDataToOption($option, $option->getSku(), $product->getStore(), $product->getTaxClassId())) { $helper->calculateOptionSpecialPrice($option, $product, false); } $option->setIsPriceCalculated(true); } } return $collection; }
/** * Get all custom option values prices * * @param Mage_Catalog_Model_Product_Option $option * @return array */ protected function _getCustomOptionValuesPrices($option) { $values = $option->getValues(); $prices = array(); if ($values) { foreach ($values as $value) { /* @var $value Mage_Catalog_Model_Product_Option_Value */ $prices[] = $value->getPrice(true); } } return $prices; }
/** * Check whether specified option could have multiple values * * @param Mage_Catalog_Model_Product_Option $option * @return bool */ protected function _isOptionMultiple($option) { switch ($option->getType()) { case Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE: case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX: return true; } return false; }
/** * * @param string $filename * @param resource $image * @param Mage_Catalog_Model_Product_Option $option */ protected function _uploadPhoto($filename, $image, $option) { $result = array(); $optionFile = $option->groupFactory($option->getType()); $extension = pathinfo(strtolower($filename), PATHINFO_EXTENSION); $filename = Mage_Core_Model_File_Uploader::getCorrectFileName($filename); $dispersion = Mage_Core_Model_File_Uploader::getDispretionPath($filename); $quoteDir = $optionFile->getQuoteTargetDir() . $dispersion; $uploadDir = Mage::helper('aydus_customconfigurable')->getMediaDir() . DS . $dispersion; if (!file_exists($quoteDir)) { mkdir($quoteDir, 0775, true); } if (!file_exists($uploadDir)) { mkdir($uploadDir, 0775, true); } $hash = md5($image); $filenameHash = $hash . '.' . $extension; $quoteFilePath = $quoteDir . DS . $filenameHash; $size = file_put_contents($quoteFilePath, $image); $result['error'] = $size > 0 ? false : true; if ($result['error']) { $result['data'] = 'File upload failed'; } else { $time = time(); $uploadFilePath = $uploadDir . DS . $time . '-' . $filename; if (copy($quoteFilePath, $uploadFilePath)) { $result['data'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'aydus' . DS . 'customconfigurable' . $dispersion . DS . $time . '-' . $filename; } else { $result['error'] = true; $result['data'] = 'Could not copy uploaded image to ' . $uploadFilePath . '; check permissions'; } } return $result; }
/** * Add option to array of product options * * @param Mage_Catalog_Model_Product_Option $option * @return Mage_Catalog_Model_Product */ public function addOption(Mage_Catalog_Model_Product_Option $option) { $this->_options[$option->getId()] = $option; return $this; }
/** * Retrieve option values or false for options which has no values * * @param Mage_Catalog_Model_Product_Option $option * @return array|bool */ protected function _getOptionValues(Mage_Catalog_Model_Product_Option $option) { $values = $option->getValues(); if (!empty($values)) { $result = array(); /** @var $value Mage_Catalog_Model_Product_Option_Value */ foreach ($values as $value) { $optionData = array(); foreach ($this->_assertOptionValues as $assertKey) { if ($value->hasData($assertKey)) { $optionData[$assertKey] = $value->getData($assertKey); } } $result[] = $optionData; } return $result; } return false; }
/** * Get option html * * @param Mage_Catalog_Model_Product_Option $option * @return string */ public function getOptionHtml($option) { if (!isset($this->_optionRenderers[$option->getType()])) { return $this->__('There is no defined renderer for "%s" option type.', $option->getType()); } return $this->getLayout()->createBlock($this->_optionRenderers[$option->getType()])->setOption($option)->toHtml(); }
protected function _construct() { parent::_construct(); $this->_init('customoptions/product_option'); }