本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\GroupInterface::getAxisAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP GroupInterface::getAxisAttributes方法的具体用法?PHP GroupInterface::getAxisAttributes怎么用?PHP GroupInterface::getAxisAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\GroupInterface
的用法示例。
在下文中一共展示了GroupInterface::getAxisAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: normalizeAxisAttributes
/**
* Normalize the attributes
*
* @param GroupInterface $group
*
* @return array
*/
protected function normalizeAxisAttributes(GroupInterface $group)
{
$attributes = array();
foreach ($group->getAxisAttributes() as $attribute) {
$attributes[] = $attribute->getCode();
}
sort($attributes);
return $attributes;
}
示例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: 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, []]);
}
示例4: 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;
}
示例5:
function it_adds_a_violation_if_a_group_contains_axis_attributes($context, GroupInterface $group, GroupType $type, VariantGroupAxis $constraint, AttributeInterface $axis)
{
$group->getId()->willReturn(null);
$group->getType()->willReturn($type);
$group->getCode()->willReturn('xsell');
$type->isVariant()->willReturn(false);
$group->getAxisAttributes()->willReturn([$axis]);
$violationData = ['%group%' => 'xsell'];
$context->addViolation($constraint->unexpectedAxisMessage, $violationData)->shouldBeCalled();
$this->validate($group, $constraint);
}
示例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->addViolation($constraint->message, array('%group%' => $variantGroup->getCode(), '%attributes%' => $this->formatValues($invalidAttrCodes)));
}
}
示例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:
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);
}
示例11: 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;
}
示例12: setAxes
/**
* @param GroupInterface $variantGroup
* @param array $axes
*
* @throws \InvalidArgumentException
*/
protected function setAxes(GroupInterface $variantGroup, array $axes)
{
if (null !== $variantGroup->getId()) {
if (array_diff($this->getOriginalAxes($variantGroup->getAxisAttributes()), array_values($axes))) {
throw new \InvalidArgumentException('Attributes: This property cannot be changed.');
}
}
foreach ($axes as $axis) {
$attribute = $this->attributeRepository->findOneByIdentifier($axis);
if (null !== $attribute) {
$variantGroup->addAxisAttribute($attribute);
} else {
throw new \InvalidArgumentException(sprintf('Attribute "%s" does not exist', $axis));
}
}
}
示例13: getAxisAttributeCodes
/**
* @param GroupInterface $variantGroup
*
* @return array
*/
protected function getAxisAttributeCodes($variantGroup)
{
$axisAttributes = $variantGroup->getAxisAttributes();
$axisAttributeCodes = [];
foreach ($axisAttributes as $axisAttribute) {
$axisAttributeCodes[] = $axisAttribute->getCode();
}
return $axisAttributeCodes;
}
示例14: prepareQueryCriterias
/**
* Prepare query criteria for variant group
*
* @param GroupInterface $variantGroup
* @param ProductInterface $product
* @param Constraint $constraint
*
* @return array
*/
protected function prepareQueryCriterias(GroupInterface $variantGroup, ProductInterface $product, Constraint $constraint)
{
$criteria = array();
foreach ($variantGroup->getAxisAttributes() as $attribute) {
$value = $product->getValue($attribute->getCode());
// we don't add criteria when option is null, as this check is performed by HasVariantAxesValidator
if (null !== $value && null !== $value->getOption()) {
$criteria[] = ['attribute' => $attribute, 'option' => $value->getOption()];
} else {
$this->addEmptyAxisViolation($constraint, $variantGroup->getLabel(), $product->getIdentifier()->getVarchar(), $attribute->getCode());
}
}
return $criteria;
}
示例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);
}