Example #1
0
 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));
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * @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();
 }