當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ProductInterface::addGroup方法代碼示例

本文整理匯總了PHP中Pim\Component\Catalog\Model\ProductInterface::addGroup方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProductInterface::addGroup方法的具體用法?PHP ProductInterface::addGroup怎麽用?PHP ProductInterface::addGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pim\Component\Catalog\Model\ProductInterface的用法示例。


在下文中一共展示了ProductInterface::addGroup方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1:

 function it_adds_groups_field($groupRepository, ProductInterface $product, GroupInterface $pack, GroupInterface $cross, GroupInterface $up, GroupTypeInterface $nonVariantType)
 {
     $groupRepository->findOneByIdentifier('pack')->willReturn($pack);
     $groupRepository->findOneByIdentifier('cross')->willReturn($cross);
     $pack->getType()->willReturn($nonVariantType);
     $nonVariantType->isVariant()->willReturn(false);
     $cross->getType()->willReturn($nonVariantType);
     $nonVariantType->isVariant()->willReturn(false);
     $product->addGroup($pack)->shouldBeCalled();
     $product->addGroup($cross)->shouldBeCalled();
     $this->addFieldData($product, 'groups', ['pack', 'cross']);
 }
開發者ID:a2xchip,項目名稱:pim-community-dev,代碼行數:12,代碼來源:GroupFieldAdderSpec.php

示例2:

 function it_sets_variant_group_field($groupRepository, ProductInterface $product, GroupInterface $shirt, GroupInterface $cross, GroupInterface $up, GroupTypeInterface $variantType, GroupTypeInterface $nonVariantType)
 {
     $groupRepository->findOneByIdentifier('shirt')->willReturn($shirt);
     $shirt->getType()->willReturn($variantType);
     $variantType->isVariant()->willReturn(true);
     $product->getGroups()->willReturn([$up, $cross]);
     $up->getType()->willReturn($nonVariantType);
     $nonVariantType->isVariant()->willReturn(false);
     $cross->getType()->willReturn($variantType);
     $variantType->isVariant()->willReturn(true);
     $product->removeGroup($cross)->shouldBeCalled();
     $product->addGroup($shirt)->shouldBeCalled();
     $this->setFieldData($product, 'variant_group', 'shirt');
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:14,代碼來源:VariantGroupFieldSetterSpec.php

示例3: addFieldData

 /**
  * {@inheritdoc}
  *
  * Expected data input format : ["group_code"]
  */
 public function addFieldData(ProductInterface $product, $field, $data, array $options = [])
 {
     $this->checkData($field, $data);
     $groups = [];
     foreach ($data as $groupCode) {
         $group = $this->groupRepository->findOneByIdentifier($groupCode);
         if (null === $group) {
             throw InvalidArgumentException::expected($field, 'existing group code', 'adder', 'groups', $groupCode);
         } elseif ($group->getType()->isVariant()) {
             throw InvalidArgumentException::expected($field, 'non variant group code', 'adder', 'groups', $groupCode);
         } else {
             $groups[] = $group;
         }
     }
     foreach ($groups as $group) {
         $product->addGroup($group);
     }
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:23,代碼來源:GroupFieldAdder.php

示例4: setFieldData

 /**
  * {@inheritdoc}
  *
  * Expected data input format : ["group_code"]
  */
 public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
 {
     $this->checkData($field, $data);
     $groups = [];
     foreach ($data as $groupCode) {
         $group = $this->groupRepository->findOneByIdentifier($groupCode);
         if (null === $group) {
             throw InvalidArgumentException::expected($field, 'existing group code', 'setter', 'groups', $groupCode);
         } else {
             $groups[] = $group;
         }
     }
     $oldGroups = $product->getGroups();
     foreach ($oldGroups as $group) {
         $product->removeGroup($group);
     }
     foreach ($groups as $group) {
         $product->addGroup($group);
     }
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:25,代碼來源:GroupFieldSetter.php

示例5: setFieldData

 /**
  * {@inheritdoc}
  *
  * Expected data input format : "variant_group_code"
  */
 public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
 {
     $this->checkData($field, $data);
     if (null !== $data) {
         $variantGroup = $this->groupRepository->findOneByIdentifier($data);
         if (null === $variantGroup) {
             throw InvalidArgumentException::expected($field, 'existing variant group code', 'setter', 'variant_group', $data);
         }
         if (!$variantGroup->getType()->isVariant()) {
             throw InvalidArgumentException::expected($field, 'variant group code', 'setter', 'variant_group', $data);
         }
     }
     $existingGroups = $product->getGroups();
     foreach ($existingGroups as $group) {
         if ($group->getType()->isVariant()) {
             $product->removeGroup($group);
         }
     }
     if (null !== $data) {
         $product->addGroup($variantGroup);
     }
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:27,代碼來源:VariantGroupFieldSetter.php

示例6: denormalizeGroups

 /**
  * Denormalize product groups
  *
  * @param string           $data
  * @param string           $format
  * @param array            $context
  * @param ProductInterface $product
  */
 protected function denormalizeGroups($data, $format, array $context, ProductInterface $product)
 {
     foreach ($product->getGroups() as $group) {
         $product->removeGroup($group);
     }
     $groupCodes = strlen($data) > 0 ? explode(",", $data) : [];
     foreach ($groupCodes as $groupCode) {
         $product->addGroup($this->serializer->denormalize($groupCode, $this->groupClass, $format, $context));
     }
 }
開發者ID:a2xchip,項目名稱:pim-community-dev,代碼行數:18,代碼來源:ProductDenormalizer.php


注:本文中的Pim\Component\Catalog\Model\ProductInterface::addGroup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。