/** * Displays a form to create a new ProductAttribute entity. * * @Route("/{product}/new", name="supplier_product_attribute_new") * @Method("GET") * @Template() */ public function newAction($product) { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('HypersitesStockBundle:Product')->findOneBy(array('id' => $product)); $entity = new ProductAttribute(); $entity->setProduct($product); $form = $this->createCreateForm($entity); return array('product' => $product, 'entity' => $entity, 'form' => $form->createView()); }
/** * Method that create the Variatons Attribute that identify each Variation * @param ProductAttribute $productAttribute * @retun void() */ private function generateVariationAttribute(ProductAttribute $productAttribute) { $values = $productAttribute->getAttributeValue(); foreach ($values as $variation) { $variationAttribute = new \Hypersites\StockBundle\Entity\VariationAttributes(); $variationAttribute->setProductAttribute($productAttribute); $variationAttribute->setAttributeValue($variation); $this->em->persist($variationAttribute); $this->variationAttributeCollection->add($variationAttribute); } $productAttribute->setVariationAttributes($this->variationAttributeCollection); $this->em->persist($productAttribute); $this->em->flush(); }