function it_copies_a_price_collection_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, ProductPriceInterface $price) { $fromLocale = 'fr_FR'; $toLocale = 'fr_FR'; $toScope = 'mobile'; $fromScope = 'mobile'; $fromAttribute->getCode()->willReturn('fromAttributeCode'); $toAttribute->getCode()->willReturn('toAttributeCode'); $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled(); $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled(); $fromProductValue->getData()->willReturn([$price]); $price->getCurrency()->willReturn('USD'); $price->getData()->willReturn(123); $product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue); $product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue); $product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null); $product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue); $product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue); $product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null); $product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue); $product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue); $builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue); $builder->addPriceForCurrencyWithData($toProductValue, 'USD', 123)->shouldBeCalled(); $products = [$product1, $product2, $product3, $product4]; foreach ($products as $product) { $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]); } }
function it_returns_data_if_it_is_not_a_numeric(ProductPriceInterface $price, ProductValueInterface $productValue, AttributeInterface $attribute) { $price->getValue()->willReturn($productValue); $productValue->getAttribute()->willReturn($attribute); $attribute->isDecimalsAllowed()->willReturn(false); $price->getCurrency()->willReturn('EUR'); $price->getData()->willReturn('a_price_data'); $this->normalize($price, 'standard', ['is_decimals_allowed' => false])->shouldReturn(['amount' => 'a_price_data', 'currency' => 'EUR']); }
function it_normalizes_empty_price($priceNormalizer, $localizer, ProductPriceInterface $price) { $options = ['decimal_separator' => ',']; $price->getData()->willReturn(''); $price->getCurrency()->willReturn('EUR'); $priceNormalizer->normalize($price, null, $options)->willReturn(['price-EUR' => '']); $localizer->localize([['currency' => 'price-EUR', 'data' => '']], $options)->willReturn([['currency' => 'price-EUR', 'data' => '']]); $this->normalize($price, null, $options)->shouldReturn(['price-EUR' => '']); }
public function it_succesfully_checks_incomplete_price_collection(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ArrayCollection $arrayCollection, CurrencyInterface $currency1, CurrencyInterface $currency2, ProductPriceInterface $price1) { $channel->getCurrencies()->willReturn($arrayCollection); $arrayCollection->toArray()->willReturn([$currency1, $currency2]); $currency1->getCode()->willReturn('USD'); $price1->getCurrency()->willReturn('USD'); $price1->getData()->willReturn(null); $value->getData()->willReturn([$price1]); $this->isComplete($value, $channel, $locale)->shouldReturn(false); }
function it_does_not_validate_a_product_value_with_backendtype_as_prices($context, ProductValueComplete $constraint, ProductValueInterface $productValue, ProductPriceInterface $productPrice, AttributeInterface $attribute, ConstraintViolationBuilderInterface $violation) { $constraint->getChannel()->willReturn($this->getChannel()); $productPrice->getCurrency()->willReturn('EUR'); $productPrice->getData()->willReturn(null); $productValue->getData()->willReturn([$productPrice]); $attribute->getBackendType()->willReturn('prices'); $productValue->getAttribute()->willReturn($attribute); $context->buildViolation($constraint->messageComplete)->shouldBeCalled()->willReturn($violation); $this->validate($productValue, $constraint); }
function it_adds_violation_when_validating_non_numeric_product_price_value($context, ProductPriceInterface $productPrice, IsNumeric $numericConstraint, ConstraintViolationBuilderInterface $violation) { $productPrice->getData()->willReturn('a'); $context->buildViolation($numericConstraint->message)->shouldBeCalled()->willReturn($violation); $this->validate($productPrice, $numericConstraint); }
function it_does_not_validate_a_product_media($context, NotDecimal $constraint, ProductPriceInterface $productPrice, ConstraintViolationBuilderInterface $violation) { $productPrice->getData()->willReturn(520.55); $context->buildViolation($constraint->message)->shouldBeCalled()->willReturn($violation); $this->validate($productPrice, $constraint); }
function it_normalizes_empty_price(ProductPriceInterface $price) { $price->getData()->willReturn(''); $price->getCurrency()->willReturn('EUR'); $this->normalize($price, null, ['field_name' => 'price'])->shouldReturn(['price-EUR' => '']); }
function it_returns_flat_data_with_french_attribute($channelManager, $serializer, ChannelInterface $channel, ProductInterface $product, ProductValueInterface $number, AttributeInterface $attribute, MetricInterface $metric, ProductValueInterface $metricValue, ProductPriceInterface $price, ProductValueInterface $priceValue) { $this->setLocale('fr_FR'); $attribute->getAttributeType()->willReturn('pim_catalog_number'); $number->getDecimal('10.50'); $number->getAttribute()->willReturn($attribute); $attribute->getAttributeType()->willReturn('pim_catalog_metric'); $metric->getData()->willReturn('10.00'); $metric->getUnit()->willReturn('GRAM'); $metricValue->getAttribute()->willReturn($attribute); $metricValue->getData()->willReturn($metric); $attribute->getAttributeType()->willReturn('pim_catalog_price_collection'); $price->getData()->willReturn('10'); $price->getCurrency()->willReturn('EUR'); $priceValue->getAttribute()->willReturn($attribute); $priceValue->getData()->willReturn($price); $product->getValues()->willReturn([$number, $metricValue, $priceValue]); $serializer->normalize($product, 'flat', ['scopeCode' => 'mobile', 'localeCodes' => '', 'locale' => 'fr_FR'])->willReturn(['10,50', '10,00 GRAM', '10,00 EUR', '25/10/2015']); $channelManager->getChannelByCode('mobile')->willReturn($channel); $this->setChannelCode('mobile'); $this->process($product)->shouldReturn(['media' => [], 'product' => ['10,50', '10,00 GRAM', '10,00 EUR', '25/10/2015']]); }
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]); }
function it_does_not_validate_a_product_price($context, Range $constraint, ProductPriceInterface $productPrice, ConstraintViolationBuilderInterface $violation) { $constraint->min = 0; $constraint->max = 100; $productPrice->getData()->willReturn(150); $context->buildViolation($constraint->maxMessage, ['{{ value }}' => 150, '{{ limit }}' => 100])->shouldBeCalled()->willReturn($violation); $violation->atPath('data')->shouldBeCalled()->willReturn($violation); $violation->addViolation()->shouldBeCalled(); $this->validate($productPrice, $constraint); }
function it_normalizes_price(ProductPriceInterface $price) { $price->getData()->willReturn('12.75'); $price->getCurrency()->willReturn('EUR'); $this->normalize($price, 'mongodb_json', [])->shouldReturn(['data' => '12.75', 'currency' => 'EUR']); }