本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\GroupInterface::getProducts方法的典型用法代码示例。如果您正苦于以下问题:PHP GroupInterface::getProducts方法的具体用法?PHP GroupInterface::getProducts怎么用?PHP GroupInterface::getProducts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\GroupInterface
的用法示例。
在下文中一共展示了GroupInterface::getProducts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateVariantGroup
/**
* Validate variant group
*
* @param GroupInterface $variantGroup
* @param Constraint $constraint
*/
protected function validateVariantGroup(GroupInterface $variantGroup, Constraint $constraint)
{
$existingCombinations = array();
$products = $variantGroup->getProducts();
if (null === $products) {
$products = $this->getMatchingProducts($variantGroup);
}
foreach ($products as $product) {
$values = array();
foreach ($variantGroup->getAxisAttributes() as $attribute) {
$code = $attribute->getCode();
$option = $product->getValue($code) ? (string) $product->getValue($code)->getOption() : null;
if (null === $option) {
$this->addEmptyAxisViolation($constraint, $variantGroup->getLabel(), $product->getIdentifier()->getVarchar(), $attribute->getCode());
}
$values[] = sprintf('%s: %s', $code, $option);
}
$combination = implode(', ', $values);
if (in_array($combination, $existingCombinations)) {
$this->addExistingCombinationViolation($constraint, $variantGroup->getLabel(), $combination);
} else {
$existingCombinations[] = $combination;
}
}
}
示例2:
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]);
}
示例3:
function it_adds_violation_when_validating_group_containing_products_with_non_unique_combination_of_axis_attributes($context, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, ProductInterface $redTShirtProduct, ProductInterface $redTShirtProduct2, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation)
{
$tShirtGroupType->isVariant()->willReturn(true);
$tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
$tShirtVariantGroup->getProducts()->willReturn([$redTShirtProduct, $redTShirtProduct2]);
$tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
$sizeAttribute->getCode()->willReturn('size');
$colorAttribute->getCode()->willReturn('color');
$sizeProductValue->getOption()->willReturn('XL');
$colorProductValue->getOption()->willReturn('Red');
$redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct->getValue('color')->willReturn($colorProductValue);
$redTShirtProduct2->getValue('size')->willReturn($sizeProductValue);
$redTShirtProduct2->getValue('color')->willReturn($colorProductValue);
$tShirtVariantGroup->getLabel()->willReturn('Groupe TShirt');
$context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'Groupe TShirt', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation);
$this->validate($tShirtVariantGroup, $uniqueVariantAxisConstraint);
}
示例4: copyValuesToProducts
/**
* Copy variant group values to products
*
* @param GroupInterface $variantGroup
*/
protected function copyValuesToProducts(GroupInterface $variantGroup)
{
$template = $variantGroup->getProductTemplate();
$products = $variantGroup->getProducts();
if ($template && count($template->getValuesData()) > 0 && count($products) > 0) {
$skippedMessages = $this->productTplApplier->apply($template, $products->toArray());
$nbSkipped = count($skippedMessages);
$nbUpdated = count($products) - $nbSkipped;
$this->incrementUpdatedProductsCount($nbUpdated);
if ($nbSkipped > 0) {
$this->incrementSkippedProductsCount($nbSkipped, $skippedMessages);
}
}
}
示例5: copyVariantGroupValues
/**
* Copy the variant group values on any products belonging in the variant group
*
* @param GroupInterface $group
*/
protected function copyVariantGroupValues(GroupInterface $group)
{
$template = $group->getProductTemplate();
$products = $group->getProducts()->toArray();
$this->productTplApplier->apply($template, $products);
}
示例6:
function it_marks_products_as_updated_when_a_group_is_removed_or_updated(EntityManager $em, ProductInterface $foo, ProductInterface $bar, GroupInterface $group)
{
$group->getProducts()->willReturn([$foo, $bar]);
$this->guessUpdates($em, $group, UpdateGuesserInterface::ACTION_UPDATE_ENTITY)->shouldReturn([$foo, $bar]);
$this->guessUpdates($em, $group, UpdateGuesserInterface::ACTION_DELETE)->shouldReturn([$foo, $bar]);
}