private function setData(\Club\ShopBundle\Entity\Product $product, $data) { $em = $this->getDoctrine()->getManager(); foreach ($data as $attribute => $value) { if ($attribute == 'location') { $str = ''; foreach ($value as $l) { $str .= $l->getId() . ','; } $str = preg_replace("/,\$/", "", $str); $value = $str != '' ? $str : null; } if (preg_match("/^(start_date|expire_date)\$/", $attribute) && $value != '') { $value = $value->format('Y-m-d'); } if (preg_match("/^(start_time|stop_time)\$/", $attribute) && $value != '') { $value = $value->format('H:i:s'); } $prod_attr = $em->getRepository('ClubShopBundle:ProductAttribute')->findOneBy(array('product' => $product->getId(), 'attribute' => $attribute)); if (strlen($value)) { $prod_attr = !$prod_attr ? $this->buildProductAttribute($product, $attribute) : $prod_attr; $prod_attr->setValue($value); $em->persist($prod_attr); } elseif ($prod_attr && $value == '') { $em->remove($prod_attr); } } $em->flush(); }
private function setData(\Club\ShopBundle\Entity\Product $product, $data) { $em = $this->getDoctrine()->getEntityManager(); foreach ($em->getRepository('ClubShopBundle:Attribute')->findAll() as $attr) { $prod_attr = $em->getRepository('ClubShopBundle:ProductAttribute')->findOneBy(array('product' => $product->getId(), 'attribute' => $attr->getId())); if (($attr->getAttributeName() == 'StartDate' || $attr->getAttributeName() == 'ExpireDate') && $data[$attr->getAttributeName()] != '') { $data[$attr->getAttributeName()] = $data[$attr->getAttributeName()]->format('Y-m-d'); } if ($attr->getAttributeName() == 'Location') { $str = ''; foreach ($data[$attr->getAttributeName()] as $l) { $str .= $l->getId() . ','; } $str = preg_replace("/,\$/", "", $str); $str = $str != '' ? $str : null; if ($str == '') { if ($prod_attr) { $em->remove($prod_attr); } } else { if (!$prod_attr) { $prod_attr = $this->buildProductAttribute($product, $attr); } $prod_attr->setValue($str); $em->persist($prod_attr); } } else { if ($prod_attr && $data[$attr->getAttributeName()] == '') { $em->remove($prod_attr); } elseif ($prod_attr && $data[$attr->getAttributeName()] != '') { $prod_attr->setValue($data[$attr->getAttributeName()]); $em->persist($prod_attr); } elseif (!$prod_attr && $data[$attr->getAttributeName()] != '') { $prod_attr = $this->buildProductAttribute($product, $attr); $prod_attr->setValue($data[$attr->getAttributeName()]); $em->persist($prod_attr); } } } $em->flush(); }
public function getBoughtByUser(\Club\ShopBundle\Entity\Product $product, \Club\UserBundle\Entity\User $user) { return $this->createQueryBuilder('op')->join('op.order', 'o')->join('o.user', 'u')->join('op.product', 'p')->where('u.id = :user')->andWhere('p.id = :product')->andWhere('o.cancelled = false')->setParameter('user', $user->getId())->setParameter('product', $product->getId())->getQuery()->getResult(); }
public function getUsersByProduct(\Club\ShopBundle\Entity\Product $product) { return $this->_em->createQueryBuilder()->select('op, o, u')->from('ClubShopBundle:OrderProduct', 'op')->join('op.order', 'o')->join('o.user', 'u')->where('op.product = :product')->andWhere('o.paid = true')->orderBy('o.id', 'DESC')->setParameter('product', $product->getId())->getQuery()->getResult(); }
public function getProductInCart(\Club\ShopBundle\Entity\Product $product, \Club\ShopBundle\Entity\Cart $cart) { return $this->createQueryBuilder('cp')->join('cp.cart', 'c')->join('cp.product', 'p')->where('c.id = :cart')->andWhere('p.id = :product')->setParameter('cart', $cart->getId())->setParameter('product', $product->getId())->getQuery()->getOneOrNullResult(); }