Ejemplo n.º 1
0
 /**
  * Retrieve product configured options
  *
  * @return array
  */
 public function getConfiguredOptions()
 {
     $item = $this->getItem();
     $data = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());
     $helper = $this->_helperPool->get($data['helper']);
     return $helper->getOptions($item);
 }
Ejemplo n.º 2
0
 /**
  * Returns helper for product type
  *
  * @param Product $product
  * @return \Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface
  */
 protected function _getProductHelper($product)
 {
     // Retrieve whole array of renderers
     $productHelpers = $this->getProductHelpers();
     if (!is_array($productHelpers)) {
         $column = $this->getColumn();
         if ($column) {
             $grid = $column->getGrid();
             if ($grid) {
                 $productHelpers = $grid->getProductConfigurationHelpers();
                 $this->setProductHelpers($productHelpers ? $productHelpers : []);
             }
         }
     }
     // Check whether we have helper for our product
     $productType = $product->getTypeId();
     if (isset($productHelpers[$productType])) {
         $helperName = $productHelpers[$productType];
     } elseif (isset($productHelpers['default'])) {
         $helperName = $productHelpers['default'];
     } else {
         $helperName = 'Magento\\Catalog\\Helper\\Product\\Configuration';
     }
     return $this->_productConfigPool->get($helperName);
 }
Ejemplo n.º 3
0
 public function testGetItemData()
 {
     $urlModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Url::class)->disableOriginalConstructor()->getMock();
     $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['getUrlModel', 'isVisibleInSiteVisibility', 'getSku'])->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getUrlModel')->willReturn($urlModel);
     $product->expects($this->any())->method('isVisibleInSiteVisibility')->willReturn(true);
     $product->expects($this->any())->method('getSku')->willReturn('simple');
     /** @var \Magento\Quote\Model\Quote\Item $item */
     $item = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)->setMethods(['getProductType', 'getProduct', 'getCalculationPrice'])->disableOriginalConstructor()->getMock();
     $item->expects($this->any())->method('getProduct')->willReturn($product);
     $item->expects($this->any())->method('getProductType')->willReturn('simple');
     $item->expects($this->any())->method('getCalculationPrice')->willReturn(5);
     $this->imageHelper->expects($this->any())->method('init')->with($product)->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('getUrl')->willReturn('url');
     $this->imageHelper->expects($this->any())->method('getLabel')->willReturn('label');
     $this->imageHelper->expects($this->any())->method('getWidth')->willReturn(100);
     $this->imageHelper->expects($this->any())->method('getHeight')->willReturn(100);
     $this->configurationPool->expects($this->any())->method('getByProductType')->willReturn($product);
     $itemData = $this->model->getItemData($item);
     $this->assertArrayHasKey('options', $itemData);
     $this->assertArrayHasKey('qty', $itemData);
     $this->assertArrayHasKey('item_id', $itemData);
     $this->assertArrayHasKey('configure_url', $itemData);
     $this->assertArrayHasKey('is_visible_in_site_visibility', $itemData);
     $this->assertArrayHasKey('product_type', $itemData);
     $this->assertArrayHasKey('product_name', $itemData);
     $this->assertArrayHasKey('product_sku', $itemData);
     $this->assertArrayHasKey('product_url', $itemData);
     $this->assertArrayHasKey('product_has_url', $itemData);
     $this->assertArrayHasKey('product_price', $itemData);
     $this->assertArrayHasKey('product_price_value', $itemData);
     $this->assertArrayHasKey('product_image', $itemData);
     $this->assertArrayHasKey('canApplyMsrp', $itemData);
 }
Ejemplo n.º 4
0
 /**
  * Retrieve formatted item options view
  *
  * @param \Magento\Quote\Api\Data\CartItemInterface $item
  * @return string
  */
 private function getFormattedOptionValue($item)
 {
     $optionsData = [];
     /* @var $helper \Magento\Catalog\Helper\Product\Configuration */
     $helper = $this->configurationPool->getByProductType('default');
     $options = $this->configurationPool->getByProductType($item->getProductType())->getOptions($item);
     foreach ($options as $index => $optionValue) {
         $params = ['max_length' => 55, 'cut_replacer' => ' <a href="#" class="dots tooltip toggle" onclick="return false">...</a>'];
         $option = $helper->getFormattedOptionValue($optionValue, $params);
         $optionsData[$index] = $option;
         $optionsData[$index]['label'] = $optionValue['label'];
     }
     return \Zend_Json::encode($optionsData);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     $shippingAddress = $quote->getShippingAddress();
     if ($quote->isVirtual()) {
         $totalsData = array_merge($quote->getBillingAddress()->getData(), $quote->getData());
     } else {
         $totalsData = array_merge($shippingAddress->getData(), $quote->getData());
     }
     $totals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     $weeeTaxAppliedAmount = 0;
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->itemConverter->modelToDataObject($item);
         $weeeTaxAppliedAmount += $item->getWeeeTaxAppliedAmount();
     }
     $totals->setCouponCode($this->couponService->get($cartId));
     $calculatedTotals = $this->totalsConverter->process($quote->getTotals());
     $amount = $totals->getGrandTotal() - $totals->getTaxAmount();
     $amount = $amount > 0 ? $amount : 0;
     $totals->setGrandTotal($amount);
     $totals->setTotalSegments($calculatedTotals);
     $totals->setItems($items);
     $totals->setWeeeTaxAppliedAmount($weeeTaxAppliedAmount);
     return $totals;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /**
      * Quote.
      *
      * @var \Magento\Quote\Model\Quote $quote
      */
     $quote = $this->quoteRepository->getActive($cartId);
     $shippingAddress = $quote->getShippingAddress();
     if ($quote->isVirtual()) {
         $totalsData = array_merge($quote->getBillingAddress()->getData(), $quote->getData());
     } else {
         $totalsData = array_merge($shippingAddress->getData(), $quote->getData());
     }
     $totals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($totals, $totalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->converter->modelToDataObject($item);
     }
     $totals->setItems($items);
     return $totals;
 }
Ejemplo n.º 7
0
 /**
  * Returns html for showing item options
  *
  * @param \Magento\Wishlist\Model\Item $item
  * @return string
  *
  * @deprecated after 1.6.2.0
  */
 public function getDetailsHtml(\Magento\Wishlist\Model\Item $item)
 {
     $cfg = $this->getOptionsRenderCfg($item->getProduct()->getTypeId());
     if (!$cfg) {
         return '';
     }
     $block = $this->getChildBlock('item_options');
     if (!$block) {
         return '';
     }
     if ($cfg['template']) {
         $template = $cfg['template'];
     } else {
         $cfgDefault = $this->getOptionsRenderCfg('default');
         if (!$cfgDefault) {
             return '';
         }
         $template = $cfgDefault['template'];
     }
     $block->setTemplate($template);
     $block->setOptionList($this->_helperPool->get($cfg['helper'])->getOptions($item));
     return $block->toHtml();
 }
Ejemplo n.º 8
0
 /**
  * Get list of all options for product
  *
  * @return array
  * @codeCoverageIgnore
  */
 protected function getOptionList()
 {
     return $this->configurationPool->getByProductType($this->item->getProductType())->getOptions($this->item);
 }
 /**
  * @dataProvider getByProductTypeDataProvider
  * @param string $productType
  * @param string $expectedResult
  */
 public function testGetByProductType($productType, $expectedResult)
 {
     $this->assertEquals($expectedResult, $this->model->getByProductType($productType));
 }