/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $metric = $productValue->getMetric(); // Process only if the value is not null if (is_object($metric)) { if ($metric->getData() && $metric->getBaseUnit()) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_metric', 'value' => (double) $metric->getData(), 'unit' => $metric->getUnit()); } } }
function it_copies_a_metric_value_to_a_product_value($builder, $metricFactory, $attrValidatorHelper, MetricInterface $metric, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, ProductValue $toProductValue2) { $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(); $attrValidatorHelper->validateUnitFamilies(Argument::cetera())->shouldBeCalled(); $fromProductValue->getData()->willReturn($metric); $toProductValue->setMetric($metric)->shouldBeCalledTimes(2); $toProductValue->getData()->willReturn($metric); $toProductValue->getMetric()->willReturn($metric); $toProductValue2->setMetric($metric)->shouldBeCalledTimes(1); $toProductValue2->getData()->willReturn($metric); $toProductValue2->getMetric()->willReturn(null); $metric->getFamily()->shouldBeCalled()->willReturn('Weight'); $metric->getData()->shouldBeCalled()->willReturn(123); $metric->getUnit()->shouldBeCalled()->willReturn('kg'); $metric->setData(123)->shouldBeCalled(); $metric->setUnit('kg')->shouldBeCalled(); $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($toProductValue2); $metricFactory->createMetric('Weight')->shouldBeCalledTimes(1)->willReturn($metric); $builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue); $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_sets_non_numeric_attribute_data_to_a_product_value(AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, $builder, $factory, MetricInterface $metric, ProductValue $productValue) { $locale = 'fr_FR'; $scope = 'mobile'; $data = ['data' => 'foo', 'unit' => 'KILOGRAM']; $attribute->getCode()->willReturn('attributeCode'); $attribute->getMetricFamily()->willReturn('Weight'); $productValue->getMetric()->willReturn(null); $productValue->setMetric($metric)->shouldBeCalled(); $metric->setUnit('KILOGRAM')->shouldBeCalled(); $metric->setData($data['data'])->shouldBeCalled(); $builder->addProductValue($product2, $attribute, $locale, $scope)->willReturn($productValue); $factory->createMetric('Weight')->shouldBeCalledTimes(3)->willReturn($metric); $product1->getValue('attributeCode', $locale, $scope)->willReturn($productValue); $product2->getValue('attributeCode', $locale, $scope)->willReturn(null); $product3->getValue('attributeCode', $locale, $scope)->willReturn($productValue); $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]); }
/** * {@inheritDoc} */ public function getMetric() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getMetric', array()); return parent::getMetric(); }
function it_sets_numeric_value_to_a_product_value(AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, $builder, $measureManager, $factory, MetricInterface $metric, ProductValue $productValue) { $locale = 'fr_FR'; $scope = 'mobile'; $data = ['data' => 107, 'unit' => 'KILOGRAM']; $attribute->getCode()->willReturn('attributeCode'); $attribute->getMetricFamily()->willReturn('Weight'); $measureManager->getUnitSymbolsForFamily('Weight')->shouldBeCalled()->willReturn(['KILOGRAM' => 'kg', 'GRAM' => 'g']); $productValue->getMetric()->willReturn(null); $productValue->setMetric($metric)->shouldBeCalled(); $metric->setUnit('KILOGRAM')->shouldBeCalled(); $metric->setData($data['data'])->shouldBeCalled(); $builder->addProductValue($product2, $attribute, $locale, $scope)->willReturn($productValue); $factory->createMetric('Weight')->shouldBeCalledTimes(3)->willReturn($metric); $product1->getValue('attributeCode', $locale, $scope)->willReturn($productValue); $product2->getValue('attributeCode', $locale, $scope)->willReturn(null); $product3->getValue('attributeCode', $locale, $scope)->willReturn($productValue); $products = [$product1, $product2, $product3]; $this->setValue($products, $attribute, $data, $locale, $scope); }