/** * {@inheritdoc} */ public function addAttribute($name, $value, $presentation = null) { $attribute = $this->attributeRepository->findOneBy(array('name' => $name)); if (null === $attribute) { $attribute = $this->attributeRepository->createNew(); $attribute->setName($name); $attribute->setPresentation($presentation ?: $name); $this->productManager->persist($attribute); $this->productManager->flush($attribute); } $attributeValue = $this->attributeValueRepository->createNew(); $attributeValue->setAttribute($attribute); $attributeValue->setValue($value); $this->product->addAttribute($attributeValue); return $this; }
function it_assigns_prototype_attributes_and_options_to_product($attributeValueRepository, PrototypeInterface $prototype, ProductInterface $product, AttributeInterface $attribute, AttributeValueInterface $attributeValue, OptionInterface $option) { $prototype->getAttributes()->willReturn(array($attribute))->shouldBeCalled(); $prototype->getOptions()->willReturn(array($option))->shouldBeCalled(); $attributeValueRepository->createNew()->shouldBeCalled()->willReturn($attributeValue); $attributeValue->setAttribute($attribute)->shouldBeCalled(); $product->addAttribute($attributeValue)->shouldBeCalled(); $product->addOption($option)->shouldBeCalled(); $this->build($prototype, $product); }
/** * {@inheritdoc} */ public function build(PrototypeInterface $prototype, ProductInterface $product) { foreach ($prototype->getAttributes() as $attribute) { $attributeValue = $this->attributeValueRepository->createNew(); $attributeValue->setAttribute($attribute); $product->addAttribute($attributeValue); } foreach ($prototype->getOptions() as $option) { $product->addOption($option); } }