当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getCustomOption方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getCustomOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getCustomOption方法的具体用法?PHP Product::getCustomOption怎么用?PHP Product::getCustomOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getCustomOption方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFinalPrice

 /**
  * Get product final price
  *
  * @param   float $qty
  * @param   \Magento\Catalog\Model\Product $product
  * @return  float
  */
 public function getFinalPrice($qty, $product)
 {
     if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
         return $product->getCalculatedFinalPrice();
     }
     if ($product->getCustomOption('simple_product')) {
         $product->setSelectedConfigurableOption($product->getCustomOption('simple_product')->getProduct());
     }
     //TODO: MAGETWO-23739 catalogrule price must get from simple product.
     $finalPrice = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $finalPrice = max(0, $finalPrice);
     $product->setFinalPrice($finalPrice);
     return $finalPrice;
 }
开发者ID:nja78,项目名称:magento2,代码行数:22,代码来源:Price.php

示例2: getFinalPrice

 /**
  * Get product final price
  *
  * @param   float $qty
  * @param   \Magento\Catalog\Model\Product $product
  * @return  float
  */
 public function getFinalPrice($qty, $product)
 {
     if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
         return $product->getCalculatedFinalPrice();
     }
     if ($product->getCustomOption('simple_product') && $product->getCustomOption('simple_product')->getProduct()) {
         $finalPrice = parent::getFinalPrice($qty, $product->getCustomOption('simple_product')->getProduct());
     } else {
         $priceInfo = $product->getPriceInfo();
         $finalPrice = $priceInfo->getPrice('final_price')->getAmount()->getValue();
     }
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $finalPrice = max(0, $finalPrice);
     $product->setFinalPrice($finalPrice);
     return $finalPrice;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:23,代码来源:Price.php

