本文整理汇总了PHP中Pim\Component\Catalog\Model\GroupInterface::getAxisAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP GroupInterface::getAxisAttributes方法的具体用法?PHP GroupInterface::getAxisAttributes怎么用?PHP GroupInterface::getAxisAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\GroupInterface
的用法示例。
在下文中一共展示了GroupInterface::getAxisAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormOptionsForEdition
/**
* @param GroupInterface $group
*
* @return array
*/
protected function getFormOptionsForEdition(GroupInterface $group)
{
$axesIds = array_map(function (AttributeInterface $attribute) {
return $attribute->getId();
}, $group->getAxisAttributes()->toArray());
$options = ['data' => $group->getAxisAttributes(), 'disabled' => true, 'read_only' => true, 'query_builder' => function (AttributeRepositoryInterface $repository) use($axesIds) {
$qb = $repository->findAllAxesQB();
$qb->andWhere('a.id IN (:ids)');
$qb->setParameter('ids', $axesIds);
return $qb;
}];
return $options;
}
示例2: validateAttributeAxis
/**
* @param VariantGroupAxis $constraint
* @param GroupInterface $variantGroup
*/
protected function validateAttributeAxis(VariantGroupAxis $constraint, GroupInterface $variantGroup)
{
$allowedTypes = [AttributeTypes::OPTION_SIMPLE_SELECT, AttributeTypes::REFERENCE_DATA_SIMPLE_SELECT];
foreach ($variantGroup->getAxisAttributes() as $attribute) {
if (!in_array($attribute->getAttributeType(), $allowedTypes)) {
$this->addInvalidAxisViolation($constraint, $variantGroup->getCode(), $attribute->getCode());
}
}
}
示例3: normalizeAxisAttributes
/**
* Normalize the attributes
*
* @param GroupInterface $group
*
* @return array
*/
protected function normalizeAxisAttributes(GroupInterface $group)
{
$attributes = [];
foreach ($group->getAxisAttributes() as $attribute) {
$attributes[] = $attribute->getCode();
}
sort($attributes);
return $attributes;
}
示例4: Attribute
function it_throws_an_error_if_axis_is_updated(GroupInterface $variantGroup)
{
$variantGroup->setCode('mycode')->shouldBeCalled();
$variantGroup->getId()->willReturn(42);
$attribute = new Attribute();
$attribute->setCode('other');
$variantGroup->getAxisAttributes()->willReturn(new ArrayCollection([$attribute]));
$values = ['code' => 'mycode', 'axis' => ['main_color']];
$this->shouldThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.'))->during('update', [$variantGroup, $values, []]);
}
示例5: getMissingAxisCodes
/**
* Get missing axis codes of a product given a variant group
*
* @param ProductInterface $product
* @param GroupInterface $variantGroup
*
* @return array
*/
protected function getMissingAxisCodes(ProductInterface $product, GroupInterface $variantGroup)
{
$missingAxisCodes = [];
foreach ($variantGroup->getAxisAttributes() as $attribute) {
$value = $product->getValue($attribute->getCode());
if (null === $value || null === $value->getData()) {
$missingAxisCodes[] = $attribute->getCode();
}
}
return $missingAxisCodes;
}
示例6:
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);
}
示例7:
function it_adds_a_violation_if_axis_attributes_are_invalid($context, GroupInterface $variantGroup, GroupType $type, VariantGroupAxis $constraint, ConstraintViolationBuilderInterface $violation, AttributeInterface $invalidAxis)
{
$variantGroup->getId()->willReturn(12);
$variantGroup->getType()->willReturn($type);
$variantGroup->getCode()->willReturn('tshirt');
$type->isVariant()->willReturn(true);
$variantGroup->getAxisAttributes()->willReturn([$invalidAxis]);
$invalidAxis->getAttributeType()->willReturn(AttributeTypes::TEXT);
$invalidAxis->getCode()->willReturn('name');
$violationData = ['%group%' => 'tshirt', '%attribute%' => 'name'];
$context->buildViolation($constraint->invalidAxisMessage, $violationData)->shouldBeCalled()->willReturn($violation);
$this->validate($variantGroup, $constraint);
}
示例8: 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->buildViolation($constraint->message, ['%group%' => $variantGroup->getCode(), '%attributes%' => $this->formatValues($invalidAttrCodes)])->addViolation();
}
}
示例9:
function it_adds_a_violation_when_validates_a_product_with_missing_value_for_an_axe_of_its_variant_group($context, ProductInterface $product, GroupInterface $tShirtVariantGroup, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeValue, ProductValueInterface $identifierValue, HasVariantAxes $constraint, ConstraintViolationBuilderInterface $violation)
{
$tShirtVariantGroup->getCode()->willReturn('tshirt');
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$colorAttribute->getCode()->willReturn('color');
$product->getIdentifier()->willReturn($identifierValue);
$product->getVariantGroup()->willReturn($tShirtVariantGroup);
$product->getValue('size')->willReturn($sizeValue);
$product->getValue('color')->willReturn(null);
$sizeValue->getData()->willReturn('XL');
$context->buildViolation('The product "%product%" is in the variant group "%variant%" but it misses the following axes: %axes%.', ['%product%' => $identifierValue, '%variant%' => 'tshirt', '%axes%' => 'color'])->shouldBeCalled()->willReturn($violation);
$this->validate($product, $constraint);
}
示例10: ArrayCollection
function it_processes_variant_group_without_product_template($objectDetacher, $normalizer, $stepExecution, $variantGroupUpdater, $mediaFetcher, AttributeInterface $color, AttributeInterface $weight, GroupInterface $variantGroup, JobParameters $jobParameters)
{
$stepExecution->getJobParameters()->willReturn($jobParameters);
$jobParameters->has('with_media')->willReturn(true);
$jobParameters->get('with_media')->willReturn(false);
$variantGroup->getProductTemplate()->willReturn(null);
$variantGroup->getCode()->willReturn('my_variant_group');
$color->getCode()->willReturn('color');
$weight->getCode()->willReturn('weight');
$variantGroup->getAxisAttributes()->willReturn(new ArrayCollection([$color, $weight]));
$variantStandard = ['code' => 'my_variant_group', 'axis' => ['color', 'weight'], 'type' => 'variant', 'labels' => ['en_US' => 'My variant group', 'fr_FR' => 'Mon groupe de variante']];
$normalizer->normalize($variantGroup, null, ['with_variant_group_values' => true, 'identifier' => 'my_variant_group'])->willReturn($variantStandard);
$variantGroupUpdater->update($variantGroup, Argument::any())->shouldNotBeCalled();
$mediaFetcher->fetchAll(Argument::any())->shouldNotBeCalled();
$this->process($variantGroup)->shouldReturn($variantStandard);
$objectDetacher->detach($variantGroup)->shouldBeCalled();
}
示例11:
function it_adds_a_violation_if_variant_group_template_contains_a_unique_attribute(GroupInterface $variantGroup, GroupType $type, ProductTemplateInterface $template, VariantGroupValues $constraint, $attributeRepository, $context, ConstraintViolationBuilderInterface $violation)
{
$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->buildViolation($constraint->message, $violationData)->shouldBeCalled()->willReturn($violation);
$this->validate($variantGroup, $constraint);
$template->getValuesData()->willReturn(['sku' => 'SKU-001', 'barcode' => 01122334455]);
$violationData = ['%group%' => 'tshirt', '%attributes%' => '"sku", "barcode"'];
$context->buildViolation($constraint->message, $violationData)->shouldBeCalled()->willReturn($violation);
$this->validate($variantGroup, $constraint);
}
示例12: getNonEligibleAttributes
/**
* Get non eligible attributes to a product template
*
* @param GroupInterface $variantGroup
*
* @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_normalizes_a_variant_group_with_its_values($transNormalizer, $valuesDenormalizer, $valuesNormalizer, GroupInterface $group, GroupTypeInterface $groupType, AttributeInterface $attr, ProductTemplateInterface $productTemplate)
{
$groupType->getCode()->willReturn('VARIANT');
$groupType->isVariant()->willReturn(true);
$group->getCode()->willReturn('laser_sabers');
$valuesData = ['name' => 'Light saber model', 'size' => '120'];
$context = ['with_variant_group_values' => true];
$format = 'csv';
$productTemplate->getValuesData()->willReturn($valuesData);
$valuesDenormalizer->denormalize($valuesData, Argument::any(), Argument::any())->willReturn('denormalized_values');
$valuesNormalizer->normalize('denormalized_values', Argument::any(), Argument::any())->willReturn('normalized_values');
$group->getProductTemplate()->willReturn($productTemplate);
$group->getType()->willReturn($groupType);
$attr->getCode()->willReturn('light_color');
$group->getAxisAttributes()->willReturn([$attr]);
$transNormalizer->normalize($group, $format, $context)->willReturn([]);
$this->normalize($group, $format, $context)->shouldReturn(['code' => 'laser_sabers', 'type' => 'VARIANT', 'axis' => ['light_color'], 'values' => 'normalized_values']);
}
示例14:
function it_normalizes_a_variant_group_with_its_values_on_versioning_context($transNormalizer, $valuesDenormalizer, GroupInterface $group, CustomSerializer $serializer, GroupTypeInterface $groupType, AttributeInterface $attr, ProductTemplateInterface $productTemplate, ProductValueInterface $productValue1)
{
$groupType->getCode()->willReturn('VARIANT');
$groupType->isVariant()->willReturn(true);
$group->getCode()->willReturn('lego');
$valuesData = ['name' => 'Light saber model', 'size' => '120'];
$context = ['versioning' => true];
$format = 'csv';
$productTemplate->getValuesData()->willReturn($valuesData);
$valuesDenormalizer->denormalize($valuesData, 'ProductValue[]', 'json')->willReturn([$productValue1]);
$newContext = array_merge($context, ['with_variant_group_values' => true]);
$serializer->normalize($productValue1, $format, ['entity' => 'product'] + $newContext)->willReturn(['age' => '6+']);
$group->getProductTemplate()->willReturn($productTemplate);
$group->getType()->willReturn($groupType);
$attr->getCode()->willReturn('model');
$group->getAxisAttributes()->willReturn([$attr]);
$transNormalizer->normalize($group, $format, $context)->willReturn([]);
$this->setSerializer($serializer);
$this->normalize($group, $format, $context)->shouldReturn(['code' => 'lego', 'type' => 'VARIANT', 'axis' => 'model', 'age' => '6+']);
}
示例15:
function it_is_not_attribute_removable_with_group_containing_attribute(AttributeInterface $attribute, GroupInterface $group, GroupTypeInterface $groupType, ArrayCollection $groupAttributes)
{
$groupType->isVariant()->willReturn(true);
$groupAttributes->contains($attribute)->willReturn(true);
$group->getType()->willReturn($groupType);
$group->getAxisAttributes()->willReturn($groupAttributes);
$group->addProduct($this)->willReturn($this);
$this->addGroup($group);
$this->isAttributeRemovable($attribute)->shouldReturn(false);
}