Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Optimized different methods, to fit import order command.

  • Loading branch information...
commit a6005dc89868a65e8e91d014aa548248613d39d2 1 parent 2578419
@hollodk hollodk authored
View
4 src/Club/LogBundle/Listener/NewOrderListener.php
@@ -23,8 +23,8 @@ public function onShopOrder(\Club\ShopBundle\Event\FilterOrderEvent $event)
$log->setLogType('shop');
$log->setLog('Created a new order #'.$order->getId());
- $user = $this->security_context->getToken()->getUser();
- if ($user instanceOf \Club\UserBundle\Entity\User) $log->setUser($user);
+ if ($this->security_context->getToken() && $this->security_context->isGranted('IS_AUTHENTICATED_FULLY'))
+ $log->setUser($this->security_context->getToken()->getUser());
$this->em->persist($log);
$this->em->flush();
View
6 src/Club/LogBundle/Listener/OrderChangeListener.php
@@ -16,15 +16,15 @@ public function __construct($em,$security_context)
public function onOrderChange(\Club\ShopBundle\Event\FilterOrderEvent $event)
{
$order = $event->getOrder();
- $user = $this->security_context->getToken()->getUser();
-
$log = new \Club\LogBundle\Entity\Log();
$log->setEvent('onOrderChange');
$log->setSeverity('informational');
- $log->setUser($user);
$log->setLogType('shop');
$log->setLog('Changed order status on order #'.$order->getId());
+ if ($this->security_context->getToken() && $this->security_context->isGranted('IS_AUTHENTICATED_FULLY'))
+ $log->setUser($this->security_context->getToken()->getUser());
+
$this->em->persist($log);
$this->em->flush();
}
View
33 src/Club/ShopBundle/Command/ImportOrderCommand.php
@@ -16,6 +16,7 @@ protected function configure()
->setName('club:import:order')
->setDescription('Import orders')
->addArgument('file', InputArgument::REQUIRED, 'What filename to import')
+ ->addArgument('location', InputArgument::REQUIRED, 'What location to shop from?')
->addArgument('product', InputArgument::REQUIRED, 'What product id to let the users buy?')
->setHelp(<<<EOF
The required filename just has to have a list of member numbers.
@@ -27,16 +28,40 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
+ $product = $em->find('ClubShopBundle:Product', $input->getArgument('product'));
+ $location = $em->find('ClubUserBundle:Location', $input->getArgument('location'));
$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
- ));
+ $user = $em->getRepository('ClubUserBundle:User')->findOneBy(array( 'member_number' => $member_number ));
+ if (!$user) throw new \Exception('No such user: '.$member_number);
- if (!$user) throw new \Exception('No such user: '.$member_number);
+ $order = $this->getContainer()->get('order');
+ $order->createSimpleOrder($user, $location);
+ $cart_prod = new \Club\ShopBundle\Entity\CartProduct();
+ $cart_prod->setType('product');
+ $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();
+
+ $status = $em->getRepository('ClubShopBundle:OrderStatus')->getAcceptedStatus();
+ $order->changeStatus($status);
+ }
}
$em->flush();
}
View
10 src/Club/ShopBundle/Controller/AdminOrderController.php
@@ -40,14 +40,12 @@ public function editAction($id)
if ($this->getRequest()->getMethod() == 'POST') {
$form->bindRequest($this->getRequest());
if ($form->isValid()) {
- $em = $this->getDoctrine()->getEntityManager();
- $em->persist($order);
- $em->flush();
+ $data = $form->getData();
- $this->get('session')->setFlash('notice',$this->get('translator')->trans('Your changes are saved.'));
+ $this->get('order')->setOrder($order);
+ $this->get('order')->changeStatus($data->getOrderStatus());
- $event = new \Club\ShopBundle\Event\FilterOrderEvent($order);
- $this->get('event_dispatcher')->dispatch(\Club\ShopBundle\Event\Events::onOrderChange, $event);
+ $this->get('session')->setFlash('notice',$this->get('translator')->trans('Your changes are saved.'));
return $this->redirect($this->generateUrl('admin_shop_order'));
}
View
1  src/Club/ShopBundle/Entity/Product.php
@@ -91,6 +91,7 @@ public function __construct()
{
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
$this->product_attributes = new \Doctrine\Common\Collections\ArrayCollection();
+ $this->type = 'product';
}
public function __toString()
View
29 src/Club/ShopBundle/Helper/Order.php
@@ -8,12 +8,17 @@ class Order
private $em;
private $event_dispatcher;
- public function __construct($em,$event_dispatcher)
+ public function __construct($em, $event_dispatcher)
{
$this->em = $em;
$this->event_dispatcher = $event_dispatcher;
}
+ public function setOrder(\Club\ShopBundle\Entity\Order $order)
+ {
+ $this->order = $order;
+ }
+
public function createSimpleOrder(\Club\UserBundle\Entity\User $user, \Club\UserBundle\Entity\Location $location)
{
$this->order = new \Club\ShopBundle\Entity\Order();
@@ -26,18 +31,18 @@ public function createSimpleOrder(\Club\UserBundle\Entity\User $user, \Club\User
$this->setCurrency();
}
- public function addSimpleProduct($product)
+ public function addSimpleProduct(\Club\ShopBundle\Entity\CartProduct $product)
{
+ // will not add product attribute
$prod = new \Club\ShopBundle\Entity\OrderProduct();
$prod->setOrder($this->order);
- $prod->setPrice($product['price']);
- $prod->setQuantity($product['quantity']);
- $prod->setProductName($product['product_name']);
- $prod->setType($product['type']);
+ $prod->setPrice($product->getPrice());
+ $prod->setQuantity($product->getQuantity());
+ $prod->setProductName($product->getProductName());
+ $prod->setType($product->getType());
$this->order->addOrderProduct($prod);
-
$this->em->persist($prod);
}
@@ -76,6 +81,16 @@ public function getOrder()
return $this->order;
}
+ public function changeStatus(\Club\ShopBundle\Entity\OrderStatus $order_status)
+ {
+ $this->order->setOrderStatus($order_status);
+ $this->em->persist($this->order);
+ $this->em->flush();
+
+ $event = new \Club\ShopBundle\Event\FilterOrderEvent($this->order);
+ $this->event_dispatcher->dispatch(\Club\ShopBundle\Event\Events::onOrderChange, $event);
+ }
+
private function setCustomerAddressByUser($user)
{
$address = $this->getAddressByUser($user);
View
2  src/Club/TODO
@@ -1,4 +1,6 @@
== NOTES TO THIS RELEASE ==
+validate change order works
+validate team penalty still works
merge migrations into one file
filter with subscription date does not seems to wrk
quick create intervals when creating the field
View
12 src/Club/TeamBundle/Listener/TeamPenaltyListener.php
@@ -33,13 +33,13 @@ public function onTeamPenalty(\Club\TaskBundle\Event\FilterTaskEvent $event)
$participant = $this->em->getRepository('ClubTeamBundle:Participant')->getUserInRange($user->getUser(), $first, $last);
if (!count($participant)) {
if ($this->penalty_enabled) {
+ $product = new \Club\ShopBundle\Entity\CartProduct();
+ $product->setPrice($schedule->getPenalty());
+ $product->setQuantity(1);
+ $product->setType('team_fee');
+ $product->setProductName($this->penalty_product_name);
+
$this->order->createSimpleOrder($user->getUser(),$schedule->getLocation());
- $product = array(
- 'price' => $schedule->getPenalty(),
- 'quantity' => 1,
- 'type' => 'product',
- 'product_name' => $this->penalty_product_name
- );
$this->order->addSimpleProduct($product);
$this->order->save();
}
Please sign in to comment.
Something went wrong with that request. Please try again.