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


PHP Product::getOptionById方法代码示例

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


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

示例1: testOptionApi

 /**
  * @covers \Magento\Catalog\Model\Product::setOptions
  * @covers \Magento\Catalog\Model\Product::getOptionById
  * @covers \Magento\Catalog\Model\Product::getOptions
  */
 public function testOptionApi()
 {
     $this->assertNull($this->_model->getOptions());
     $optionId = uniqid();
     $option = $this->objectManager->create('Magento\\Catalog\\Model\\Product\\Option', ['data' => ['key' => 'value']]);
     $option->setId($optionId);
     $this->_model->setOptions([$option]);
     $this->assertSame($option, $this->_model->getOptionById($optionId));
     $this->assertEquals([$option], $this->_model->getOptions());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:15,代码来源:ProductExternalTest.php

示例2: testOptionApi

 /**
  * @covers \Magento\Catalog\Model\Product::addOption
  * @covers \Magento\Catalog\Model\Product::getOptionById
  * @covers \Magento\Catalog\Model\Product::getOptions
  */
 public function testOptionApi()
 {
     $this->assertEquals([], $this->_model->getOptions());
     $optionId = uniqid();
     $option = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product\\Option', ['data' => ['key' => 'value']]);
     $option->setId($optionId);
     $this->_model->addOption($option);
     $this->assertSame($option, $this->_model->getOptionById($optionId));
     $this->assertEquals([$optionId => $option], $this->_model->getOptions());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:ProductExternalTest.php

示例3: _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

示例4: 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

示例5: getOptionById

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


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