function it_adds_missing_product_values_from_family_on_new_product($valuesResolver, FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, ProductValueInterface $skuValue) { $sku->getCode()->willReturn('sku'); $sku->getAttributeType()->willReturn('pim_catalog_identifier'); $sku->isLocalizable()->willReturn(false); $sku->isScopable()->willReturn(false); $name->getCode()->willReturn('name'); $name->getAttributeType()->willReturn('pim_catalog_text'); $name->isLocalizable()->willReturn(true); $name->isScopable()->willReturn(false); $desc->getCode()->willReturn('description'); $desc->getAttributeType()->willReturn('pim_catalog_text'); $desc->isLocalizable()->willReturn(true); $desc->isScopable()->willReturn(true); // get expected attributes $product->getAttributes()->willReturn([$sku]); $family->getAttributes()->willReturn([$sku, $name, $desc]); $product->getFamily()->willReturn($family); // get eligible values $valuesResolver->resolveEligibleValues(['sku' => $sku, 'name' => $name, 'description' => $desc])->willReturn([['attribute' => 'sku', 'type' => 'pim_catalog_identifier', 'locale' => null, 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => null], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'print'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'print']]); // get existing values $skuValue->getAttribute()->willReturn($sku); $skuValue->getLocale()->willReturn(null); $skuValue->getScope()->willReturn(null); $product->getValues()->willReturn([$skuValue]); // add 6 new values : 4 desc (locales x scopes) + 2 name (locales $product->addValue(Argument::any())->shouldBeCalledTimes(6); $this->addMissingProductValues($product); }
function it_renders_a_product_with_an_image($templating, ProductInterface $blender, AttributeGroupInterface $media, AttributeInterface $mainImage) { $path = realpath(__DIR__ . '/../../../../../features/Context/fixtures/'); $blender->getAttributes()->willReturn([$mainImage]); $mainImage->getGroup()->willReturn($media); $media->getLabel()->willReturn('Media'); $mainImage->getCode()->willReturn('main_image'); $mainImage->getAttributeType()->willReturn('pim_catalog_image'); $templating->render(self::TEMPLATE_NAME, ['product' => $blender, 'locale' => 'en_US', 'scope' => 'ecommerce', 'groupedAttributes' => ['Media' => ['main_image' => $mainImage]], 'imageAttributes' => ['main_image' => $mainImage], 'uploadDir' => $path . DIRECTORY_SEPARATOR, 'customFont' => null])->shouldBeCalled(); $this->render($blender, 'pdf', ['locale' => 'en_US', 'scope' => 'ecommerce']); }
function it_renders_a_product_with_an_image($templating, ProductInterface $blender, AttributeGroupInterface $media, AttributeInterface $mainImage, ProductValueInterface $productValue, FileInfoInterface $fileInfo, CacheManager $cacheManager) { $path = realpath(__DIR__ . '/../../../../../features/Context/fixtures/'); $blender->getAttributes()->willReturn([$mainImage]); $blender->getValue("main_image", "en_US", "ecommerce")->willReturn($productValue); $productValue->getMedia()->willReturn($fileInfo); $fileInfo->getKey()->willReturn('fookey'); $cacheManager->isStored('fookey', 'thumbnail')->willReturn(true); $mainImage->getGroup()->willReturn($media); $media->getLabel()->willReturn('Media'); $mainImage->getCode()->willReturn('main_image'); $mainImage->getAttributeType()->willReturn('pim_catalog_image'); $templating->render(self::TEMPLATE_NAME, ['product' => $blender, 'locale' => 'en_US', 'scope' => 'ecommerce', 'groupedAttributes' => ['Media' => ['main_image' => $mainImage]], 'imageAttributes' => ['main_image' => $mainImage], 'uploadDir' => $path . DIRECTORY_SEPARATOR, 'customFont' => null])->shouldBeCalled(); $this->render($blender, 'pdf', ['locale' => 'en_US', 'scope' => 'ecommerce']); }
function it_adds_missing_product_values_from_family_on_new_product(FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, $localeRepository, LocaleInterface $fr, LocaleInterface $en, $channelRepository, ChannelInterface $ecom, ChannelInterface $print, ProductValueInterface $skuValue) { // get expected attributes $product->getAttributes()->willReturn([$sku]); $product->getFamily()->willReturn($family); $family->getAttributes()->willReturn([$sku, $name, $desc]); // get expected values $sku->getCode()->willReturn('sku'); $sku->getAttributeType()->willReturn('pim_catalog_identifier'); $sku->isLocalizable()->willReturn(false); $sku->isScopable()->willReturn(false); $sku->isLocaleSpecific()->willReturn(false); $name->getCode()->willReturn('name'); $name->getAttributeType()->willReturn('pim_catalog_text'); $name->isLocalizable()->willReturn(true); $name->isScopable()->willReturn(false); $name->isLocaleSpecific()->willReturn(false); $desc->getCode()->willReturn('desc'); $desc->getAttributeType()->willReturn('pim_catalog_text'); $desc->isLocalizable()->willReturn(true); $desc->isScopable()->willReturn(true); $desc->isLocaleSpecific()->willReturn(false); $fr->getCode()->willReturn('fr_FR'); $en->getCode()->willReturn('fr_FR'); $localeRepository->getActivatedLocales()->willReturn([$fr, $en]); $ecom->getCode()->willReturn('ecom'); $ecom->getLocales()->willReturn([$en, $fr]); $print->getCode()->willReturn('print'); $print->getLocales()->willReturn([$en, $fr]); $channelRepository->findAll()->willReturn([$ecom, $print]); // get existing values $skuValue->getAttribute()->willReturn($sku); $skuValue->getLocale()->willReturn(null); $skuValue->getScope()->willReturn(null); $product->getValues()->willReturn([$skuValue]); // add 6 new values : 4 desc (locales x scopes) + 2 name (locales $product->addValue(Argument::any())->shouldBeCalledTimes(6); $this->addMissingProductValues($product); }
/** * Get attributes to display * * @param ProductInterface $product * @param string $locale * * @return AttributeInterface[] */ protected function getAttributes(ProductInterface $product, $locale) { return $product->getAttributes(); }
/** * Get expected attributes for the product * * @param ProductInterface $product * * @return AttributeInterface[] */ protected function getExpectedAttributes(ProductInterface $product) { $attributes = []; $productAttributes = $product->getAttributes(); foreach ($productAttributes as $attribute) { $attributes[$attribute->getCode()] = $attribute; } if ($family = $product->getFamily()) { foreach ($family->getAttributes() as $attribute) { $attributes[$attribute->getCode()] = $attribute; } } return $attributes; }
/** * Get the product edit template parameters * * @param FormInterface $form * @param ProductInterface $product * @param array $channels * @param array $trees * * @return array */ protected function getProductEditTemplateParams(FormInterface $form, ProductInterface $product, array $channels, array $trees) { $defaultParameters = array('form' => $form->createView(), 'dataLocale' => $this->getDataLocaleCode(), 'comparisonLocale' => $this->getComparisonLocale(), 'channels' => $channels, 'attributesForm' => $this->getAvailableAttributesForm($product->getAttributes())->createView(), 'product' => $product, 'trees' => $trees, 'created' => $this->versionManager->getOldestLogEntry($product), 'updated' => $this->versionManager->getNewestLogEntry($product), 'locales' => $this->getUserLocales(), 'createPopin' => $this->getRequest()->get('create_popin')); $event = new GenericEvent($this, ['parameters' => $defaultParameters]); $this->dispatch(ProductEvents::PRE_RENDER_EDIT, $event); return $event->getArgument('parameters'); }