Esempio n. 1
0
 /**
  * Prepare item info
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_shouldRenderInfo = true;
     $key = 'order_item_info';
     foreach (array('name' => __('Product Name'), 'sku' => __('SKU'), 'qty' => __('Quantity')) as $itemKey => $label) {
         $value = $this->_recurringPayment->getInfoValue($key, $itemKey);
         if ($value) {
             $this->_addInfo(array('label' => $label, 'value' => $value));
         }
     }
     $request = $this->_recurringPayment->getInfoValue($key, 'info_buyRequest');
     if (empty($request)) {
         return;
     }
     $request = unserialize($request);
     if (empty($request['options'])) {
         return;
     }
     $options = $this->_option->getCollection()->addIdsToFilter(array_keys($request['options']))->addTitleToResult($this->_recurringPayment->getInfoValue($key, 'store_id'))->addValuesToResult();
     foreach ($options as $option) {
         $quoteItemOption = $this->_quoteItemOptionFactory->create()->setId($option->getId());
         $group = $option->groupFactory($option->getType())->setOption($option)->setRequest(new \Magento\Framework\Object($request))->setProduct($this->_product)->setUseQuotePath(true)->setQuoteItemOption($quoteItemOption)->validateUserValue($request['options']);
         $skipHtmlEscaping = false;
         if ('file' == $option->getType()) {
             $skipHtmlEscaping = true;
             $downloadParams = array('id' => $this->_recurringPayment->getId(), 'option_id' => $option->getId(), 'key' => $request['options'][$option->getId()]['secret_key']);
             $group->setCustomOptionDownloadUrl('sales/download/downloadProfileCustomOption')->setCustomOptionUrlParams($downloadParams);
         }
         $optionValue = $group->prepareForCart();
         $this->_addInfo(array('label' => $option->getTitle(), 'value' => $group->getFormattedOptionValue($optionValue), 'skip_html_escaping' => $skipHtmlEscaping));
     }
 }
Esempio n. 2
0
 public function testAddOptionArray()
 {
     $optionCode = 1234;
     $optionData = ['product' => 'test', 'code' => $optionCode];
     $optionMock = $this->getMockBuilder('Magento\\Sales\\Model\\Quote\\Item\\Option')->setMethods(['setData', 'setItem', 'getCode', '__wakeup', 'isDeleted'])->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('setData')->with($optionData)->will($this->returnValue($optionMock));
     $optionMock->expects($this->once())->method('setItem')->with($this->model)->will($this->returnValue($optionMock));
     $optionMock->expects($this->exactly(3))->method('getCode')->will($this->returnValue($optionCode));
     $this->itemOptionFactory->expects($this->at(0))->method('create')->will($this->returnValue($optionMock));
     $this->model->addOption($optionData);
     $this->assertEquals([$optionMock], $this->model->getOptions());
     $this->assertEquals([$optionCode => $optionMock], $this->model->getOptionsByCode());
     $this->assertEquals($optionMock, $this->model->getOptionByCode($optionCode));
 }
Esempio n. 3
0
 /**
  * Parse user input value and return cart prepared value
  *
  * @param string $optionValue
  * @param array $productOptionValues Values for product option
  * @return string|null
  */
 public function parseOptionValue($optionValue, $productOptionValues)
 {
     // search quote item option Id in option value
     if (preg_match('/\\[([0-9]+)\\]/', $optionValue, $matches)) {
         $confItemOptionId = $matches[1];
         $option = $this->_itemOptionFactory->create()->load($confItemOptionId);
         try {
             unserialize($option->getValue());
             return $option->getValue();
         } catch (\Exception $e) {
             return null;
         }
     } else {
         return null;
     }
 }
Esempio n. 4
0
 /**
  * Add option to item
  *
  * @param \Magento\Sales\Model\Quote\Item\Option|\Magento\Framework\Object $option
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function addOption($option)
 {
     if (is_array($option)) {
         $option = $this->_itemOptionFactory->create()->setData($option)->setItem($this);
     } elseif ($option instanceof \Magento\Framework\Object && !$option instanceof \Magento\Sales\Model\Quote\Item\Option) {
         $option = $this->_itemOptionFactory->create()->setData($option->getData())->setProduct($option->getProduct())->setItem($this);
     } elseif ($option instanceof \Magento\Sales\Model\Quote\Item\Option) {
         $option->setItem($this);
     } else {
         throw new \Magento\Framework\Model\Exception(__('We found an invalid item option format.'));
     }
     $exOption = $this->getOptionByCode($option->getCode());
     if ($exOption) {
         $exOption->addData($option->getData());
     } else {
         $this->_addOptionCode($option);
         $this->_options[] = $option;
     }
     return $this;
 }