function it_transforms_product_associations_to_array(ProductAssociationInterface $productAssociation, ProductAssociationTypeInterface $productAssociationType, ProductInterface $firstAssociatedProduct, ProductInterface $secondAssociatedProduct) { $productAssociation->getType()->willReturn($productAssociationType); $productAssociation->getAssociatedProducts()->willReturn(new ArrayCollection([$firstAssociatedProduct->getWrappedObject(), $secondAssociatedProduct->getWrappedObject()])); $firstAssociatedProduct->getId()->willReturn(7); $secondAssociatedProduct->getId()->willReturn(21); $productAssociationType->getCode()->willReturn('accessories'); $this->transform([$productAssociation])->shouldReturn(['accessories' => '7,21']); }
function it_allows_to_remove_association(ProductAssociationInterface $association) { $association->setOwner($this)->shouldBeCalled(); $association->setOwner(null)->shouldBeCalled(); $this->addAssociation($association); $this->removeAssociation($association); $this->hasAssociation($association)->shouldReturn(false); }
/** * @param ProductAssociationInterface $productAssociation * @param string $productIds */ private function setAssociatedProductsByProductIds(ProductAssociationInterface $productAssociation, $productIds) { $products = $this->productRepository->findBy(['id' => explode(',', $productIds)]); $productAssociation->clearAssociatedProducts(); foreach ($products as $product) { $productAssociation->addAssociatedProduct($product); } }