本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\GroupInterface::getProductTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP GroupInterface::getProductTemplate方法的具体用法?PHP GroupInterface::getProductTemplate怎么用?PHP GroupInterface::getProductTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\GroupInterface
的用法示例。
在下文中一共展示了GroupInterface::getProductTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: normalizeVariantGroupValues
/**
* Normalize the variant group values
*
* @param GroupInterface $group
* @param string $format
* @param array $context
*
* @return array
*/
protected function normalizeVariantGroupValues(GroupInterface $group, $format, array $context)
{
$valuesData = [];
if ($group->getType()->isVariant() && null !== $group->getProductTemplate()) {
$template = $group->getProductTemplate();
$valuesData = $template->getValuesData();
}
return $valuesData;
}
示例2: normalizeVariantGroupValues
/**
* {@inheritdoc}
*/
protected function normalizeVariantGroupValues(GroupInterface $group, $format, array $context)
{
if (!$group->getType()->isVariant() || null === $group->getProductTemplate()) {
return [];
}
$valuesData = $group->getProductTemplate()->getValuesData();
$values = $this->valuesDenormalizer->denormalize($valuesData, 'ProductValue[]', 'json');
$normalizedValues = [];
foreach ($values as $value) {
$normalizedValues = array_replace($normalizedValues, $this->serializer->normalize($value, $format, ['entity' => 'product'] + $context));
}
ksort($normalizedValues);
return $normalizedValues;
}
示例3: ProductValue
function it_updates_a_variant_group($attributeRepository, $groupTypeRepository, $productBuilder, GroupInterface $variantGroup, AttributeInterface $attribute, GroupTypeInterface $type, GroupTranslation $translatable, ProductInterface $product, ProductTemplateInterface $productTemplate)
{
$groupTypeRepository->findOneByIdentifier('VARIANT')->willReturn($type);
$attributeRepository->findOneByIdentifier('main_color')->willReturn($attribute);
$attributeRepository->findOneByIdentifier('secondary_color')->willReturn($attribute);
$variantGroup->getTranslation()->willReturn($translatable);
$translatable->setLabel('T-shirt super beau')->shouldBeCalled();
$variantGroup->setCode('mycode')->shouldBeCalled();
$variantGroup->setLocale('fr_FR')->shouldBeCalled();
$variantGroup->setType($type)->shouldBeCalled();
$variantGroup->getId()->willReturn(null);
$variantGroup->addAxisAttribute(Argument::any())->shouldBeCalled();
$productTemplate->getValuesData()->willReturn([]);
$productTemplate->setValues(Argument::any())->shouldBeCalled();
$productTemplate->setValuesData(['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]])->shouldBeCalled();
$variantGroup->getProductTemplate()->willReturn($productTemplate);
$variantGroup->setProductTemplate($productTemplate)->shouldBeCalled();
$productValue = new ProductValue();
$identifierValue = new ProductValue();
$productBuilder->createProduct()->willReturn($product);
$product->getValues()->willReturn(new ArrayCollection([$productValue, $identifierValue]));
$product->getIdentifier()->willReturn($identifierValue);
$values = ['code' => 'mycode', 'axis' => ['main_color', 'secondary_color'], 'type' => 'VARIANT', 'labels' => ['fr_FR' => 'T-shirt super beau'], 'values' => ['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]]];
$this->update($variantGroup, $values, []);
}
示例4: perform
/**
* {@inheritdoc}
*/
public function perform()
{
parent::perform();
if (null !== $this->group->getProductTemplate()) {
$this->templateUpdater->update($this->group->getProductTemplate(), $this->objects);
}
}
示例5:
function it_handles_media_values_of_variant_group_product_templates($templateMediaManager, GroupInterface $group, GroupType $type, ProductTemplateInterface $template)
{
$group->getType()->willReturn($type);
$group->getCode()->willReturn('my_code');
$type->isVariant()->willReturn(true);
$group->getProductTemplate()->willReturn($template);
$templateMediaManager->handleProductTemplateMedia($template)->shouldBeCalled();
$this->save($group);
}
示例6: FileNotFoundException
function it_throws_an_exception_if_media_of_variant_group_is_not_found($normalizer, $denormalizer, ArrayCollection $productValuesCollection, ArrayCollection $mediaCollection, ProductMediaInterface $media, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ProductValueInterface $productValue)
{
$variantGroup->getProductTemplate()->willReturn($productTemplate);
$variantGroup->getCode()->willReturn('my_variant_group');
$productTemplate->getValuesData()->willReturn([$productValue]);
$denormalizer->denormalize([$productValue], 'ProductValue[]', 'json')->willReturn($productValuesCollection);
$productValuesCollection->filter(Argument::cetera())->willReturn($mediaCollection);
$mediaCollection->toArray()->willReturn([$media]);
$normalizer->normalize([$media], 'csv', ['field_name' => 'media', 'prepare_copy' => true, 'identifier' => 'my_variant_group'])->willThrow(new FileNotFoundException('upload/path/img.jpg'));
$this->shouldThrow(new InvalidItemException('The file "upload/path/img.jpg" does not exist', ['item' => 'my_variant_group', 'uploadDirectory' => 'upload/path/']))->duringProcess($variantGroup);
}
示例7:
function it_handles_media_values_of_variant_group_product_templates($templateMediaManager, $eventDispatcher, GroupInterface $group, GroupType $type, ProductTemplateInterface $template)
{
$group->getType()->willReturn($type);
$group->getCode()->willReturn('my_code');
$type->isVariant()->willReturn(true);
$group->getProductTemplate()->willReturn($template);
$templateMediaManager->handleProductTemplateMedia($template)->shouldBeCalled();
$eventDispatcher->dispatch(StorageEvents::PRE_SAVE, Argument::cetera())->shouldBeCalled();
$eventDispatcher->dispatch(StorageEvents::POST_SAVE, Argument::cetera())->shouldBeCalled();
$this->save($group);
}
示例8:
function it_returns_non_eligible_attributes($attributeRepository, GroupInterface $group, ProductTemplateInterface $template, AttributeInterface $length, AttributeInterface $name, AttributeInterface $color, AttributeInterface $identifier, Collection $collection)
{
$group->getProductTemplate()->willReturn($template);
$group->getAxisAttributes()->willReturn($collection);
$collection->toArray()->willReturn([$length]);
$template->getValuesData()->willReturn(['name' => 'foo', 'color' => 'bar']);
$attributeRepository->findOneByIdentifier('name')->willReturn($name);
$attributeRepository->findOneByIdentifier('color')->willReturn($color);
$attributeRepository->findBy(['unique' => true])->willReturn([$name, $identifier]);
$attributes = [$length, $name, $color, $identifier];
$this->getNonEligibleAttributes($group)->shouldReturn($attributes);
}
示例9: prepareVariantGroupMedia
/**
* Prepares media files present in the product template of the variant group for export.
* Returns an array of files to be copied from 'filePath' to 'exportPath'.
*
* @param GroupInterface $group
*
* @throws InvalidItemException If a media file is not found
*
* @return array
*/
protected function prepareVariantGroupMedia(GroupInterface $group)
{
$mediaValues = $this->getProductTemplateMediaValues($group->getProductTemplate());
if (count($mediaValues) < 1) {
return [];
}
try {
return $this->normalizer->normalize($mediaValues, $this->format, ['field_name' => 'media', 'prepare_copy' => true, 'identifier' => $group->getCode()]);
} catch (FileNotFoundException $e) {
throw new InvalidItemException($e->getMessage(), ['item' => $group->getCode(), 'uploadDirectory' => $this->uploadDirectory]);
}
}
示例10: validateProductTemplateValues
/**
* Validate variant group product template values
*
* @param GroupInterface $variantGroup
* @param Constraint $constraint
*/
protected function validateProductTemplateValues(GroupInterface $variantGroup, Constraint $constraint)
{
$template = $variantGroup->getProductTemplate();
$valuesData = $template->getValuesData();
$forbiddenAttrCodes = $this->attributeRepository->findUniqueAttributeCodes();
foreach ($variantGroup->getAxisAttributes() as $axisAttribute) {
$forbiddenAttrCodes[] = $axisAttribute->getCode();
}
$invalidAttrCodes = array_intersect($forbiddenAttrCodes, array_keys($valuesData));
if (count($invalidAttrCodes) > 0) {
$this->context->addViolation($constraint->message, array('%group%' => $variantGroup->getCode(), '%attributes%' => $this->formatValues($invalidAttrCodes)));
}
}
示例11:
function it_does_not_copy_values_to_products_when_template_is_empty(GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, Collection $productCollection, ProductInterface $productOne, ProductInterface $productTwo, $productTplApplier, $stepExecution)
{
$variantGroup->getId()->willReturn(42);
$stepExecution->incrementSummaryInfo('update')->shouldBeCalled();
$variantGroup->getProductTemplate()->willReturn($productTemplate);
$productTemplate->getValuesData()->willReturn([]);
$variantGroup->getProducts()->willReturn($productCollection);
$productCollection->isEmpty()->willReturn(false);
$productCollection->toArray()->willReturn([$productOne, $productTwo]);
$productCollection->count()->willReturn(2);
$productTplApplier->apply($productTemplate, [$productOne, $productTwo])->shouldNotBeCalled();
$this->write([$variantGroup]);
}
示例12: getNonEligibleAttributes
/**
* Get non eligible attributes to a product template
*
* @param GroupInterface $group
*
* @return AttributeInterface[]
*/
public function getNonEligibleAttributes(GroupInterface $variantGroup)
{
$attributes = $variantGroup->getAxisAttributes()->toArray();
$template = $variantGroup->getProductTemplate();
if (null !== $template) {
foreach (array_keys($template->getValuesData()) as $attributeCode) {
$attributes[] = $this->attributeRepository->findOneByIdentifier($attributeCode);
}
}
$uniqueAttributes = $this->attributeRepository->findBy(['unique' => true]);
foreach ($uniqueAttributes as $attribute) {
if (!in_array($attribute, $attributes)) {
$attributes[] = $attribute;
}
}
return $attributes;
}
示例13:
function it_adds_a_violation_if_variant_group_template_contains_a_unique_attribute(GroupInterface $variantGroup, GroupType $type, ProductTemplateInterface $template, VariantGroupValues $constraint, $attributeRepository, $context)
{
$variantGroup->getType()->willReturn($type);
$variantGroup->getCode()->willReturn('tshirt');
$type->isVariant()->willReturn(true);
$variantGroup->getProductTemplate()->willReturn($template);
$variantGroup->getAxisAttributes()->willReturn([]);
$attributeRepository->findUniqueAttributeCodes()->willReturn(['sku', 'barcode']);
$template->getValuesData()->willReturn(['sku' => 'SKU-001']);
$violationData = ['%group%' => 'tshirt', '%attributes%' => '"sku"'];
$context->addViolation($constraint->message, $violationData)->shouldBeCalled();
$this->validate($variantGroup, $constraint);
$template->getValuesData()->willReturn(['sku' => 'SKU-001', 'barcode' => 01122334455]);
$violationData = ['%group%' => 'tshirt', '%attributes%' => '"sku", "barcode"'];
$context->addViolation($constraint->message, $violationData)->shouldBeCalled();
$this->validate($variantGroup, $constraint);
}
示例14: getProductTemplate
/**
* @param GroupInterface $variantGroup
*
* @return ProductTemplateInterface
*/
protected function getProductTemplate(GroupInterface $variantGroup)
{
if ($variantGroup->getProductTemplate()) {
$template = $variantGroup->getProductTemplate();
} else {
$template = new $this->productTemplateClass();
}
return $template;
}
示例15:
function it_has_attribute_in_a_variant_group_template(AttributeInterface $attribute, GroupInterface $group, GroupTypeInterface $groupType, ArrayCollection $groupAttributes, ProductTemplateInterface $template)
{
$groupType->isVariant()->willReturn(true);
$groupAttributes->contains($attribute)->willReturn(false);
$template->hasValueForAttribute($attribute)->shouldBeCalled()->willReturn(true);
$group->getType()->willReturn($groupType);
$group->getProductTemplate()->willReturn($template);
$group->getAxisAttributes()->willReturn($groupAttributes);
$group->addProduct($this)->willReturn($this);
$this->addGroup($group);
$this->hasAttributeInVariantGroup($attribute)->shouldReturn(true);
}