function it_converts_metric_values_given_the_configured_base_unit_in_the_channel($converter, AbstractProductValue $weightValue, AbstractProductValue $surfaceValue, AbstractProductValue $nameValue, AbstractAttribute $weight, AbstractAttribute $surface, AbstractAttribute $name, AbstractMetric $weightMetric, AbstractMetric $surfaceMetric, ProductInterface $product, Channel $channel)
 {
     $weightValue->getAttribute()->willReturn($weight);
     $weightValue->getData()->willReturn($weightMetric);
     $weight->getCode()->willReturn('weight');
     $weightMetric->getFamily()->willReturn('Weight');
     $weightMetric->getUnit()->willReturn('KILOGRAM');
     $weightMetric->getData()->willReturn(1);
     $surfaceValue->getAttribute()->willReturn($surface);
     $surfaceValue->getData()->willReturn($surfaceMetric);
     $surface->getCode()->willReturn('surface');
     $surfaceMetric->getFamily()->willReturn('Surface');
     $surfaceMetric->getUnit()->willReturn('METER_SQUARE');
     $surfaceMetric->getData()->willReturn(10);
     $nameValue->getAttribute()->willReturn($name);
     $nameValue->getData()->willReturn('foobar');
     $product->getValues()->willReturn(array($weightValue, $surfaceValue, $nameValue));
     $channel->getConversionUnits()->willReturn(array('weight' => 'GRAM'));
     $converter->setFamily('Weight')->shouldBeCalled();
     $converter->convert('KILOGRAM', 'GRAM', 1)->willReturn(0.001);
     $converter->setFamily('Surface')->shouldNotBeCalled();
     $weightMetric->setData(0.001)->shouldBeCalled();
     $weightMetric->setUnit('GRAM')->shouldBeCalled();
     $this->convert($product, $channel);
 }
 function let(AttributeConstraintGuesser $guesser, AbstractProductValue $value, AbstractAttribute $color, AttributeOption $red)
 {
     $value->getAttribute()->willReturn($color);
     $value->getData()->willReturn(new ArrayCollection([$red]));
     $color->getBackendType()->willReturn(AbstractAttributeType::BACKEND_TYPE_OPTIONS);
     $this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_OPTIONS, 'pim_ajax_entity', $guesser);
 }
 function it_normalizes_a_value_with_an_array_data(AbstractProductValue $value, $simpleAttribute, $serializer)
 {
     $itemOne = new \stdClass();
     $itemTwo = new \stdClass();
     $array = [$itemOne, $itemTwo];
     $value->getData()->willReturn($array);
     $value->getAttribute()->willReturn($simpleAttribute);
     $serializer->normalize(Argument::any(), 'flat', ['field_name' => 'simple'])->shouldBeCalled()->willReturn(['simple' => 'red, blue']);
     $this->normalize($value, 'flat', [])->shouldReturn(['simple' => 'red, blue']);
 }
 /**
  * Get the internal key that is used to index
  * a product value in a collection of values
  *
  * @param AbstractProductValue $value
  *
  * @return string
  */
 public static function getKey(AbstractProductValue $value)
 {
     $attribute = $value->getAttribute();
     $key = $attribute->getCode();
     if ($attribute->isLocalizable()) {
         $key .= '_' . $value->getLocale();
     }
     if ($attribute->isScopable()) {
         $key .= '_' . $value->getScope();
     }
     return $key;
 }
 function it_normalizes_a_product_value_into_mongodb_document($mongoFactory, $serializer, AbstractProductValue $value, AbstractAttribute $attribute, \MongoDBRef $mongoDBRef, \MongoId $mongoId)
 {
     $context = ['_id' => $mongoId, 'collection_name' => 'product'];
     $mongoFactory->createMongoId()->willReturn($mongoId);
     $mongoFactory->createMongoDBRef('product', $mongoId)->willReturn($mongoDBRef);
     $attribute->getId()->willReturn(123);
     $attribute->getBackendType()->willReturn('text');
     $value->getAttribute()->willReturn($attribute);
     $value->getData()->willReturn('my description');
     $value->getLocale()->willReturn(null);
     $value->getScope()->willReturn(null);
     $this->normalize($value, 'mongodb_document', $context)->shouldReturn(['_id' => $mongoId, 'attribute' => 123, 'entity' => $mongoDBRef, 'text' => 'my description']);
 }
 function it_normalizes_product_with_a_multiselect_value($filter, $serializer, ProductInterface $product, AbstractAttribute $skuAttribute, AbstractAttribute $colorsAttribute, AbstractProductValue $sku, AbstractProductValue $colors, AttributeOption $red, AttributeOption $blue, Collection $values, Family $family)
 {
     $family->getCode()->willReturn('shoes');
     $skuAttribute->getCode()->willReturn('sku');
     $skuAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $skuAttribute->isLocalizable()->willReturn(false);
     $skuAttribute->isScopable()->willReturn(false);
     $sku->getAttribute()->willReturn($skuAttribute);
     $sku->getData()->willReturn('sku-001');
     $colorsAttribute->getCode()->willReturn('colors');
     $colorsAttribute->isLocalizable()->willReturn(false);
     $colorsAttribute->isScopable()->willReturn(false);
     $colors->getAttribute()->willReturn($colorsAttribute);
     $colors->getData()->willReturn([$red, $blue]);
     $product->getIdentifier()->willReturn($sku);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroupCodes()->willReturn('');
     $product->getCategoryCodes()->willReturn('');
     $product->getAssociations()->willReturn([]);
     $product->getValues()->willReturn($values);
     $filter->filter($values, ['identifier' => $sku, 'scopeCode' => null, 'localeCodes' => []])->willReturn([$sku, $colors]);
     $serializer->normalize($sku, 'flat', Argument::any())->willReturn(['sku' => 'sku-001']);
     $serializer->normalize($colors, 'flat', Argument::any())->willReturn(['colors' => 'red, blue']);
     $this->normalize($product, 'flat', [])->shouldReturn(['sku' => 'sku-001', 'family' => 'shoes', 'groups' => '', 'categories' => '', 'colors' => 'red, blue', 'enabled' => 1]);
 }
 function let(AttributeConstraintGuesser $guesser, AbstractProductValue $value, AbstractAttribute $name)
 {
     $value->getAttribute()->willReturn($name);
     $this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_VARCHAR, 'text', $guesser);
 }
 function let(AttributeConstraintGuesser $guesser, MeasureManager $manager, MetricFactory $metricFactory, AbstractProductValue $value, AbstractAttribute $size)
 {
     $value->getAttribute()->willReturn($size);
     $this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_METRIC, 'pim_enrich_metric', $guesser, $manager, $metricFactory);
 }
 function let(AttributeConstraintGuesser $guesser, AbstractProductValue $value, AbstractAttribute $isAvailable)
 {
     $value->getAttribute()->willReturn($isAvailable);
     $this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_BOOLEAN, 'switch', $guesser);
 }
 function let(AttributeConstraintGuesser $guesser, AbstractProductValue $value, AbstractAttribute $releaseDate)
 {
     $value->getAttribute()->willReturn($releaseDate);
     $this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_DATE, 'oro_date', $guesser);
 }