예제 #1
0
 public function testPrepareAttributeSet()
 {
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getNewVariationsAttributeSetId'])->disableOriginalConstructor()->getMock();
     $attributeMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['isInSet', 'setAttributeSetId', 'setAttributeGroupId', 'save'])->disableOriginalConstructor()->getMock();
     $attributeSetMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->setMethods(['load', 'addSetInfo', 'getDefaultGroupId'])->disableOriginalConstructor()->getMock();
     $eavEntityMock = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity')->setMethods(['setType', 'getTypeId'])->disableOriginalConstructor()->getMock();
     $productMock->expects($this->once())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->configurableProduct->expects($this->once())->method('getUsedProductAttributes')->with($productMock)->willReturn([$attributeMock]);
     $this->attributeSetFactory->expects($this->once())->method('create')->willReturn($attributeSetMock);
     $attributeSetMock->expects($this->once())->method('load')->with('new_attr_set_id')->willReturnSelf();
     $this->entityFactoryMock->expects($this->once())->method('create')->willReturn($eavEntityMock);
     $eavEntityMock->expects($this->once())->method('setType')->with('catalog_product')->willReturnSelf();
     $eavEntityMock->expects($this->once())->method('getTypeId')->willReturn('type_id');
     $attributeSetMock->expects($this->once())->method('addSetInfo')->with('type_id', [$attributeMock]);
     $attributeMock->expects($this->once())->method('isInSet')->with('new_attr_set_id')->willReturn(false);
     $attributeMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $attributeSetMock->expects($this->once())->method('getDefaultGroupId')->with('new_attr_set_id')->willReturn('default_group_id');
     $attributeMock->expects($this->once())->method('setAttributeGroupId')->with('default_group_id')->willReturnSelf();
     $attributeMock->expects($this->once())->method('save')->willReturnSelf();
     $this->model->prepareAttributeSet($productMock);
 }
예제 #2
0
 /**
  * Relate simple products to configurable
  *
  * @param ProductInterface $product
  * @param ProductExtensionInterface $extensionAttributes
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 private function setLinkedProducts(ProductInterface $product, ProductExtensionInterface $extensionAttributes)
 {
     $associatedProductIds = $product->hasData('associated_product_ids') ? $product->getData('associated_product_ids') : [];
     $variationsMatrix = $this->getVariationMatrixFromProduct($product);
     if ($associatedProductIds || $variationsMatrix) {
         $this->variationHandler->prepareAttributeSet($product);
     }
     if (!empty($variationsMatrix)) {
         $generatedProductIds = $this->variationHandler->generateSimpleProducts($product, $variationsMatrix);
         $associatedProductIds = array_merge($associatedProductIds, $generatedProductIds);
     }
     $extensionAttributes->setConfigurableProductLinks(array_filter($associatedProductIds));
 }