function it_has_attribute_requirements(AttributeRequirementInterface $requirement) { $requirement->getAttributeCode()->willReturn('foo'); $requirement->getChannelCode()->willReturn('bar'); $this->addAttributeRequirement($requirement); $this->getAttributeRequirements()->toArray()->shouldReturn(['foo_bar' => $requirement]); }
function it_provide_product_completeness_if_a_family_is_defined($familyRepository, $productValueCompleteChecker, QueryBuilder $qb, AbstractQuery $query, AttributeRequirementInterface $requirement, ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en, FamilyInterface $shirt, CompletenessInterface $completeness, ProductValueInterface $nameValue, AttributeInterface $name) { $product->getFamily()->willReturn($shirt); $product->getCompletenesses()->willReturn([$completeness]); $en->getCode()->willReturn('en_US'); $mobile->getCode()->willReturn('mobile'); $completeness->getLocale()->willReturn($en); $completeness->getChannel()->willReturn($mobile); $completeness->getMissingCount()->willReturn(1); $familyRepository->getFullRequirementsQB($shirt, 'en_US')->willReturn($qb); $qb->getQuery()->willReturn($query); $query->getResult()->willReturn([$requirement]); $requirement->getChannel()->willReturn($mobile); $requirement->getAttribute()->willReturn($name); $requirement->isRequired()->willReturn(true); $name->getCode()->willReturn('name'); $name->isLocalizable()->willreturn(true); $name->isScopable()->willReturn(false); $name->isLocaleSpecific()->willReturn(true); $name->hasLocaleSpecific($en)->willReturn(false); $product->getValues()->willReturn(new ArrayCollection()); $productValueCompleteChecker->supportsValue($nameValue); $productValueCompleteChecker->isComplete($nameValue, $mobile, $en); $this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn(['en_US' => ['channels' => ['mobile' => ['completeness' => $completeness, 'missing' => []]], 'stats' => ['total' => 1, 'complete' => 0]]]); }
function it_does_not_validate_families_with_missing_identifier_requirements($attributeRepository, $channelRepository, $context, $minimumRequirements, FamilyInterface $family, AttributeRequirementInterface $requirementEcommerce, AttributeRequirementInterface $requirementMobile, ConstraintViolationBuilderInterface $violation) { $family->getAttributeRequirements()->willReturn([$requirementEcommerce, $requirementMobile]); $attributeRepository->getIdentifierCode()->willReturn('sku'); $requirementEcommerce->getAttributeCode()->willReturn('sku'); $requirementEcommerce->getChannelCode()->willReturn('ecommerce'); $requirementMobile->getAttributeCode()->willReturn('sku'); $requirementMobile->getChannelCode()->willReturn('mobile'); $channelRepository->getChannelCodes()->willReturn(['ecommerce', 'mobile', 'print']); $family->getCode()->willReturn('familyCode'); $context->buildViolation(Argument::any(), Argument::any())->willReturn($violation)->shouldBeCalled(); $this->validate($family, $minimumRequirements); }
function it_returns_well_formatted_actions_for_batch_job(AttributeInterface $attrColor, AttributeInterface $attrSize, ChannelInterface $channelMobile, ChannelInterface $channelEcommerce, AttributeRequirementInterface $colorMobileRequirement, AttributeRequirementInterface $colorEcommerceRequirement, AttributeRequirementInterface $sizeEcommerceRequirement) { $attrColor->getCode()->willReturn('color'); $attrSize->getCode()->willReturn('size'); $channelMobile->getCode()->willReturn('mobile'); $channelEcommerce->getCode()->willReturn('ecommerce'); $colorMobileRequirement->getAttribute()->willReturn($attrColor); $colorEcommerceRequirement->getAttribute()->willReturn($attrColor); $sizeEcommerceRequirement->getAttribute()->willReturn($attrSize); $colorMobileRequirement->getChannel()->willReturn($channelMobile); $colorEcommerceRequirement->getChannel()->willReturn($channelEcommerce); $sizeEcommerceRequirement->getChannel()->willReturn($channelEcommerce); $colorMobileRequirement->isRequired()->willReturn(false); $colorEcommerceRequirement->isRequired()->willReturn(true); $sizeEcommerceRequirement->isRequired()->willReturn(true); $colorMobileRequirement->getAttributeCode()->willReturn('color'); $colorEcommerceRequirement->getAttributeCode()->willReturn('color'); $sizeEcommerceRequirement->getAttributeCode()->willReturn('size'); $colorMobileRequirement->getChannelCode()->willReturn('mobile'); $colorEcommerceRequirement->getChannelCode()->willReturn('ecommerce'); $sizeEcommerceRequirement->getChannelCode()->willReturn('ecommerce'); $this->addAttributeRequirement($colorMobileRequirement); $this->addAttributeRequirement($colorEcommerceRequirement); $this->addAttributeRequirement($sizeEcommerceRequirement); $this->getActions()->shouldReturn([['attribute_code' => 'color', 'channel_code' => 'mobile', 'is_required' => false], ['attribute_code' => 'color', 'channel_code' => 'ecommerce', 'is_required' => true], ['attribute_code' => 'size', 'channel_code' => 'ecommerce', 'is_required' => true]]); }
function it_creates_a_family($attributeRepository, $channelManager, $factory, AttributeInterface $identifierAttribute, ChannelInterface $printChannel, ChannelInterface $ecommerceChannel, AttributeRequirementInterface $printRequirement, AttributeRequirementInterface $ecommerceRequirement) { $attributeRepository->getIdentifier()->willReturn($identifierAttribute)->shouldBeCalled(); $printRequirement->setFamily(Argument::any())->willReturn(null); $printRequirement->getAttributeCode()->willReturn('anyCode'); $printRequirement->getChannelCode()->willReturn('print'); $ecommerceRequirement->setFamily(Argument::any())->willReturn(null); $ecommerceRequirement->getAttributeCode()->willReturn('anyCode'); $ecommerceRequirement->getChannelCode()->willReturn('ecommerce'); $channelManager->getChannels()->willReturn([$printChannel, $ecommerceChannel])->shouldBeCalled(); $factory->createAttributeRequirement($identifierAttribute, $printChannel, true)->willReturn($printRequirement)->shouldBeCalled(); $factory->createAttributeRequirement($identifierAttribute, $ecommerceChannel, true)->willReturn($ecommerceRequirement)->shouldBeCalled(); $family = $this->createFamily(); $family->shouldBeAnInstanceOf('Pim\\Bundle\\CatalogBundle\\Model\\FamilyInterface'); $family->getAttributes()->shouldHaveCount(1); $family->getAttributes()->first()->shouldBeEqualTo($identifierAttribute); $family->getAttributeRequirements()->shouldHaveCount(2); $family->getAttributeRequirements()->shouldBeEqualTo(['anyCode_print' => $printRequirement, 'anyCode_ecommerce' => $ecommerceRequirement]); }
/** * Adds a requirement to the completenesses * * @param array &$completenesses * @param AttributeRequirementInterface $requirement * @param ArrayCollection $productValues * @param LocaleInterface[] $locales */ protected function addRequirementToCompleteness(array &$completenesses, AttributeRequirementInterface $requirement, ArrayCollection $productValues, array $locales) { $attribute = $requirement->getAttribute(); $channel = $requirement->getChannel(); foreach ($locales as $locale) { $localeCode = $locale->getCode(); $valueCode = $this->getValueCode($attribute, $localeCode, $channel->getCode()); $missing = false; $productValue = isset($productValues[$valueCode]) ? $productValues[$valueCode] : null; $isIncomplete = null !== $productValue && $this->productValueCompleteChecker->supportsValue($productValue) && !$this->productValueCompleteChecker->isComplete($productValue, $channel, $locale); $shouldExistInLocale = !$attribute->isLocaleSpecific() || $attribute->hasLocaleSpecific($locale); if ((null === $productValue || $isIncomplete) && $shouldExistInLocale) { $completenesses[$localeCode]['channels'][$channel->getCode()]['missing'][] = $attribute; } } }
/** * {@inheritdoc} */ public function getAttributeRequirementKey(AttributeRequirementInterface $requirement) { return sprintf('%s_%s', $requirement->getAttributeCode(), $requirement->getChannelCode()); }
/** * Adds a requirement to the completenesses * * @param array &$completenesses * @param AttributeRequirementInterface $requirement * @param ArrayCollection $productValues * @param array $localeCodes */ protected function addRequirementToCompleteness(array &$completenesses, AttributeRequirementInterface $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; } } }
public function it_should_not_remove_identifier_requirements_when_other_requirements_are_provided($attrRequiFactory, $channelRepository, FamilyInterface $family, AttributeRepositoryInterface $attributeRepository, AttributeInterface $skuAttribute, AttributeInterface $nameAttribute, AttributeInterface $descAttribute, AttributeRequirementInterface $skuMobileRqrmt, AttributeRequirementInterface $skuPrintRqrmt, AttributeRequirementInterface $namePrintRqrmt, AttributeRequirementInterface $descPrintRqrmt, ChannelInterface $mobileChannel, ChannelInterface $printChannel) { $values = ['code' => 'mycode', 'requirements' => ['print' => ['name', 'description']]]; $family->getAttributeRequirements()->willReturn([$skuMobileRqrmt, $skuPrintRqrmt]); $skuMobileRqrmt->getAttribute()->willReturn($skuAttribute); $skuPrintRqrmt->getAttribute()->willReturn($skuAttribute); $skuMobileRqrmt->getChannelCode()->willReturn('mobile'); $skuPrintRqrmt->getChannelCode()->willReturn('print'); $skuAttribute->getAttributeType()->willReturn(AttributeTypes::IDENTIFIER); $channelRepository->findOneByIdentifier('print')->willReturn($printChannel); $attributeRepository->findOneByIdentifier('name')->willReturn($nameAttribute); $attributeRepository->findOneByIdentifier('description')->willReturn($descAttribute); $attrRequiFactory->createAttributeRequirement($nameAttribute, $printChannel, true)->willReturn($namePrintRqrmt); $attrRequiFactory->createAttributeRequirement($descAttribute, $printChannel, true)->willReturn($descPrintRqrmt); $namePrintRqrmt->getAttribute()->willReturn($nameAttribute); $descPrintRqrmt->getAttribute()->willReturn($descAttribute); $channelRepository->getChannelCodes()->willReturn(['mobile', 'print']); $channelRepository->findOneByIdentifier('mobile')->willReturn($mobileChannel); $channelRepository->findOneByIdentifier('print')->willReturn($printChannel); $attributeRepository->getIdentifier()->willReturn($skuAttribute); $family->setCode('mycode')->shouldBeCalled(); $family->setAttributeRequirements([$skuMobileRqrmt, $skuPrintRqrmt, $namePrintRqrmt, $descPrintRqrmt])->shouldBeCalled(); $this->update($family, $values, []); }
/** * Adds a requirement to the completenesses * * @param array &$completenesses * @param AttributeRequirementInterface $requirement * @param ArrayCollection $productValues * @param Locale[] $locales */ protected function addRequirementToCompleteness(array &$completenesses, AttributeRequirementInterface $requirement, ArrayCollection $productValues, array $locales) { $attribute = $requirement->getAttribute(); $channel = $requirement->getChannel(); foreach ($locales as $locale) { $localeCode = $locale->getCode(); $valueCode = $this->getValueCode($attribute, $localeCode, $channel->getCode()); $missing = false; $productValue = isset($productValues[$valueCode]) ? $productValues[$valueCode] : null; if (null === $productValue) { $missing = true; } elseif ($this->productValueCompleteCkecker->supportsValue($productValue) && !$this->productValueCompleteCkecker->isComplete($productValue, $channel, $locale)) { $missing = true; } if ($missing) { $completenesses[$localeCode]['channels'][$channel->getCode()]['missing'][] = $attribute; } } }