示例3: getSelectionQty

 /**
  * Get selection quantity
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $selectionId
  * @return float
  */
 public function getSelectionQty(\Magento\Catalog\Model\Product $product, $selectionId)
 {
     $selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
     if ($selectionQty) {
         return $selectionQty->getValue();
     }
     return 0;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Configuration.php

示例4: getSelectionQty

 /**
  * Get selection quantity
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $selectionId
  *
  * @return float
  */
 public function getSelectionQty($product, $selectionId)
 {
     $selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
     if ($selectionQty) {
         return $selectionQty->getValue();
     }
     return 0;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:16,代码来源:Configuration.php

示例5: testCustomOptionsApi

 /**
  * @covers \Magento\Catalog\Model\Product::addCustomOption
  * @covers \Magento\Catalog\Model\Product::setCustomOptions
  * @covers \Magento\Catalog\Model\Product::getCustomOptions
  * @covers \Magento\Catalog\Model\Product::getCustomOption
  * @covers \Magento\Catalog\Model\Product::hasCustomOptions
  */
 public function testCustomOptionsApi()
 {
     $this->assertEquals([], $this->_model->getCustomOptions());
     $this->assertFalse($this->_model->hasCustomOptions());
     $this->_model->setId(99);
     $this->_model->addCustomOption('one', 'value1');
     $option = $this->_model->getCustomOption('one');
     $this->assertInstanceOf('Magento\\Framework\\DataObject', $option);
     $this->assertEquals($this->_model->getId(), $option->getProductId());
     $this->assertSame($option->getProduct(), $this->_model);
     $this->assertEquals('one', $option->getCode());
     $this->assertEquals('value1', $option->getValue());
     $this->assertEquals(['one' => $option], $this->_model->getCustomOptions());
     $this->assertTrue($this->_model->hasCustomOptions());
     $this->_model->setCustomOptions(['test']);
     $this->assertTrue(is_array($this->_model->getCustomOptions()));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:24,代码来源:ProductExternalTest.php

示例6: getSku

 /**
  * Get sku of product
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @return string
  */
 public function getSku($product)
 {
     $simpleOption = $product->getCustomOption('simple_product');
     if ($simpleOption) {
         $optionProduct = $simpleOption->getProduct();
         $simpleSku = null;
         if ($optionProduct) {
             $simpleSku = $simpleOption->getProduct()->getSku();
         }
         $sku = parent::getOptionSku($product, $simpleSku);
     } else {
         $sku = parent::getSku($product);
     }
     return $sku;
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:21,代码来源:Configurable.php

示例7: _applyOptionsPrice

 /**
  * Apply options price
  *
  * @param Product $product
  * @param int $qty
  * @param float $finalPrice
  * @return float
  * @deprecated (MAGETWO-31469)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     $optionIds = $product->getCustomOption('option_ids');
     if ($optionIds) {
         $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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:Price.php

示例8: getBeforeQty

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\DataObject $selection
  * @return float|int
  */
 protected function getBeforeQty($product, $selection)
 {
     $beforeQty = 0;
     $customOption = $product->getCustomOption('product_qty_' . $selection->getId());
     if ($customOption && $customOption->getProduct()->getId() == $selection->getId()) {
         $beforeQty = (double) $customOption->getValue();
         return $beforeQty;
     }
     return $beforeQty;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:15,代码来源:Type.php

示例9: getTotalBundleItemsPrice

 /**
  * Get Total price  for Bundle items
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param null|float $qty
  * @return float
  */
 public function getTotalBundleItemsPrice($product, $qty = null)
 {
     $price = 0.0;
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_selection_ids');
         if ($customOption) {
             $selectionIds = unserialize($customOption->getValue());
             $selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds, $product);
             $selections->addTierPriceData();
             $this->_eventManager->dispatch('prepare_catalog_product_collection_prices', ['collection' => $selections, 'store_id' => $product->getStoreId()]);
             foreach ($selections->getItems() as $selection) {
                 if ($selection->isSalable()) {
                     $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
                     if ($selectionQty) {
                         $price += $this->getSelectionFinalTotalPrice($product, $selection, $qty, $selectionQty->getValue());
                     }
                 }
             }
         }
     }
     return $price;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:29,代码来源:Price.php

示例10: getBundleSelectionIds

 /**
  * Retrieve array of bundle selection IDs
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
 {
     $customOption = $product->getCustomOption('bundle_selection_ids');
     if ($customOption) {
         $selectionIds = unserialize($customOption->getValue());
         if (!empty($selectionIds) && is_array($selectionIds)) {
             return $selectionIds;
         }
     }
     return [];
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:Price.php

示例11: getOptionSku

 /**
  * Default action to get sku of product with option
  *
  * @param \Magento\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');
     }
     $optionIds = $product->getCustomOption('option_ids');
     if ($optionIds) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $product->getOptionById($optionId);
             if ($option) {
                 $confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $optionId);
                 $group = $option->groupFactory($option->getType())->setOption($option)->setListener(new \Magento\Framework\DataObject());
                 $optionSku = $group->getOptionSku($confItemOption->getValue(), $skuDelimiter);
                 if ($optionSku) {
                     $sku .= $skuDelimiter . $optionSku;
                 }
                 if ($group->getListener()->getHasError()) {
                     $product->setHasError(true)->setMessage($group->getListener()->getMessage());
                 }
             }
         }
     }
     return $sku;
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:32,代码来源:AbstractType.php

示例12: isVirtual

 /**
  * Check is virtual product
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return bool
  */
 public function isVirtual($product)
 {
     if ($product->hasCustomOptions()) {
         $customOption = $product->getCustomOption('bundle_selection_ids');
         $selectionIds = unserialize($customOption->getValue());
         $selections = $this->getSelectionsByIds($selectionIds, $product);
         $virtualCount = 0;
         foreach ($selections->getItems() as $selection) {
             if ($selection->isVirtual()) {
                 $virtualCount++;
             }
         }
         if ($virtualCount == count($selections)) {
             return true;
         }
     }
     return false;
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:24,代码来源:Type.php

示例13: getCustomOption

 /**
  * {@inheritdoc}
  */
 public function getCustomOption($code)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCustomOption');
     if (!$pluginInfo) {
         return parent::getCustomOption($code);
     } else {
         return $this->___callPlugins('getCustomOption', func_get_args(), $pluginInfo);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Interceptor.php

示例14: importProduct

 /**
  * Import product recurring payment information
  * Returns false if it cannot be imported
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this|false
  */
 public function importProduct(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getIsRecurring() && is_array($product->getRecurringPayment())) {
         // import recurring payment data
         $this->addData($product->getRecurringPayment());
         // automatically set product name if there is no schedule description
         if (!$this->hasScheduleDescription()) {
             $this->setScheduleDescription($product->getName());
         }
         // collect start datetime from the product options
         $options = $product->getCustomOption(self::PRODUCT_OPTIONS_KEY);
         if ($options) {
             $options = unserialize($options->getValue());
             if (is_array($options)) {
                 if (isset($options['start_datetime'])) {
                     $startDatetime = new \Magento\Framework\Stdlib\DateTime\Date($options['start_datetime'], \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
                     $this->setNearestStartDatetime($startDatetime);
                 }
             }
         }
         return $this->_filterValues();
     }
     return false;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:31,代码来源:RecurringPayment.php


注:本文中的Magento\Catalog\Model\Product::getCustomOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。