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']); }
function it_normalizes_product(SerializerInterface $serializer, ProductInterface $product, FamilyInterface $family, Completeness $completeness) { $serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface'); $this->setSerializer($serializer); $product->getFamily()->willReturn($family); $product->getGroups()->willReturn([]); $product->getValues()->willReturn([]); $product->getCompletenesses()->willReturn([$completeness]); $product->getCreated()->willReturn(null); $product->getUpdated()->willReturn(null); $product->isEnabled()->willReturn(true); $serializer->normalize($family, 'mongodb_json', [])->willReturn('family normalization'); $serializer->normalize($completeness, 'mongodb_json', [])->willReturn(['completenessCode' => 'completeness normalization']); $this->normalize($product, 'mongodb_json', [])->shouldReturn([ProductNormalizer::FAMILY_FIELD => 'family normalization', ProductNormalizer::COMPLETENESSES_FIELD => array('completenessCode' => 'completeness normalization'), ProductNormalizer::ENABLED_FIELD => true]); }
function it_normalizes_the_properties_of_the_product(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, ArrayCollection $values, \ArrayIterator $iterator, $filter, $normalizer) { $values->getIterator()->willReturn($iterator); $product->getFamily()->willReturn(null); $product->getGroupCodes()->willReturn([]); $product->getVariantGroup()->willReturn(null); $product->getCategoryCodes()->willReturn([]); $product->isEnabled()->willReturn(true); $value->getAttribute()->willReturn($attribute); $attribute->getCode()->willReturn('name'); $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); $normalizer->normalize($values, 'json', Argument::any())->willReturn(['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]); $this->normalize($product, 'json')->shouldReturn(['family' => null, 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]]); }
function it_normalizes_an_existing_product_without_family_into_mongodb_document($mongoFactory, $serializer, ProductInterface $product, \MongoId $mongoId, \MongoDate $mongoDate, Association $assoc1, Association $assoc2, CategoryInterface $category1, CategoryInterface $category2, GroupInterface $group1, GroupInterface $group2, ProductValueInterface $value1, ProductValueInterface $value2) { $mongoFactory->createMongoId('product1')->willReturn($mongoId); $mongoFactory->createMongoDate()->willReturn($mongoDate); $category1->getId()->willReturn(12); $category2->getId()->willReturn(34); $group1->getId()->willReturn(56); $group2->getId()->willReturn(78); $product->getId()->willReturn('product1'); $product->getCreated()->willReturn(null); $product->getFamily()->willReturn(null); $product->isEnabled()->willReturn(true); $product->getGroups()->willReturn([$group1, $group2]); $product->getCategories()->willReturn([$category1, $category2]); $product->getAssociations()->willReturn([$assoc1, $assoc2]); $product->getValues()->willReturn([$value1, $value2]); $context = ['_id' => $mongoId]; $serializer->normalize($product, 'mongodb_json')->willReturn(['data' => 'data', 'completenesses' => 'completenesses']); $serializer->normalize($value1, 'mongodb_document', $context)->willReturn('my_value_1'); $serializer->normalize($value2, 'mongodb_document', $context)->willReturn('my_value_2'); $serializer->normalize($assoc1, 'mongodb_document', $context)->willReturn('my_assoc_1'); $serializer->normalize($assoc2, 'mongodb_document', $context)->willReturn('my_assoc_2'); $this->normalize($product, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'created' => $mongoDate, 'updated' => $mongoDate, 'enabled' => true, 'groupIds' => [56, 78], 'categoryIds' => [12, 34], 'associations' => ['my_assoc_1', 'my_assoc_2'], 'values' => ['my_value_1', 'my_value_2'], 'normalizedData' => ['data' => 'data'], 'completenesses' => []]); }
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]); }
/** * Normalize properties * * @param ProductInterface $product */ protected function normalizeProperties(ProductInterface $product) { $this->results['enabled'] = (int) $product->isEnabled(); }