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_adds_violation_when_currency_does_not_exists($currencyManager, $context, Currency $constraint, ProductPriceInterface $price)
 {
     $price->getCurrency()->willReturn('CHF');
     $currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
     $context->addViolationAt('currency', Argument::any())->shouldBeCalled();
     $this->validate($price, $constraint)->shouldReturn(null);
 }
 function it_marks_product_as_updated_when_a_product_price_is_updated(EntityManager $em, UnitOfWork $uow, ProductInterface $product, ProductValueInterface $value, ProductPriceInterface $price)
 {
     $price->getValue()->willReturn($value);
     $value->getEntity()->willReturn($product);
     $em->getUnitOfWork()->willReturn($uow);
     $uow->getEntityChangeSet($price)->willReturn(['data' => ['10', '11']]);
     $this->guessUpdates($em, $price, UpdateGuesserInterface::ACTION_UPDATE_ENTITY)->shouldReturn([$product]);
 }
 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_sets_a_attribute_data_price_collection_value_to_a_product_value($builder, AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $productValue, ProductPriceInterface $price)
 {
     $locale = 'fr_FR';
     $scope = 'mobile';
     $data = [['data' => 123.2, 'currency' => 'EUR']];
     $attribute->getCode()->willReturn('attributeCode');
     $builder->addProductValue($product2, $attribute, $locale, $scope)->willReturn($productValue);
     $product1->getValue('attributeCode', $locale, $scope)->shouldBeCalled()->willReturn($productValue);
     $product2->getValue('attributeCode', $locale, $scope)->willReturn(null);
     $product3->getValue('attributeCode', $locale, $scope)->willReturn($productValue);
     $product4->getValue('attributeCode', $locale, $scope)->willReturn($productValue);
     $productValue->getPrices()->willReturn([$price]);
     $price->setData(null)->shouldBeCalled();
     $builder->addPriceForCurrencyWithData($productValue, 'EUR', 123.2)->shouldBeCalled();
     $this->setattributeData($product1, $attribute, $data, ['locale' => $locale, 'scope' => $scope]);
     $this->setattributeData($product2, $attribute, $data, ['locale' => $locale, 'scope' => $scope]);
     $this->setattributeData($product3, $attribute, $data, ['locale' => $locale, 'scope' => $scope]);
     $data = [['data' => 'foo', 'currency' => 'EUR']];
     $builder->addPriceForCurrencyWithData($productValue, 'EUR', 'foo')->shouldBeCalled();
     $this->setattributeData($product4, $attribute, $data, ['locale' => $locale, 'scope' => $scope]);
 }
 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]);
 }
 /**
  * {@inheritdoc}
  */
 public function addPrice(ProductPriceInterface $price)
 {
     if (null !== ($actualPrice = $this->getPrice($price->getCurrency()))) {
         $this->removePrice($actualPrice);
     }
     $this->prices->add($price);
     $price->setValue($this);
     return $this;
 }
 function it_does_not_validate_a_product_media($context, NotDecimal $constraint, ProductPriceInterface $productPrice)
 {
     $productPrice->getData()->willReturn(520.55);
     $context->addViolationAt('data', $constraint->message)->shouldBeCalled();
     $this->validate($productPrice, $constraint);
 }
 function it_returns_flat_data_with_french_attribute($channelManager, $serializer, $dateformatProvider, $numberFormatProvider, ChannelInterface $channel, ProductInterface $product, ProductValueInterface $number, AttributeInterface $attribute, MetricInterface $metric, ProductValueInterface $metricValue, ProductPriceInterface $price, ProductValueInterface $priceValue)
 {
     $dateformatProvider->getFormat('fr_FR')->willReturn('d/m/Y');
     $numberFormatProvider->getFormat('fr_FR')->willReturn(['decimal_separator' => ',']);
     $this->configureOptions('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' => '', 'decimal_separator' => ',', 'date_format' => 'd/m/Y'])->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_does_not_validate_a_product_price($context, Range $constraint, ProductPriceInterface $productPrice)
 {
     $constraint->min = 0;
     $constraint->max = 100;
     $productPrice->getData()->willReturn(150);
     $context->addViolationAt('data', $constraint->maxMessage, ['{{ value }}' => 150, '{{ limit }}' => 100])->shouldBeCalled();
     $this->validate($productPrice, $constraint);
 }
 function it_adds_violation_when_validating_non_numeric_product_price_value($context, ProductPriceInterface $productPrice, Numeric $numericConstraint, ConstraintViolationBuilderInterface $violation)
 {
     $productPrice->getData()->willReturn('a');
     $context->buildViolation($numericConstraint->message)->shouldBeCalled()->willReturn($violation);
     $this->validate($productPrice, $numericConstraint);
 }
 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_normalizes_price(ProductPriceInterface $price)
 {
     $price->getData()->willReturn('12.75');
     $price->getCurrency()->willReturn('EUR');
     $this->normalize($price, 'mongodb_json', [])->shouldReturn(['data' => '12.75', 'currency' => 'EUR']);
 }