/** * Gives an array of products which can be handed over to a select form element * * @param type $thisProduct * @return array */ private function getProductOptions(Entity\Product $thisProduct = null, $productId = null) { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $products = $em->getRepository("ErsBase\\Entity\\Product")->findBy(array(), array('position' => 'ASC')); $options = array(); foreach ($products as $product) { $selected = false; if ($thisProduct->getId() == $product->getId()) { continue; } if ($productId == $product->getId()) { $selected = true; } $options[] = array('value' => $product->getId(), 'label' => $product->getName(), 'selected' => $selected); } return $options; }
private function removeProductVariants(Entity\Product $Product) { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $ProductVariants = $em->getRepository("ErsBase\\Entity\\ProductVariant")->findBy(array('Product_id' => $Product->getId())); foreach ($ProductVariants as $variant) { $ProductVariantValues = $em->getRepository("ErsBase\\Entity\\ProductVariantValue")->findBy(array('ProductVariant_id' => $variant->getId()), array('position' => 'ASC')); foreach ($ProductVariantValues as $value) { $em->remove($value); } $em->remove($variant); } }