function it_returns_a_price_collection_even_if_the_data_is_empty($productBuilder, ProductValueInterface $priceValue, ProductPriceInterface $price, ArrayCollection $priceCollection) { $productBuilder->addPriceForCurrency(Argument::cetera())->willReturn($price); $priceValue->addPrice($price)->shouldBeCalled(); $priceValue->getPrices()->willReturn($priceCollection); $context = ['value' => $priceValue, 'price_currency' => 'WillNotBeUsed']; $this->denormalize('', 'className', null, $context)->shouldReturn($priceCollection); $this->denormalize(null, 'className', null, $context)->shouldReturn($priceCollection); }
/** * @param ProductValueInterface $value * @param string $currency * * @return null|ProductPriceInterface */ protected function getPriceForCurrency(ProductValueInterface $value, $currency) { foreach ($value->getPrices() as $price) { if ($currency === $price->getCurrency()) { return $price; } } return null; }
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]); }