/**
  * Update attribute data
  *
  * @param OptionInterface $attribute
  * @param array $item
  * @return void
  */
 private function updateAttributeData(OptionInterface $attribute, array $item)
 {
     $values = [];
     foreach ($item['values'] as $value) {
         $option = $this->optionValueFactory->create();
         $option->setValueIndex($value['value_index']);
         $values[] = $option;
     }
     $attribute->setData(array_replace_recursive((array) $attribute->getData(), $item));
     $attribute->setValues($values);
 }
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Products "5" and "4" have the same set of attribute values.
  */
 public function testAroundSaveWithLinksWithDuplicateAttributes()
 {
     $links = [4, 5];
     $attributeCode = 'color';
     $attributeId = 23;
     $this->option->expects(static::once())->method('getAttributeId')->willReturn($attributeId);
     $this->product->expects(static::once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE);
     $this->result->expects(static::once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn([$this->option]);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($links);
     $this->productAttributeRepository->expects(static::once())->method('get')->willReturn($this->eavAttribute);
     $this->eavAttribute->expects(static::once())->method('getAttributeCode')->willReturn($attributeCode);
     $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['load', 'getData', '__wakeup'])->getMock();
     $this->productFactory->expects(static::exactly(2))->method('create')->willReturn($product);
     $product->expects(static::exactly(2))->method('load')->willReturnSelf();
     $product->expects(static::exactly(4))->method('getData')->with($attributeCode)->willReturn($attributeId);
     $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product);
 }
 /**
  * Get product entity id by product attribute
  *
  * @param OptionInterface $option
  * @return int
  */
 public function getEntityIdByAttribute(OptionInterface $option)
 {
     $select = $this->getConnection()->select()->from(['e' => $this->getTable('catalog_product_entity')], ['e.entity_id'])->where('e.' . $this->getProductEntityLinkField() . '=?', $option->getProductId())->limit(1);
     return (int) $this->getConnection()->fetchOne($select);
 }
Exemplo n.º 4
0
 /**
  * Ensure that all necessary data is available for a new option creation.
  *
  * @param OptionInterface $option
  * @return void
  * @throws InputException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function validateNewOptionData(OptionInterface $option)
 {
     $inputException = new InputException();
     if (!$option->getAttributeId()) {
         $inputException->addError(__('Option attribute ID is not specified.'));
     }
     if (!$option->getLabel()) {
         $inputException->addError(__('Option label is not specified.'));
     }
     if (!$option->getValues()) {
         $inputException->addError(__('Option values are not specified.'));
     } else {
         foreach ($option->getValues() as $optionValue) {
             if (!$optionValue->getValueIndex()) {
                 $inputException->addError(__('Value index is not specified for an option.'));
             }
             if (null === $optionValue->getPricingValue()) {
                 $inputException->addError(__('Price is not specified for an option.'));
             }
             if (null === $optionValue->getIsPercent()) {
                 $inputException->addError(__('Percent/absolute is not specified for an option.'));
             }
         }
     }
     if ($inputException->wasErrorAdded()) {
         throw $inputException;
     }
 }