本文整理汇总了PHP中Magento\Quote\Model\Quote\Item::getOptionByCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::getOptionByCode方法的具体用法?PHP Item::getOptionByCode怎么用?PHP Item::getOptionByCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote\Item
的用法示例。
在下文中一共展示了Item::getOptionByCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetOptionByCodeNotDeletedCode
public function testGetOptionByCodeNotDeletedCode()
{
$optionCode = 1234;
$optionMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item\\Option')->setMethods(['setItem', 'getCode', '__wakeup', 'isDeleted'])->disableOriginalConstructor()->getMock();
$optionMock->expects($this->once())->method('setItem')->with($this->model)->will($this->returnValue($optionMock));
$optionMock->expects($this->exactly(3))->method('getCode')->will($this->returnValue($optionCode));
$optionMock->expects($this->once())->method('isDeleted')->will($this->returnValue(false));
$this->model->addOption($optionMock);
$this->assertSame($optionMock, $this->model->getOptionByCode($optionCode));
}
示例2: getCustomOptions
/**
* Get Custom Options of item
*
* @param Item $item
* @return string
*/
public function getCustomOptions(Item $item)
{
$optionStr = '';
$this->_moveToCustomerStorage = true;
if ($optionIds = $item->getOptionByCode('option_ids')) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
$option = $item->getProduct()->getOptionById($optionId);
if ($option) {
$optionStr .= $option->getTitle() . ':';
$quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
$optionStr .= "\n";
}
}
}
return $optionStr;
}
示例3: _prepareOptionsForRequest
/**
* Prepare options array for info buy request
*
* @param \Magento\Quote\Model\Quote\Item $item
* @return array
*/
protected function _prepareOptionsForRequest($item)
{
$newInfoOptions = [];
$optionIds = $item->getOptionByCode('option_ids');
if ($optionIds) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
$option = $item->getProduct()->getOptionById($optionId);
$optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
$group = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Option')->groupFactory($option->getType())->setOption($option)->setQuoteItem($item);
$newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
}
}
return $newInfoOptions;
}
示例4: buildItemId
/**
* @param Item $item
* @return string
*/
protected function buildItemId(Item $item)
{
/** @var Item $parentItem */
$parentItem = $item->getOptionByCode('product_type');
if (!is_null($parentItem)) {
return $parentItem->getProduct()->getSku();
} elseif ($item->getProductType() === 'simple') {
// todo: if the product has a configurable parent and there is "super_attribute" data in the buy request, assume we need to use the parent product SKU, just like in Magento 1.
}
return $item->getProduct()->getSku();
}