本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}