custom/plugins/NextagCheckout/src/Subscriber/OrderPlaced.php line 36

Open in your IDE?
  1. <?php
  2. namespace Nextag\Checkout\Subscriber;
  3. use Nextag\Checkout\Content\Checkout\CheckoutService;
  4. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. class OrderPlaced implements EventSubscriberInterface
  9. {
  10.     private $requestStack;
  11.     private $session;
  12.     private $checkoutService;
  13.    
  14.     public function __construct(RequestStack $requestStack
  15.         CheckoutService $checkoutService
  16.         \Nextag\Checkout\Helper\Log $log,
  17.         Session $session
  18.     )
  19.     {
  20.         $this->requestStack $requestStack;
  21.         $this->checkoutService $checkoutService;
  22.         $this->log $log;        
  23.         $this->session $session;
  24.     }
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             CheckoutOrderPlacedEvent::class => 'onOrderPlaced'
  29.         ];
  30.     }
  31.     public function onOrderPlaced(CheckoutOrderPlacedEvent $event)
  32.     {
  33.         try {
  34.             $request $this->requestStack->getCurrentRequest();
  35.             $comment $request->get('next_checkout_comment');
  36.             $deliverydate $request->get('date');
  37.             $deliverytype $request->get('next_checkout_deliverytype');
  38.             $deliverylocation $request->get('next_checkout_deliverylocation');
  39.             $deliverylocationcomment $request->get('next_checkout_deliverylocationcomment');
  40.             $giftmessagefrom $request->get('next_checkout_giftmessagefrom');
  41.             $giftmessageto $request->get('next_checkout_giftmessageto');
  42.             $giftmessage $request->get('next_checkout_giftmessage');
  43.          
  44.             $giftbox1qty $request->get('next_checkout_giftbox1qty');
  45.             $giftbox2qty $request->get('next_checkout_giftbox2qty');
  46.             $giftbox3qty $request->get('next_checkout_giftbox3qty');
  47.             $giftbox4qty $request->get('next_checkout_giftbox4qty');
  48.             $giftbox5qty $request->get('next_checkout_giftbox5qty');
  49.             $giftbox6qty $request->get('next_checkout_giftbox6qty');
  50.             $giftbox7qty $request->get('next_checkout_giftbox7qty');
  51.             $giftbox8qty $request->get('next_checkout_giftbox8qty');
  52.             $giftbox1comment $request->get('next_checkout_giftbox1comment');
  53.             $giftbox2comment $request->get('next_checkout_giftbox2comment');
  54.             $giftbox3comment $request->get('next_checkout_giftbox3comment');
  55.             $giftbox4comment $request->get('next_checkout_giftbox4comment');
  56.             $giftbox5comment $request->get('next_checkout_giftbox5comment');
  57.             $giftbox6comment $request->get('next_checkout_giftbox6comment');
  58.             $giftbox7comment $request->get('next_checkout_giftbox7comment');
  59.             $giftbox8comment $request->get('next_checkout_giftbox8comment');
  60.             $retouren $request->get('next_checkout_retouren');
  61.             $voigtkundennummer $request->get('next_checkout_voigtkundennummer');
  62.          
  63.             //TODO erweitern
  64.             $language $request->get('next_checkout_language');
  65.             $data = [];
  66.             if ($comment && gettype($comment) == 'string') {
  67.                 $data["comment"] = $comment;
  68.             }
  69.             if ($deliverydate && gettype($deliverydate) == 'string') {
  70.                 $data["deliverydate"] = $deliverydate;
  71.             }
  72.             if ($deliverytype && gettype($deliverytype) == 'string') {
  73.                 $data["deliverytype"] = $deliverytype;
  74.             }
  75.             if ($deliverylocation && gettype($deliverylocation) == 'string') {
  76.                 $data["deliverylocation"] = $deliverylocation;
  77.             }
  78.             if ($deliverylocationcomment && gettype($deliverylocationcomment) == 'string') {
  79.                 $data["deliverylocationcomment"] = $deliverylocationcomment;
  80.             }
  81.             if ($giftmessagefrom && gettype($giftmessagefrom) == 'string') {
  82.                 $data["giftmessagefrom"] = $giftmessagefrom;
  83.             }
  84.             if ($giftmessageto && gettype($giftmessageto) == 'string') {
  85.                 $data["giftmessageto"] = $giftmessageto;
  86.             }
  87.             if ($giftmessage && gettype($giftmessage) == 'string') {
  88.                 $data["giftmessage"] = $giftmessage;
  89.             }
  90.             if ($giftbox1qty && is_numeric($giftbox1qty)) {
  91.                 $data["giftbox1qty"] =(int) $giftbox1qty;
  92.             }
  93.             if ($giftbox2qty && is_numeric($giftbox2qty)) {
  94.                 $data["giftbox2qty"] = (int) $giftbox2qty;
  95.             }
  96.             if ($giftbox3qty && is_numeric($giftbox3qty)) {
  97.                 $data["giftbox3qty"] = (int) $giftbox3qty;
  98.             }
  99.             if ($giftbox4qty && is_numeric($giftbox4qty)) {
  100.                 $data["giftbox4qty"] = (int) $giftbox4qty;
  101.             }
  102.             if ($giftbox5qty && is_numeric($giftbox5qty)) {
  103.                 $data["giftbox5qty"] = (int) $giftbox5qty;
  104.             }
  105.             if ($giftbox6qty && is_numeric($giftbox6qty)) {
  106.                 $data["giftbox6qty"] = (int) $giftbox6qty;
  107.             }
  108.             if ($giftbox7qty && is_numeric($giftbox7qty)) {
  109.                 $data["giftbox7qty"] = (int) $giftbox7qty;
  110.             }
  111.             if ($giftbox8qty && is_numeric($giftbox8qty)) {
  112.                 $data["giftbox8qty"] = (int) $giftbox8qty;
  113.             }
  114.             if ($giftbox1comment && gettype($giftbox1comment) == 'string') {
  115.                 $data["giftbox1comment"] = $giftbox1comment;
  116.             }
  117.             if ($giftbox2comment && gettype($giftbox2comment) == 'string') {
  118.                 $data["giftbox2comment"] = $giftbox2comment;
  119.             }
  120.             if ($giftbox3comment && gettype($giftbox3comment) == 'string') {
  121.                 $data["giftbox3comment"] = $giftbox3comment;
  122.             }
  123.             if ($giftbox4comment && gettype($giftbox4comment) == 'string') {
  124.                 $data["giftbox4comment"] = $giftbox4comment;
  125.             }
  126.             if ($giftbox5comment && gettype($giftbox5comment) == 'string') {
  127.                 $data["giftbox5comment"] = $giftbox5comment;
  128.             }
  129.             if ($giftbox6comment && gettype($giftbox6comment) == 'string') {
  130.                 $data["giftbox6comment"] = $giftbox6comment;
  131.             }
  132.             if ($giftbox7comment && gettype($giftbox7comment) == 'string') {
  133.                 $data["giftbox7comment"] = $giftbox7comment;
  134.             }
  135.             if ($giftbox8comment && gettype($giftbox8comment) == 'string') {
  136.                 $data["giftbox7comment"] = $giftbox8comment;
  137.             }
  138.             if ($retouren && gettype($retouren) == 'string') {
  139.                 $data["retouren"] = $retouren;
  140.             }
  141.             if ($voigtkundennummer && gettype($voigtkundennummer) == 'string') {
  142.                 $data["voigtkundennummer"] = $voigtkundennummer;
  143.             }
  144.        
  145.             if ($language && gettype($language) == 'string') {
  146.                 $data["language"] = $language;
  147.             } else {
  148.                 $language "de";
  149.             }
  150.             if (!empty($data)) {
  151.                  if (!isset($data["comment"]) || $data["comment"] == null) {
  152.                     $data["comment"] = "";
  153.                 }
  154.                 if (!isset($data["retouren"]) || $data["retouren"] == null) {
  155.                     $data["retouren"] = "";
  156.                 }
  157.                 if (!isset($data["giftmessage"]) || $data["giftmessage"] == null) {
  158.                     $data["giftmessage"] = "";
  159.                 }
  160.                 if ($this->session->get("pos") == "SG") {
  161.                     $data["orderedBy"] = "POS St. Gallen";
  162.                 } elseif ($this->session->get("pos") == "ZH") {
  163.                     $data["orderedBy"] = "POS St. Zürich";
  164.                 } else {
  165.                     $data["orderedBy"] = "Kunde";
  166.                 }
  167.                 $this->checkoutService->save($data$event);
  168.             }
  169.         } catch (\Exception $exception) {
  170.             $this->log->error($exception);
  171.         }
  172.     }
  173. }