/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context * @throws \Pim\Bundle\CatalogBundle\Exception\MissingIdentifierException */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $media = $productValue->getMedia(); if ($media && null !== $media->getFilename()) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_image', 'filename_original' => $media->getOriginalFilename(), 'filename' => $media->getFilename(), 'mimetype' => $media->getMimeType(), 'length' => filesize($this->mediaManager->getFilePath($media)), 'absolute_path' => $this->mediaManager->getFilePath($media), 'attribute_id' => $media->getValue()->getAttribute()->getId(), 'media_id' => $media->getId(), 'rest_url' => '/api/rest/media/' . $productValue->getEntity()->getIdentifier() . '/' . $productValue->getAttribute()->getId()]; } }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $decimal = $productValue->getDecimal(); if (null !== $decimal) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_number', 'value' => (double) $decimal); } }
function it_copies_multi_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, AttributeOptionInterface $attributeOption) { $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->getOptions()->willReturn([$attributeOption])->shouldBeCalled(3); $toProductValue->getOptions()->willReturn([$attributeOption]); $toProductValue->removeOption($attributeOption)->shouldBeCalled(); $toProductValue->addOption($attributeOption)->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($toProductValue); $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]); } }
/** * Test related methods */ public function testGuessUpdates() { $attribute = new Attribute(); $attribute->setCode('my_attribute'); $value = new ProductValue(); $value->setAttribute($attribute); $product = new Product(); $product->addValue($value); $guesser = new ProductValueUpdateGuesser(); $em = $this->getEntityManagerMock(); $updates = $guesser->guessUpdates($em, $value, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($product, $updates[0]); $attribute = new Attribute(); $attribute->setCode('my_price'); $price = new ProductPrice(); $value = new ProductValue(); $value->setAttribute($attribute); $value->addPrice($price); $product = new Product(); $product->addValue($value); $updates = $guesser->guessUpdates($em, $price, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($product, $updates[0]); }
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]); } }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $text = $productValue->getText(); $attribute = $productValue->getAttribute(); if (null !== $text) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_textarea', 'value' => $text); } }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $options = $productValue->getOptions(); /** @var \Pim\Bundle\CatalogBundle\Entity\Option $subValue */ foreach ($options->getValues() as $subValue) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_simpleselect', 'code' => $subValue->getCode()]; } }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $prices = $productValue->getPrices(); /** @var ProductPrice $price */ foreach ($prices as $price) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_price_collection', 'amount' => (double) $price->getData(), 'currency' => $price->getCurrency()]; } }
function let(ProductValue $value, MappingCollection $attributeMapping, AbstractAttribute $attribute) { $this->globalContext = ['identifier' => 'identifier', 'scopeCode' => 'scope_code', 'localeCode' => 'locale_code', 'onlyLocalized' => false, 'magentoAttributes' => ['attribute_code' => ['code' => 'attribute_ode', 'scope' => 'global']], 'magentoAttributesOptions' => [], 'currencyCode' => 'currency_code', 'attributeCodeMapping' => $attributeMapping]; $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code'); $value->getData()->willReturn('hello'); $value->getAttribute()->willReturn($attribute); $value->getScope()->willReturn('scope_code'); $attribute->getCode()->willReturn('attribute_code'); }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $text = $productValue->getText(); if (is_null($text)) { $text = $productValue->getVarchar(); } if (null !== $text) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_text', 'value' => $text); } }
/** * @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_sets_null_value_when_receiving_empty_string(AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, $builder, ProductValue $productValue) { $locale = 'fr_FR'; $scope = 'mobile'; $data = ''; $attribute->getCode()->willReturn('attributeCode'); $productValue->setData(null)->shouldBeCalled(); $builder->addProductValue($product2, $attribute, $locale, $scope)->willReturn($productValue); $product1->getValue('attributeCode', $locale, $scope)->shouldBeCalled()->willReturn($productValue); $this->setAttributeData($product1, $attribute, $data, ['locale' => $locale, 'scope' => $scope]); }
function it_sets_boolean_value_to_a_product_value(AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, $builder, ProductValue $productValue) { $locale = 'fr_FR'; $scope = 'mobile'; $data = true; $attribute->getCode()->willReturn('attributeCode'); $productValue->setData($data)->shouldBeCalled(); $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); $products = [$product1, $product2, $product3]; $this->setValue($products, $attribute, $data, $locale, $scope); }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $options = $productValue->getOptions(); if (is_array($options) && count($options) > 0) { /** @var \Pim\Bundle\CatalogBundle\Entity\AttributeOption $subValue */ foreach ($options->getValues() as $subValue) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_simpleselect', 'code' => $subValue->getCode()]; } } else { $option = $productValue->getOption(); if (is_object($option)) { $drupalProduct['values'][$field][$context['locale']][] = ['type' => 'pim_catalog_simpleselect', 'code' => $option->getCode()]; } } }
function it_sets_attribute_data_text_value_to_a_product_value(AttributeInterface $attribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, $builder, ProductValue $productValue) { $locale = 'fr_FR'; $scope = 'mobile'; $data = 'data'; $attribute->getCode()->willReturn('attributeCode'); $productValue->setData($data)->shouldBeCalled(); $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); $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]); }
/** * @param ProductValue $productValue * @param $attribute * @return string */ public function getSerializedData(ProductValue $productValue, $attribute) { /** @var ProductMedia $media */ $media = $productValue->getMedia(); /** @var MediaManager $mediaManager */ $mediaManager = $this->get('pim_catalog.manager.media'); /** @var ProductValue $productValue */ $info_media = new \stdClass(); $info_media->content = $mediaManager->getBase64($media); $info_media->created = $productValue->getAttribute()->getCreated()->getTimestamp(); $info_media->updated = $productValue->getAttribute()->getUpdated()->getTimestamp(); $info_media->filename = $media->getFilename(); $info_media->filepath = $media->getFilePath(); $info_media->originalFilename = $media->getOriginalFilename(); $info_media->mimeType = $media->getMimeType(); $info_media->size = filesize($media->getFilePath()); $data = json_encode($info_media); return $data; }
function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping) { $this->beConstructedWith('locale', 'currency'); $group->getAttributes()->willReturn([$attribute1, $attribute2]); //get attribute options $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]); $attribute1->getCode()->willReturn('attribute_1'); $attributeOption11->getAttribute()->willReturn($attribute1); $attributeOption11->getCode()->willReturn('attribute_1_option_1'); $productValueOption11->getData()->willReturn($attributeOption11); $attributeOption12->getAttribute()->willReturn($attribute1); $attributeOption12->getCode()->willReturn('attribute_1_option_2'); $productValueOption12->getData()->willReturn($attributeOption12); $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]); $attribute2->getCode()->willReturn('attribute_2'); $attributeOption21->getAttribute()->willReturn($attribute2); $attributeOption21->getCode()->willReturn('attribute_2_option_1'); $productValueOption21->getData()->willReturn($attributeOption21); $attributeOption22->getAttribute()->willReturn($attribute2); $attributeOption22->getCode()->willReturn('attribute_2_option_2'); $productValueOption22->getData()->willReturn($attributeOption22); //Get product prices $product1->getValue('price', 'locale')->willReturn($productValuePrice1); $product1->getIdentifier()->willReturn('product_1'); $productValuePrice1->getPrice('currency')->willReturn($productPrice1); $productPrice1->getData()->willReturn(5.0); $product2->getValue('price', 'locale')->willReturn($productValuePrice2); $product2->getIdentifier()->willReturn('product_2'); $productValuePrice2->getPrice('currency')->willReturn($productPrice2); $productPrice2->getData()->willReturn(15.0); $product3->getValue('price', 'locale')->willReturn($productValuePrice3); $product3->getIdentifier()->willReturn('product_3'); $productValuePrice3->getPrice('currency')->willReturn($productPrice3); $productPrice3->getData()->willReturn(10.0); $attributeMapping->getSource('attribute_1')->willReturn('attribute_1'); $attributeMapping->getSource('attribute_2')->willReturn('attribute_2'); $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1'); $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2'); }
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_copies_simple_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, AttributeOptionInterface $attributeOption) { $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($attributeOption); $toProductValue->setOption($attributeOption)->shouldBeCalledTimes(3); $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); $products = [$product1, $product2, $product3, $product4]; $this->copyValue($products, $fromAttribute, $toAttribute, $fromLocale, $toLocale, $fromScope, $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]); }
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); }
/** * @param array $drupalProduct * @param ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_identifier', 'value' => $productValue->getVarchar()); }
/** * constructor */ public function __construct() { parent::__construct(); $this->fabrics = new ArrayCollection(); $this->myNewField = rand(); }
function it_copies_media_value_to_a_product_value($attrValidatorHelper, $builder, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue) { $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(['originalFilename' => 'akeneo', 'filePath' => 'path/to/file']); $toProductValue->setData(['originalFilename' => 'akeneo', 'filePath' => 'path/to/file'])->shouldBeCalledTimes(3); $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); $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]); } }
/** * {@inheritDoc} */ public function isRemovable() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'isRemovable', array()); return parent::isRemovable(); }
/** * @param array $drupalProduct * @param \Pim\Bundle\CatalogBundle\Model\ProductValue $productValue * @param string $field * @param array $context */ public function normalize(array &$drupalProduct, $productValue, $field, array $context = array()) { $drupalProduct['values'][$field][$context['locale']][] = array('type' => 'pim_catalog_date', 'value' => $productValue->getDate() instanceof \DateTime ? $productValue->getDate()->format('c') : null); }