Пример #1
0
 /**
  * @param array $expected
  * @param array $data
  * @dataProvider getOptionsDataProvider
  */
 public function testGetOptions(array $expected, array $data)
 {
     $this->_imageHelperMock->expects($this->at(0))->method('init')->will($this->returnValue('http://example.com/base_img_url'));
     for ($i = 1; $i <= count($data['allowed_products']); $i++) {
         $this->_imageHelperMock->expects($this->at($i))->method('init')->will($this->returnValue('http://example.com/base_img_url_' . $i));
     }
     $this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
 }
Пример #2
0
 /**
  * @param array $expected
  * @param array $data
  * @dataProvider getOptionsDataProvider
  */
 public function testGetOptions(array $expected, array $data)
 {
     if (count($data['allowed_products'])) {
         $imageHelper1 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
         $imageHelper1->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url');
         $imageHelper2 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
         $imageHelper2->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url_2');
         $this->_imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$data['current_product_mock'], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][0], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][1], 'product_page_image_large', [], $imageHelper2]]);
     }
     $this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
 }
Пример #3
0
 /**
  * Composes configuration for js
  *
  * @return string
  */
 public function getJsonConfig()
 {
     $store = $this->getCurrentStore();
     $currentProduct = $this->getProduct();
     $regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price');
     $finalPrice = $currentProduct->getPriceInfo()->getPrice('final_price');
     $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());
     $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);
     $config = ['attributes' => $attributesData['attributes'], 'template' => str_replace('%s', '<%- data.price %>', $store->getCurrentCurrency()->getOutputFormat()), 'optionPrices' => $this->getOptionPrices(), 'prices' => ['oldPrice' => ['amount' => $this->_registerJsPrice($this->_convertPrice($regularPrice->getAmount()->getValue()))], 'basePrice' => ['amount' => $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getBaseAmount()))], 'finalPrice' => ['amount' => $this->_registerJsPrice($this->_convertPrice($finalPrice->getAmount()->getValue()))]], 'productId' => $currentProduct->getId(), 'chooseText' => __('Choose an Option...'), 'images' => isset($options['images']) ? $options['images'] : [], 'index' => isset($options['index']) ? $options['index'] : []];
     if ($currentProduct->hasPreconfiguredValues() && !empty($attributesData['defaultValues'])) {
         $config['defaultValues'] = $attributesData['defaultValues'];
     }
     $config = array_merge($config, $this->_getAdditionalConfig());
     return $this->jsonEncoder->encode($config);
 }
Пример #4
0
 /**
  * Composes configuration for js
  *
  * @return string
  */
 public function getJsonConfig()
 {
     $store = $this->getCurrentStore();
     $currentProduct = $this->getProduct();
     /**
      * @var \Magento\ConfigurableProduct\Pricing\Price\AttributePrice $attributePrice
      */
     $attributePrice = $currentProduct->getPriceInfo()->getPrice('attribute_price');
     $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());
     $attributes = $attributePrice->prepareAttributes($options);
     $config = array('attributes' => $attributes['priceOptions'], 'template' => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()), 'basePrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getFinalPrice())), 'oldPrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getPrice())), 'productId' => $currentProduct->getId(), 'chooseText' => __('Choose an Option...'), 'taxConfig' => $attributePrice->getTaxConfig($this->currentCustomer->getCustomerId()), 'images' => $options['images'], 'baseImage' => $options['baseImage']);
     if ($currentProduct->hasPreconfiguredValues() && !empty($attributes['defaultValues'])) {
         $config['defaultValues'] = $attributes['defaultValues'];
     }
     $config = array_merge($config, $this->_getAdditionalConfig());
     return $this->jsonEncoder->encode($config);
 }
Пример #5
0
 private function prepareGetJsonSwatchConfig()
 {
     $product1 = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product1->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
     $product1->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(1);
     $product2 = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product2->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
     $product2->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(3);
     $simpleProducts = [$product1, $product2];
     $configurableType = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $configurableType->expects($this->atLeastOnce())->method('getUsedProducts')->with($this->product, null)->willReturn($simpleProducts);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);
     $productAttribute1 = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $productAttribute1->expects($this->any())->method('getId')->willReturn(1);
     $productAttribute1->expects($this->any())->method('getAttributeCode')->willReturn('code');
     $attribute1 = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute', ['getProductAttribute'], [], '', false);
     $attribute1->expects($this->any())->method('getProductAttribute')->willReturn($productAttribute1);
     $this->helper->expects($this->any())->method('getAllowAttributes')->with($this->product)->willReturn([$attribute1]);
 }