Example #1
0
 /**
  * Returns prices for configurable product options
  *
  * @param int $attributeId
  * @param Attribute $attribute
  * @param array $options
  * @return array
  */
 public function getPriceOptions($attributeId, $attribute, array $options = [])
 {
     $prices = $attribute->getPrices();
     $optionPrices = [];
     if (!is_array($prices)) {
         return $optionPrices;
     }
     foreach ($prices as $value) {
         $optionValueAmount = $this->getOptionValueAmount($value);
         $oldPrice = $optionValueAmount->getValue();
         $optionValueModified = $this->getOptionValueModified($value);
         $basePrice = $optionValueModified->getBaseAmount();
         $finalPrice = $optionValueModified->getValue();
         $optionPrices[] = ['id' => $value['value_index'], 'label' => $value['label'], 'prices' => ['oldPrice' => ['amount' => $this->convertDot($oldPrice)], 'basePrice' => ['amount' => $this->convertDot($basePrice)], 'finalPrice' => ['amount' => $this->convertDot($finalPrice)]], 'products' => $this->getProductsIndex($attributeId, $options, $value)];
     }
     return $optionPrices;
 }
 /**
  * {@inheritdoc}
  */
 public function delete(\Magento\ConfigurableProduct\Api\Data\OptionInterface $option)
 {
     try {
         $this->optionResource->delete($option);
     } catch (\Exception $exception) {
         throw new StateException(__('Cannot delete option with id: %1', $option->getId()));
     }
     return true;
 }
 public function testSavePrices()
 {
     $rowSet = [0 => ['value_id' => '1', 'product_super_attribute_id' => '1', 'value_index' => '12', 'is_percent' => '0', 'pricing_value' => '3.0000', 'website_id' => '0'], 1 => ['value_id' => '2', 'product_super_attribute_id' => '1', 'value_index' => '13', 'is_percent' => '0', 'pricing_value' => '8.0000', 'website_id' => '0']];
     $values = [12 => ['value_index' => '12', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1'], 13 => ['value_index' => '13', 'pricing_value' => '5', 'is_percent' => '0', 'include' => '1'], 14 => ['value_index' => '14', 'pricing_value' => '3', 'is_percent' => '0', 'include' => '1']];
     $attribute = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->setMethods(['getValues', 'getId'])->disableOriginalConstructor()->getMock();
     $adapterMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->resource->expects($this->once())->method('getConnection')->with('core_write')->willReturn($adapterMock);
     $this->catalogData->expects($this->any())->method('isPriceGlobal')->willReturn(1);
     $attribute->expects($this->once())->method('getValues')->willReturn($values);
     $adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
     $selectMock->expects($this->once())->method('from')->with(null)->will($this->returnSelf());
     $selectMock->expects($this->at(1))->method('where')->with('product_super_attribute_id = :product_super_attribute_id')->will($this->returnSelf());
     $selectMock->expects($this->at(2))->method('where')->with('website_id = :website_id')->will($this->returnSelf());
     $attribute->expects($this->any())->method('getId')->willReturn(1);
     $adapterMock->expects($this->once())->method('fetchAll')->with($selectMock, ['product_super_attribute_id' => 1, 'website_id' => 0])->willReturn($rowSet);
     $this->assertEquals($this->model, $this->model->savePrices($attribute));
 }
Example #4
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage Requested option doesn't exist: 3
  */
 public function testGetNoSuchEntityException()
 {
     $productSku = 'oneSku';
     $optionId = 3;
     $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku))->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(ConfigurableType::TYPE_CODE));
     $this->productType->expects($this->once())->method('getConfigurableAttributeCollection')->with($this->equalTo($this->product))->will($this->returnValue($this->configurableAttributeCollection));
     $this->configurableAttributeCollection->expects($this->once())->method('addFieldToFilter')->with(self::ATTRIBUTE_ID_FIELD_NAME, $optionId)->will($this->returnSelf());
     $this->configurableAttributeCollection->expects($this->once())->method('getFirstItem')->will($this->returnValue($this->option));
     $this->option->expects($this->once())->method('getId')->will($this->returnValue(null));
     $this->attributeResource->expects($this->once())->method('getIdFieldName')->will($this->returnValue(self::ATTRIBUTE_ID_FIELD_NAME));
     $this->configurableAttributeCollection->expects($this->once())->method('getResource')->will($this->returnValue($this->attributeResource));
     $this->model->get($productSku, $optionId);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function delete(OptionInterface $option)
 {
     $product = $this->getProductById($option->getProductId());
     try {
         $this->configurableTypeResource->saveProducts($product, []);
     } catch (\Exception $exception) {
         throw new StateException(__('Cannot delete variations from product: %1', $option->getProductId()));
     }
     try {
         $this->optionResource->delete($option);
     } catch (\Exception $exception) {
         throw new StateException(__('Cannot delete option with id: %1', $option->getId()));
     }
     return true;
 }