コード例 #1
0
 function it_saves_multiple_family($completenessManager, $objectManager, $eventDispatcher, FamilyInterface $family1, FamilyInterface $family2)
 {
     $family1->getCode()->willReturn('my_code1');
     $family1->getCode()->willReturn('my_code2');
     $objectManager->persist($family1)->shouldBeCalled();
     $objectManager->persist($family2)->shouldBeCalled();
     $completenessManager->scheduleForFamily($family1)->shouldBeCalled($family1);
     $completenessManager->scheduleForFamily($family2)->shouldBeCalled($family2);
     $objectManager->flush()->shouldBeCalled();
     $eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, Argument::cetera())->shouldBeCalled();
     $eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, Argument::cetera())->shouldBeCalled();
     $eventDispatcher->dispatch(StorageEvents::PRE_SAVE, Argument::cetera())->shouldBeCalledTimes(2);
     $eventDispatcher->dispatch(StorageEvents::POST_SAVE, Argument::cetera())->shouldBeCalledTimes(2);
     $this->saveAll([$family1, $family2]);
 }
コード例 #2
0
 function it_provides_formatted_batch_config_for_the_job(FamilyInterface $mugs)
 {
     $mugs->getCode()->willReturn('amazing_mugs');
     $this->setFamily($mugs);
     $this->setFilters([['id', 'IN', ['1003', '1002']]]);
     $this->getBatchConfig()->shouldReturn(['filters' => [['id', 'IN', ['1003', '1002']]], 'actions' => [['field' => 'family', 'value' => 'amazing_mugs']]]);
 }
コード例 #3
0
 function it_provides_formatted_batch_config_for_the_job(FamilyInterface $mugs)
 {
     $mugs->getCode()->willReturn('amazing_mugs');
     $this->setFamily($mugs);
     $this->setFilters([['id', 'IN', ['1003', '1002']]]);
     $this->getBatchConfig()->shouldReturn('{\\"filters\\":[[\\"id\\",\\"IN\\",[\\"1003\\",\\"1002\\"]]],\\"actions\\":[{\\"field\\":\\"family\\",\\"value\\":\\"amazing_mugs\\"}]}');
 }
コード例 #4
0
 function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier)
 {
     $values->getIterator()->willReturn($iterator);
     $family->getCode()->willReturn('my_family');
     $product->getFamily()->willReturn($family);
     $product->getGroupCodes()->willReturn([]);
     $product->getVariantGroup()->willReturn(null);
     $product->getCategoryCodes()->willReturn([]);
     $product->isEnabled()->willReturn(true);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('name');
     $product->getIdentifier()->willReturn($identifier);
     $identifier->getData()->willReturn('my_code');
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
     $iterator->rewind()->willReturn(null);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($value);
     $iterator->next()->willReturn(null);
     $context = ['filter_types' => ['pim.transform.product_value.structured']];
     $serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $created = new \DateTime('2010-06-23');
     $product->getCreated()->willReturn($created);
     $serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00');
     $updated = new \DateTime('2010-06-23 23:00:00');
     $product->getUpdated()->willReturn($updated);
     $serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00');
     $this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']);
 }
コード例 #5
0
 function it_normalizes_family($normalizer, FamilyInterface $family, AttributeInterface $sku)
 {
     $sku->getCode()->willReturn('sku');
     $family->getCode()->willReturn('mongo');
     $family->getAttributeAsLabel()->willReturn($sku);
     $normalizer->normalize($family, 'mongodb_json', [])->willReturn(['label' => 'translations']);
     $this->normalize($family, 'mongodb_json', [])->shouldReturn(['code' => 'mongo', 'label' => 'translations', 'attributeAsLabel' => 'sku']);
 }
コード例 #6
0
 function it_saves_a_family_and_does_not_schedule($completenessManager, $optionsResolver, $objectManager, $eventDispatcher, FamilyInterface $family)
 {
     $family->getCode()->willReturn('my_code');
     $optionsResolver->resolveSaveOptions(['schedule' => false])->shouldBeCalled()->willReturn(['flush' => true, 'schedule' => false]);
     $objectManager->persist($family)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $completenessManager->scheduleForFamily($family)->shouldNotBeCalled($family);
     $eventDispatcher->dispatch(StorageEvents::PRE_SAVE, Argument::cetera())->shouldBeCalled();
     $eventDispatcher->dispatch(StorageEvents::POST_SAVE, Argument::cetera())->shouldBeCalled();
     $this->save($family, ['schedule' => false]);
 }
