protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $product = $em->find('ClubShopBundle:Product', $input->getArgument('product'));
     $location = $em->find('ClubUserBundle:Location', $input->getArgument('location'));
     $payment = $em->find('ClubShopBundle:PaymentMethod', 1);
     $fh = fopen($input->getArgument('file'), 'r');
     while (!feof($fh)) {
         $member_number = trim(fgets($fh, 1024));
         if (strlen($member_number) > 0) {
             $user = $em->getRepository('ClubUserBundle:User')->findOneBy(array('member_number' => $member_number));
             if (!$user) {
                 throw new \Exception('No such user: '******'order');
             $order->createSimpleOrder($user, $location);
             $cart_prod = new \Club\ShopBundle\Entity\CartProduct();
             $cart_prod->setType('subscription');
             $cart_prod->setQuantity(1);
             $cart_prod->setPrice($product->getPrice());
             $cart_prod->setProductName($product->getProductName());
             $cart_prod->setProduct($product);
             foreach ($product->getProductAttributes() as $attr) {
                 $product_attr = new \Club\ShopBundle\Entity\CartProductAttribute();
                 $product_attr->setCartProduct($cart_prod);
                 $product_attr->setValue($attr->getValue());
                 $product_attr->setAttributeName($attr->getAttribute());
                 $cart_prod->addCartProductAttribute($product_attr);
             }
             $order->addCartProduct($cart_prod);
             $order->save();
             $p = new \Club\ShopBundle\Entity\PurchaseLog();
             $p->setAmount($order->getOrder()->getAmountLeft() * 100);
             $p->setCurrency('DKK');
             $p->setAccepted(true);
             $p->setOrder($order->getOrder());
             $p->setPaymentMethod($payment);
             $em->persist($p);
             $order->makePayment($p);
             $em->flush();
         }
     }
     $em->flush();
 }
Exemple #2
0
 public function makeCartProduct(\Club\ShopBundle\Entity\Product $product)
 {
     $op = new \Club\ShopBundle\Entity\CartProduct();
     $op->setProduct($product);
     $op->setProductName($product->getProductName());
     $op->setPrice($product->getSpecialPrice());
     $op->setQuantity(1);
     $op->setType($product->getType());
     foreach ($product->getProductAttributes() as $attr) {
         $opa = new \Club\ShopBundle\Entity\CartProductAttribute();
         $opa->setCartProduct($op);
         $opa->setValue($attr->getValue());
         $opa->setAttributeName($attr->getAttribute());
         $op->addCartProductAttribute($opa);
     }
     return $op;
 }
Exemple #3
0
 private function addProductToCart(\Club\ShopBundle\Entity\Product $product)
 {
     $this->checkLocation($product);
     $trigger = 0;
     // check if its already in the cart
     foreach ($this->cart->getCartProducts() as $prod) {
         if ($prod->getProduct()->getId() == $product->getId()) {
             $prod = $this->modifyQuantity($prod);
             $trigger = 1;
         }
     }
     if (!$trigger) {
         $op = new \Club\ShopBundle\Entity\CartProduct();
         $op->setCart($this->cart);
         $op->setProduct($product);
         $op->setProductName($product->getProductName());
         $op->setPrice($product->getSpecialPrice());
         $op->setVatRate($product->getVat()->getRate());
         $op->setQuantity(1);
         $op->setType('product');
         foreach ($product->getProductAttributes() as $attr) {
             $opa = new \Club\ShopBundle\Entity\CartProductAttribute();
             $opa->setCartProduct($op);
             $opa->setValue($attr->getValue());
             $opa->setAttributeName($attr->getAttribute()->getAttributeName());
             $op->addCartProductAttribute($opa);
         }
         $this->updateProductToCart($op);
     }
 }