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


PHP ProductInterface::getAssociationForTypeCode方法代码示例

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


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

示例1: addProductsAndGroupsToAssociations

 /**
  * Add products and groups to associations
  *
  * @param ProductInterface $product
  * @param mixed            $data
  */
 protected function addProductsAndGroupsToAssociations(ProductInterface $product, $data)
 {
     foreach ($data as $typeCode => $items) {
         $association = $product->getAssociationForTypeCode($typeCode);
         if (null === $association) {
             throw InvalidArgumentException::expected('associations', 'existing association type code', 'adder', 'association', $typeCode);
         }
         $this->addAssociatedProducts($association, $items['products']);
         $this->addAssociatedGroups($association, $items['groups']);
     }
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:17,代码来源:AssociationFieldAdder.php

示例2: theFollowingAssociationsForTheProduct

 /**
  * @Given /^the following associations for the (product "([^"]+)"):$/
  */
 public function theFollowingAssociationsForTheProduct(ProductInterface $owner, $id, TableNode $values)
 {
     $rows = $values->getHash();
     foreach ($rows as $row) {
         $association = $owner->getAssociationForTypeCode($row['type']);
         if (null === $association) {
             $associationType = $this->getContainer()->get('pim_catalog.repository.association_type')->findOneBy(['code' => $row['type']]);
             $association = new Association();
             $association->setAssociationType($associationType);
             $owner->addAssociation($association);
         }
         $association->addProduct($this->getProduct($row['product']));
     }
     $this->getProductSaver()->save($owner, ['recalculate' => false]);
 }
开发者ID:bengrol,项目名称:pim-community-dev,代码行数:18,代码来源:FixturesContext.php

示例3: hasGroupedProduct

 /**
  * Test if a product has grouped products.
  *
  * @param ProductInterface $product
  * @param string           $pimGrouped
  *
  * @return boolean
  */
 protected function hasGroupedProduct(ProductInterface $product, $pimGrouped)
 {
     $association = $product->getAssociationForTypeCode($pimGrouped);
     return null !== $association && count($association->getProducts()) > 0;
 }
开发者ID:mejdoubimeriem,项目名称:prestashopconnector,代码行数:13,代码来源:ProductNormalizer.php

示例4: denormalizeAssociations

 /**
  * Denormalize product associations
  *
  * @param string           &$data
  * @param string           $format
  * @param array            $context
  * @param ProductInterface $product
  *
  * @throws RevertException
  */
 protected function denormalizeAssociations(&$data, $format, array $context, ProductInterface $product)
 {
     foreach ($product->getAssociations() as $association) {
         foreach ($association->getGroups() as $group) {
             $association->removeGroup($group);
         }
         foreach ($association->getProducts() as $prod) {
             $association->removeProduct($prod);
         }
     }
     // Get association field names and add associations
     $assocFieldNames = $this->fieldNameBuilder->getAssociationFieldNames();
     foreach ($assocFieldNames as $assocFieldName) {
         if (isset($data[$assocFieldName])) {
             if (strlen($data[$assocFieldName]) > 0) {
                 list($associationTypeCode, $part) = explode('-', $assocFieldName);
                 $association = $product->getAssociationForTypeCode($associationTypeCode);
                 $association = $this->serializer->denormalize($data[$assocFieldName], $this->associationClass, $format, ['entity' => $association, 'association_type_code' => $associationTypeCode, 'part' => $part] + $context);
                 if (!$product->getAssociationForTypeCode($associationTypeCode)) {
                     $product->addAssociation($association);
                 }
             }
             unset($data[$assocFieldName]);
         }
     }
     foreach (array_keys($data) as $fieldName) {
         if (null !== ($matches = $this->fieldNameBuilder->extractAssociationFieldNameInfos($fieldName))) {
             throw new RevertException(sprintf('Association type "%s" does not exist anymore', $matches['assoc_type_code']));
         }
     }
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:41,代码来源:ProductDenormalizer.php


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