/** * {@inheritdoc} * * @return Family */ protected function createEntity(array $data) { $family = new Family(); $family->setCode('mycode'); foreach ($this->getLabels($data) as $locale => $label) { $translation = $family->getTranslation($locale); $translation->setLabel($label); $family->addTranslation($translation); } $codes = array('attribute1', 'attribute2', 'attribute3'); $attributes = array(); foreach ($codes as $code) { $attribute = new Attribute(); $attribute->setCode($code); $family->addAttribute($attribute); $attributes[] = $attribute; } $family->setAttributeAsLabel(current($attributes)); $channel1 = new Channel(); $channel1->setCode('channel1'); $channel2 = new Channel(); $channel2->setCode('channel2'); $requirements = array(array('attribute' => $attributes[0], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[2], 'channel' => $channel1, 'required' => false), array('attribute' => $attributes[0], 'channel' => $channel2, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel2, 'required' => false), array('attribute' => $attributes[2], 'channel' => $channel2, 'required' => true)); $attrRequirements = array(); foreach ($requirements as $requirement) { $attrRequirement = new AttributeRequirement(); $attrRequirement->setAttribute($requirement['attribute']); $attrRequirement->setChannel($requirement['channel']); $attrRequirement->setRequired($requirement['required']); $attrRequirements[] = $attrRequirement; } $family->setAttributeRequirements($attrRequirements); return $family; }
function it_has_attribute_requirements(AttributeRequirement $requirement) { $requirement->getAttributeCode()->willReturn('foo'); $requirement->getChannelCode()->willReturn('bar'); $this->addAttributeRequirement($requirement); $this->getAttributeRequirements()->toArray()->shouldReturn(['foo_bar' => $requirement]); }
/** * Create and configure an attribute requirement instance * * @param AbstractAttribute $attribute * @param Channel $channel * @param boolean $required * * @return AttributeRequirement */ public function createAttributeRequirement(AbstractAttribute $attribute, Channel $channel, $required) { $requirement = new AttributeRequirement(); $requirement->setAttribute($attribute); $requirement->setChannel($channel); $requirement->setRequired($required); return $requirement; }
function it_normalizes_family($transnormalizer, $family, AttributeInterface $name, AttributeInterface $price, AttributeRequirement $ecommercereq, AttributeRequirement $mobilereq, ChannelInterface $ecommerce, ChannelInterface $mobile) { $transnormalizer->normalize(Argument::cetera())->willReturn([]); $family->getCode()->willReturn('mugs'); $family->getAttributes()->willReturn([$name, $price]); $name->getCode()->willReturn('name'); $price->getCode()->willReturn('price'); $family->getAttributeAsLabel()->willReturn($name); $family->getAttributeRequirements()->willReturn([$ecommercereq, $mobilereq]); $ecommercereq->getChannel()->willReturn($ecommerce); $mobilereq->getChannel()->willReturn($mobile); $ecommercereq->isRequired()->willReturn(true); $mobilereq->isRequired()->willReturn(false); $ecommerce->getCode()->willReturn('ecommerce'); $mobile->getCode()->willReturn('mobile'); $ecommercereq->getAttribute()->willReturn($name); $result = $this->normalize($family)->shouldReturn(['code' => 'mugs', 'attributes' => 'name,price', 'attributeAsLabel' => 'name', 'requirements' => 'ecommerce:name|mobile:']); }
/** * Create attribute requirement entity * * @param ChannelInterface $channel * @param AttributeInterface $attribute * @param FamilyInterface $family * * @return AttributeRequirementInterface */ protected function createAttributeRequirement(ChannelInterface $channel, AttributeInterface $attribute, FamilyInterface $family) { $requirement = new AttributeRequirement(); $requirement->setChannel($channel); $requirement->setAttribute($attribute); $requirement->setFamily($family); return $requirement; }
/** * Create attribute requirement entity * * @param Channel $channel * @param AbstractAttribute $attribute * @param Family $family * * @return \Pim\Bundle\CatalogBundle\Entity\AttributeRequirement */ protected function createAttributeRequirement(Channel $channel, AbstractAttribute $attribute, Family $family) { $requirement = new AttributeRequirement(); $requirement->setChannel($channel); $requirement->setAttribute($attribute); $requirement->setFamily($family); return $requirement; }
/** * {@inheritDoc} */ public function isRequired() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'isRequired', array()); return parent::isRequired(); }
/** * Adds a requirement to the completenesses * * @param array &$completenesses * @param AttributeRequirement $requirement * @param ArrayCollection $productValues * @param array $localeCodes */ protected function addRequirementToCompleteness(array &$completenesses, AttributeRequirement $requirement, ArrayCollection $productValues, array $localeCodes) { $attribute = $requirement->getAttribute(); $channel = $requirement->getChannel(); foreach ($localeCodes as $localeCode) { $constraint = new ProductValueComplete(array('channel' => $channel)); $valueCode = $this->getValueCode($attribute, $localeCode, $channel->getCode()); $missing = false; if (!isset($productValues[$valueCode])) { $missing = true; } elseif ($this->validator->validateValue($productValues[$valueCode], $constraint)->count()) { $missing = true; } if ($missing) { $completenesses[$localeCode][$channel->getCode()]['missing'][] = $attribute; } } }
/** * Get attribute requirement key * * @param AttributeRequirement $requirement * * @return string */ public function getAttributeRequirementKey(AttributeRequirement $requirement) { return sprintf('%s_%s', $requirement->getAttributeCode(), $requirement->getChannelCode()); }