本文整理汇总了PHP中Mage_Catalog_Model_Product::getOptionById方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getOptionById方法的具体用法?PHP Mage_Catalog_Model_Product::getOptionById怎么用?PHP Mage_Catalog_Model_Product::getOptionById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getOptionById方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$helper = Mage::helper('mageworx_customoptions');
$basePrice = $finalPrice;
$product->setActualPrice($basePrice);
$finalPrice = 0;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$product->setCurrentPrice($finalPrice);
$option->setProduct($product);
if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT || $option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_TEXT) {
$quoteItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty);
} else {
$price = $helper->getOptionPriceByQty($option, $qty);
if ($price != 0) {
$price = $price / $qty;
}
$finalPrice += $price;
}
}
}
$product->setBaseCustomoptionsPrice($finalPrice);
// for additional info
if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
$finalPrice += $basePrice;
}
}
if (method_exists($this, '_applyOptionsPriceFME')) {
$finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
}
return $finalPrice;
}
示例2: testOptionApi
/**
* @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());
}
示例3: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param float $finalPrice
* @return float
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$basePrice = $finalPrice;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$confItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItemOption($confItemOption);
$finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
}
}
}
return $finalPrice;
}
示例4: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$basePrice = $finalPrice;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$optionValue = $product->getCustomOption('option_' . $option->getId())->getValue();
if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
foreach (split(',', $optionValue) as $value) {
$finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getValueById($value)->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getValueById($value)->getPrice()), $basePrice);
}
} elseif ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
$finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getValueById($optionValue)->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getValueById($optionValue)->getPrice()), $basePrice);
} else {
$finalPrice += $this->_getPricingOptionValue(array('is_percent' => $option->getPriceType() == 'percent' ? true : false, 'pricing_value' => $option->getPrice()), $basePrice);
}
}
}
}
return $finalPrice;
}
示例5: getOptionSku
/**
* Default action to get sku of product with option
*
* @param Mage_Catalog_Model_Product $product Product with Custom Options
* @param string $sku Product SKU without option
* @return string
*/
public function getOptionSku($product, $sku = '')
{
$skuDelimiter = '-';
if (empty($sku)) {
$sku = $product->getData('sku');
}
if ($optionIds = $product->getCustomOption('option_ids')) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $optionId);
$group = $option->groupFactory($option->getType())->setOption($option)->setListener(new Varien_Object());
if ($optionSku = $group->getOptionSku($confItemOption->getValue(), $skuDelimiter)) {
$sku .= $skuDelimiter . $optionSku;
}
if ($group->getListener()->getHasError()) {
$product->setHasError(true)->setMessage($group->getListener()->getMessage());
}
}
}
}
return $sku;
}
示例6: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$basePrice = $finalPrice;
$finalPrice = 0;
$options = array();
$qtyRelatedOption = null;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$options[] = $option;
if ($option->getOptionCode() == $this->_getQtyOptionCode()) {
$qtyRelatedOption = $option;
}
}
}
foreach ($options as $option) {
$optionQty = null;
$quoteItemOptionInfoBuyRequest = unserialize($product->getCustomOption('info_buyRequest')->getValue());
switch ($option->getType()) {
case 'checkbox':
if (isset($quoteItemOptionInfoBuyRequest['options'][$optionId])) {
$optionValues = array();
$optionQtyArr = array();
foreach ($option->getValues() as $key => $itemV) {
if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
$optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
} else {
$optionQty = 1;
}
$optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
}
$optionQty = $optionQtyArr;
break;
}
break;
case 'drop_down':
case 'radio':
if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty'])) {
$optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty']);
} else {
$optionQty = 1;
}
case 'multiple':
if (!isset($optionQty)) {
$optionQty = 1;
}
break;
case 'field':
case 'area':
case 'file':
case 'date':
case 'date_time':
case 'time':
break;
default:
//multiple
$optionQty = 1;
}
$option->setOptionQty($optionQty);
}
$customQty = 0;
if ($qtyRelatedOption) {
foreach ($qtyRelatedOption->getValues() as $_value) {
if (isset($quoteItemOptionInfoBuyRequest['options_' . $qtyRelatedOption->getOptionId() . '_' . $_value->getOptionTypeId() . '_qty'])) {
$customQty += intval($quoteItemOptionInfoBuyRequest['options_' . $qtyRelatedOption->getOptionId() . '_' . $_value->getOptionTypeId() . '_qty']);
}
}
if ($customQty) {
$basePrice = $product->getTierPrice($customQty);
}
}
foreach ($options as $option) {
switch ($option->getType()) {
case 'field':
case 'area':
case 'file':
case 'date':
case 'date_time':
case 'time':
$finalPrice += $this->_getCustomOptionsChargableOptionPrice($option->getPrice(), $option->getPriceType() == 'percent', $basePrice, $qty, $option->getCustomoptionsIsOnetime());
break;
case 'drop_down':
case 'radio':
case 'checkbox':
$quoteItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$optionPrice = $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $option != $qtyRelatedOption ? $customQty : $qty, $option->getOptionQty());
if ($option != $qtyRelatedOption && $customQty) {
$optionPrice *= $customQty;
}
$finalPrice += $optionPrice;
}
//.........这里部分代码省略.........
示例7: getProductSku
/**
* Since it's a bad practice to overwrite core magento abstract classes via
* copying the source in the local folder structure, this method contains the
* same code found in Mage_Catalog_Model_Product_Type_Abstract.getSku; however,
* it also includes logic to allow certain options to be disregarding from
* sku concatination.
*
* NOTE: Since we're providing the same logic here that is in the base abstract
* product type class, it is very important to check this logic during future
* magento upgrades to ensure nothing gets broken.
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getProductSku($product)
{
$excludeSkus = explode(',', Mage::getConfig()->getNode(self::XML_PATH_EXCLUDE_OPTIONS_SKU));
$skuDelimiter = '-';
$sku = $product->getData('sku');
if ($optionIds = $product->getCustomOption('option_ids')) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
// pass over options with a title contained in the config
if (in_array($option->getTitle(), $excludeSkus)) {
continue;
}
$quoteItemOption = $product->getCustomOption('option_' . $optionId);
$group = $option->groupFactory($option->getType())->setOption($option)->setListener(new Varien_Object());
if ($optionSku = $group->getOptionSku($quoteItemOption->getValue(), $skuDelimiter)) {
$sku .= $skuDelimiter . $optionSku;
}
if ($group->getListener()->getHasError()) {
$product->setHasError(true)->setMessage($group->getListener()->getMessage());
}
}
}
}
return $sku;
}
示例8: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$helper = Mage::helper('customoptions');
$basePrice = $finalPrice;
$finalPrice = 0;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$option->setProduct($product);
$optionQty = null;
$quoteItemOptionInfoBuyRequest = unserialize($product->getCustomOption('info_buyRequest')->getValue());
switch ($option->getType()) {
case 'checkbox':
case 'multiswatch':
if (isset($quoteItemOptionInfoBuyRequest['options'][$optionId])) {
$optionValues = array();
$optionQtyArr = array();
foreach ($option->getValues() as $key => $itemV) {
if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
$optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
} else {
$optionQty = 1;
}
$optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
}
$optionQty = $optionQtyArr;
break;
}
break;
case 'drop_down':
case 'radio':
case 'swatch':
if (isset($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty'])) {
$optionQty = intval($quoteItemOptionInfoBuyRequest['options_' . $optionId . '_qty']);
} else {
$optionQty = 1;
}
case 'multiple':
if (!isset($optionQty)) {
$optionQty = 1;
}
break;
case 'field':
case 'area':
case 'file':
case 'date':
case 'date_time':
case 'time':
break;
}
switch ($option->getType()) {
case 'field':
case 'area':
case 'file':
case 'date':
case 'date_time':
case 'time':
$price = $helper->getOptionPriceByQty($option, $qty, $product);
if ($price != 0) {
$price = $price / $qty;
}
$finalPrice += $price;
break;
default:
//multiple
$optionQty = 1;
case 'drop_down':
case 'radio':
case 'checkbox':
case 'swatch':
case 'multiswatch':
$quoteItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty, $optionQty, $product);
}
}
}
$product->setBaseCustomoptionsPrice($finalPrice);
// for additional info
if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
$finalPrice += $basePrice;
}
}
if (method_exists($this, '_applyOptionsPriceFME')) {
$finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
}
return $finalPrice;
}
开发者ID:vinayshuklasourcefuse,项目名称:sareez,代码行数:96,代码来源:MageWorx_CustomOptions_Model_Catalog_Product_Type_Price.php