function it_massively_insert_and_update_objects($bulkSaver, $bulkDetacher, $stepExecution, $attributeGroupRepository, AttributeGroupInterface $object1, AttributeGroupInterface $object2, AttributeGroupInterface $defaultGroup) { $attributeGroupRepository->findDefaultAttributeGroup()->willReturn($defaultGroup); $bulkSaver->saveAll([$object1, $object2, $defaultGroup]); $bulkDetacher->detachAll([$object1, $object2, $defaultGroup]); $object1->getId()->willReturn(null); $stepExecution->incrementSummaryInfo('create')->shouldBeCalled(); $defaultGroup->getId()->willReturn(42); $stepExecution->incrementSummaryInfo('process')->shouldBeCalled(); $this->write([$object1, $defaultGroup]); }
function it_add_attributes_to_attribute_group($groupSaver, $attributeSaver, AttributeGroupInterface $default, AttributeGroupInterface $group, AttributeInterface $sku, AttributeInterface $name) { $group->getMaxAttributeSortOrder()->willReturn(5); $sku->setSortOrder(6)->shouldBeCalled(); $group->addAttribute($sku)->shouldBeCalled(); $name->setSortOrder(7)->shouldBeCalled(); $group->addAttribute($name)->shouldBeCalled(); $attributeSaver->saveAll([$sku, $name])->shouldBeCalled(); $groupSaver->save($group)->shouldBeCalled(); $this->addAttributes($group, [$sku, $name]); }
/** * Add attributes to a group * * @param AttributeGroupInterface $group * @param AttributeInterface[] $attributes */ public function addAttributes(AttributeGroupInterface $group, $attributes) { $maxOrder = $group->getMaxAttributeSortOrder(); foreach ($attributes as $attribute) { $maxOrder++; $attribute->setSortOrder($maxOrder); $group->addAttribute($attribute); } $this->attributeSaver->saveAll($attributes); $this->groupSaver->save($group); }
function it_does_not_update_attributes_from_the_default_group($attributeGroupRepository, AttributeGroupInterface $attributeGroup) { $values = ['code' => 'other', 'sort_order' => 1, 'attributes' => ['foo'], 'label' => ['en_US' => 'Other', 'fr_FR' => 'Autre']]; $attributeGroup->getCode()->willReturn('other'); $attributeGroup->setCode('other')->shouldBeCalled(); $attributeGroup->setSortOrder(1)->shouldBeCalled(); $attributeGroup->setLocale('en_US')->shouldBeCalled(); $attributeGroup->setLocale('fr_FR')->shouldBeCalled(); $attributeGroup->setLabel('Other')->shouldBeCalled(); $attributeGroup->setLabel('Autre')->shouldBeCalled(); $attributeGroupRepository->findDefaultAttributeGroup()->shouldNotBeCalled(); $attributeGroup->getAttributes()->shouldNotBeCalled(); $this->update($attributeGroup, $values, []); }
function it_updates_an_attribute_group($attributeRepository, AttributeGroupInterface $attributeGroup, AttributeInterface $attributeSize, AttributeInterface $attributeMainColor) { $values = ['code' => 'sizes', 'sort_order' => 1, 'attributes' => ['size', 'main_color'], 'label' => ['en_US' => 'Sizes', 'fr_FR' => 'Tailles']]; $attributeGroup->setCode('sizes')->shouldBeCalled(); $attributeGroup->setSortOrder(1)->shouldBeCalled(); $attributeRepository->findOneByIdentifier('size')->willReturn($attributeSize); $attributeRepository->findOneByIdentifier('main_color')->willReturn($attributeMainColor); $attributeGroup->addAttribute($attributeSize)->shouldBeCalled(); $attributeGroup->addAttribute($attributeMainColor)->shouldBeCalled(); $attributeGroup->setLocale('en_US')->shouldBeCalled(); $attributeGroup->setLocale('fr_FR')->shouldBeCalled(); $attributeGroup->setLabel('Sizes')->shouldBeCalled(); $attributeGroup->setLabel('Tailles')->shouldBeCalled(); $this->update($attributeGroup, $values, []); }
/** * @param AttributeGroupInterface $attributeGroup * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData($attributeGroup, $field, $data) { if ('code' == $field) { $attributeGroup->setCode($data); } elseif ('sort_order' == $field) { $attributeGroup->setSortOrder($data); } elseif ('attributes' == $field) { foreach ($data as $attributeCode) { $attribute = $this->findAttribute($attributeCode); if (null !== $attribute) { $attributeGroup->addAttribute($attribute); } else { throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode)); } } } elseif ('label' == $field) { foreach ($data as $locale => $label) { $attributeGroup->setLocale($locale); $attributeGroup->setLabel($label); } } }
/** * @param AttributeGroupInterface $group * * @Given /^I should be on the ("([^"]*)" attribute group) page$/ */ public function iShouldBeOnTheAttributeGroupPage(AttributeGroupInterface $group) { $expectedAddress = $this->getPage('AttributeGroup edit')->getUrl(['id' => $group->getId()]); $this->assertAddress($expectedAddress); }
/** * @param AttributeGroupInterface $group */ protected function initializeGroup(AttributeGroupInterface $group) { $this->view[$group->getId()] = ['label' => $group->getLabel(), 'attributes' => []]; }
/** * @param AttributeGroupInterface $attributeGroup * @param string[] $data */ protected function setAttributes(AttributeGroupInterface $attributeGroup, array $data) { if ('other' === $attributeGroup->getCode()) { return; } $defaultGroup = $this->attributeGroupRepository->findDefaultAttributeGroup(); foreach ($attributeGroup->getAttributes() as $attribute) { if (!in_array($attribute->getCode(), $data)) { $defaultGroup->addAttribute($attribute); } } foreach ($data as $attributeCode) { $attribute = $this->findAttribute($attributeCode); if (null === $attribute) { throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode)); } $attributeGroup->addAttribute($attribute); } }