当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductInterface::removeCategory方法代码示例

本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface::removeCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::removeCategory方法的具体用法?PHP ProductInterface::removeCategory怎么用?PHP ProductInterface::removeCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pim\Component\Catalog\Model\ProductInterface的用法示例。


在下文中一共展示了ProductInterface::removeCategory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 function it_removes_categories_to_a_product($categoryRepository, CategoryInterface $bookCategory, CategoryInterface $penCategory, CategoryInterface $bluePenCategory, ProductInterface $bookProduct, ProductInterface $bluePenProduct)
 {
     $categoryRepository->findOneByIdentifier('book_category')->willReturn($bookCategory);
     $bookProduct->removeCategory($bookCategory)->shouldBeCalled();
     $categoryRepository->findOneByIdentifier('pen_category')->willReturn($penCategory);
     $categoryRepository->findOneByIdentifier('blue_pen_category')->willReturn($bluePenCategory);
     $bluePenProduct->removeCategory($penCategory)->shouldBeCalled();
     $bluePenProduct->removeCategory($bluePenCategory)->shouldBeCalled();
     $this->removeFieldData($bookProduct, 'categories', ['book_category']);
     $this->removeFieldData($bluePenProduct, 'categories', ['pen_category', 'blue_pen_category']);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:11,代码来源:CategoryFieldRemoverSpec.php

示例2:

 function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
 {
     $saver->saveAll([$product])->shouldBeCalled();
     $event->getSubject()->willReturn($object);
     $object->getProducts()->willReturn([$product]);
     $product->removeCategory($object)->shouldBeCalled();
     $this->postRemove($event)->shouldReturn(null);
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:8,代码来源:ProductCategorySubscriberSpec.php

示例3:

 function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
 {
     $saver->saveAll([$product], ['flush' => 'expected_flush_value', 'recalculate' => false, 'schedule' => false])->shouldBeCalled();
     $event->getSubject()->willReturn($object);
     $event->getArgument('flush')->willReturn('expected_flush_value');
     $object->getProducts()->willReturn([$product]);
     $product->removeCategory($object)->shouldBeCalled();
     $this->postRemove($event)->shouldReturn(null);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:9,代码来源:ProductCategorySubscriberSpec.php

示例4:

 function it_sets_category_field($categoryRepository, ProductInterface $product, CategoryInterface $mug, CategoryInterface $shirt, CategoryInterface $men)
 {
     $categoryRepository->findOneByIdentifier('mug')->willReturn($mug);
     $categoryRepository->findOneByIdentifier('shirt')->willReturn($shirt);
     $product->getCategories()->willReturn([$men]);
     $product->removeCategory($men)->shouldBeCalled();
     $product->addCategory($mug)->shouldBeCalled();
     $product->addCategory($shirt)->shouldBeCalled();
     $this->setFieldData($product, 'categories', ['mug', 'shirt']);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:10,代码来源:CategoryFieldSetterSpec.php

示例5: removeFieldData

 /**
  * {@inheritdoc}
  *
  * Expected data input format : ["category_code", "another_category_code"]
  */
 public function removeFieldData(ProductInterface $product, $field, $data, array $options = [])
 {
     $this->checkData($field, $data);
     $categories = [];
     foreach ($data as $categoryCode) {
         $category = $this->categoryRepository->findOneByIdentifier($categoryCode);
         if (null === $category) {
             throw InvalidArgumentException::expected($field, 'existing category code', 'remover', 'category', $categoryCode);
         }
         $categories[] = $category;
     }
     foreach ($categories as $categoryToRemove) {
         $product->removeCategory($categoryToRemove);
     }
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:20,代码来源:CategoryFieldRemover.php

示例6: setFieldData

 /**
  * {@inheritdoc}
  *
  * Expected data input format : ["category_code"]
  */
 public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
 {
     $this->checkData($field, $data);
     $categories = [];
     foreach ($data as $categoryCode) {
         $category = $this->getCategory($categoryCode);
         if (null === $category) {
             throw InvalidArgumentException::expected($field, 'existing category code', 'setter', 'category', $categoryCode);
         } else {
             $categories[] = $category;
         }
     }
     $oldCategories = $product->getCategories();
     foreach ($oldCategories as $category) {
         $product->removeCategory($category);
     }
     foreach ($categories as $category) {
         $product->addCategory($category);
     }
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:25,代码来源:CategoryFieldSetter.php

示例7: denormalizeCategories

 /**
  * Denormalize product categories
  *
  * @param string           $data
  * @param string           $format
  * @param array            $context
  * @param ProductInterface $product
  */
 protected function denormalizeCategories($data, $format, array $context, ProductInterface $product)
 {
     foreach ($product->getCategories() as $category) {
         $product->removeCategory($category);
     }
     $categoryCodes = strlen($data) > 0 ? explode(",", $data) : [];
     foreach ($categoryCodes as $categoryCode) {
         $product->addCategory($this->serializer->denormalize($categoryCode, $this->categoryClass, $format, $context));
     }
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:18,代码来源:ProductDenormalizer.php


注:本文中的Pim\Component\Catalog\Model\ProductInterface::removeCategory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。