コード例 #7
0
 function it_builds_the_view(FormView $formView, FormInterface $form, FamilyRepositoryInterface $familyRepository, FamilyInterface $familyMugs, FamilyInterface $familyWebcams)
 {
     $options['repository'] = $familyRepository;
     $options['multiple'] = true;
     $form->getData()->willReturn('mugs,webcams');
     $familyRepository->findBy(["code" => ["mugs", "webcams"]])->willReturn([$familyMugs, $familyWebcams]);
     $familyMugs->getLabel()->willReturn('Mugs');
     $familyWebcams->getLabel()->willReturn('Webcams');
     $familyMugs->getCode()->willReturn('mugs');
     $familyWebcams->getCode()->willReturn('webcams');
     $this->buildView($formView, $form, $options);
 }
コード例 #8
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);
 }
コード例 #9
0
 /**
  * Sets the requirements for a channel
  *
  * @param string          $class
  * @param FamilyInterface $family
  * @param string          $channelCode
  * @param array           $attributeCodes
  */
 protected function setChannelRequirements($class, FamilyInterface $family, $channelCode, $attributeCodes)
 {
     foreach ($attributeCodes as $attributeCode) {
         $data = ['attribute' => $attributeCode, 'channel' => $channelCode, 'required' => true];
         $requirement = $this->transformNestedEntity($class, 'requirements', $this->requirementClass, $data);
         if ($requirement->getAttribute() === null) {
             throw new \Exception(sprintf('The attribute "%s" used as requirement in family "%s" is not known', $attributeCode, $family->getCode()));
         }
         $family->addAttributeRequirement($requirement);
     }
 }
コード例 #10
0
 function it_normalizes_product_with_price($filter, ProductInterface $product, AttributeInterface $priceAttribute, ProductValueInterface $price, Collection $prices, Collection $values, ProductPriceInterface $productPrice, FamilyInterface $family, SerializerInterface $serializer)
 {
     $family->getCode()->willReturn('shoes');
     $priceAttribute->getCode()->willReturn('price');
     $priceAttribute->getAttributeType()->willReturn('pim_catalog_price_collection');
     $priceAttribute->isLocalizable()->willReturn(false);
     $priceAttribute->isScopable()->willReturn(false);
     $price->getAttribute()->willReturn($priceAttribute);
     $price->getData()->willReturn(null);
     $productPrice->getData()->willReturn("356.00");
     $productPrice->getCurrency()->willReturn("EUR");
     $prices->add($productPrice);
     $price->getPrices()->willReturn($prices);
     $product->getIdentifier()->willReturn($price);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroupCodes()->willReturn(['group1', 'group2', 'variant_group_1']);
     $product->getCategoryCodes()->willReturn(['nice shoes', 'converse']);
     $product->getAssociations()->willReturn([]);
     $values->add($price);
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.flat', Argument::cetera())->willReturn([$price]);
     $serializer->normalize($price, 'flat', Argument::any())->willReturn(['price-EUR' => '356.00']);
     $this->normalize($product, 'flat', ['price-EUR' => ''])->shouldReturn(['price-EUR' => '356.00', 'family' => 'shoes', 'groups' => 'group1,group2,variant_group_1', 'categories' => 'nice shoes,converse', 'enabled' => 1]);
 }
コード例 #11
0
 /**
  * Normalizes a family
  *
  * @param FamilyInterface $family
  */
 protected function normalizeFamily(FamilyInterface $family = null)
 {
     $this->results[self::FIELD_FAMILY] = $family ? $family->getCode() : '';
 }
コード例 #12
0
 /**
  * Normalizes a family
  *
  * @param FamilyInterface $family
  *
  * @return string
  */
 protected function normalizeFamily(FamilyInterface $family = null)
 {
     return $family ? $family->getCode() : '';
 }
コード例 #13
0
 /**
  * Returns the attribute codes for a family
  *
  * @param FamilyInterface $family
  *
  * @return array
  */
 protected function getFamilyAttributeCodes(FamilyInterface $family)
 {
     $code = $family->getCode();
     if (!isset($this->familyAttributeCodes[$code])) {
         $this->familyAttributeCodes[$code] = $this->getAttributeCodes($family);
     }
     return $this->familyAttributeCodes[$code];
 }