本文整理匯總了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();
}