/** * {@inheritDoc} */ public function setAssociationType(\Pim\Bundle\CatalogBundle\Model\AssociationTypeInterface $associationType) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAssociationType', array($associationType)); return parent::setAssociationType($associationType); }
/** * @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]); }
/** * @param ProductInterface $product */ public function ensureAllAssociationTypes(ProductInterface $product) { $missingAssocTypes = $this->assocTypeRepository->findMissingAssociationTypes($product); if (!empty($missingAssocTypes)) { foreach ($missingAssocTypes as $associationType) { $association = new Association(); $association->setAssociationType($associationType); $product->addAssociation($association); } } }