/** * @param \Enlight_Controller_ActionEventArgs $args */ public function onPostDispatchBackendOrder($args) { // Add View directory $view = $args->getSubject()->View(); if ($args->getRequest()->getActionName() === 'load') { $view->extendsTemplate('backend/plugins/payment_stripe/order_detail_position_refund.js'); } }
/** * @param \Enlight_Controller_ActionEventArgs $args */ public function onPreDispatchPaymentPaypal($args) { $request = $args->getRequest(); /** @var \Shopware_Controllers_Frontend_PaymentPaypal $action */ $action = $args->getSubject(); if ($request->getActionName() != 'return') { return; } $paymentId = $this->session->PaypalPlusPayment; if (empty($paymentId)) { return; } $payerId = $request->getParam('PayerID'); $this->restClient->setAuthToken(); $uri = 'payments/payment/' . $paymentId; $payment = $this->restClient->get($uri, array('payer_id' => $payerId)); $statusId = $this->paypalBootstrap->Config()->get('paypalStatusId', 12); if (!empty($payment['transactions'][0]['amount']['total'])) { $ppAmount = floatval($payment['transactions'][0]['amount']['total']); $ppCurrency = floatval($payment['transactions'][0]['amount']['currency']); } else { $ppAmount = 0; $ppCurrency = ''; } $swAmount = $action->getAmount(); $swCurrency = $action->getCurrencyShortName(); if (abs($swAmount - $ppAmount) >= 0.01 || $ppCurrency != $swCurrency) { $action->redirect(array('controller' => 'checkout', 'action' => 'confirm')); return; } if ($payment['state'] == 'created') { $uri = "payments/payment/{$paymentId}/execute"; $payment = $this->restClient->create($uri, array('payer_id' => $payerId)); } if ($payment['state'] == 'approved') { if (!empty($payment['transactions'][0]['related_resources'][0]['sale']['id'])) { $transactionId = $payment['transactions'][0]['related_resources'][0]['sale']['id']; } else { $transactionId = $payment['id']; } $orderNumber = $action->saveOrder($transactionId, sha1($payment['id']), $statusId); if ($payment['payment_instruction']) { $this->saveInvoiceInstructions($orderNumber, $payment); } try { $sql = ' INSERT INTO s_order_attributes (orderID, swag_payal_express) SELECT id, 2 FROM s_order WHERE ordernumber = ? ON DUPLICATE KEY UPDATE swag_payal_express = 2 '; $action->get('db')->query($sql, array($orderNumber)); } catch (\Exception $e) { } $action->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => sha1($payment['id']))); } }
/** * @param \Enlight_Controller_ActionEventArgs $args */ public function onExtendBackendPayment($args) { $request = $args->getRequest(); $view = $args->getSubject()->View(); if ($request->getActionName() == 'load') { $this->bootstrap->registerMyTemplateDir(); $view->extendsTemplate('backend/payment/model/paypal_attribute.js'); $view->extendsTemplate('backend/payment/view/payment/paypal_form.js'); } }
/** * adds the templates directories which expand the customer module * * @param Enlight_Controller_ActionEventArgs $args */ public function onCustomerPostDispatchSecure(Enlight_Controller_ActionEventArgs $args) { $view = $args->getSubject()->View(); $args->getSubject()->View()->addTemplateDir($this->Path() . 'Views/'); if ($args->getRequest()->getActionName() === 'load') { $view->extendsTemplate('backend/customer/controller/create_backend_order/detail.js'); $view->extendsTemplate('backend/customer/controller/create_backend_order/main.js'); $view->extendsTemplate('backend/customer/view/create_backend_order/detail/base.js'); $view->extendsTemplate('backend/customer/view/create_backend_order/detail/additional.js'); $view->extendsTemplate('backend/customer/view/create_backend_order/detail/window.js'); } }
/** * Event listener method * * @param Enlight_Controller_ActionEventArgs $args */ public function onPostDispatch(Enlight_Controller_ActionEventArgs $args) { $config = $this->Config(); if (!$config->show) { return; } $view = $args->getSubject()->View(); $parent = Shopware()->Shop()->get('parentID'); $categoryId = $args->getRequest()->getParam('sCategory', $parent); $menu = $this->getAdvancedMenu($parent, $categoryId, (int) $config->levels); $view->assign('sAdvancedMenu', $menu); $view->assign('columnAmount', $config->columnAmount); $view->addTemplateDir($this->Path() . 'Views'); }
/** * When index backend module was loaded, add our snippet- and template-directory * Also extend the template * * @param \Enlight_Controller_ActionEventArgs $args */ public function onBackendIndexPostDispatch(Enlight_Controller_ActionEventArgs $args) { $args->getSubject()->View()->addTemplateDir(__DIR__ . '/Views/'); // if the controller action name equals "load" we inject our update check if ($args->getRequest()->getActionName() === 'load') { $args->getSubject()->View()->extendsTemplate('backend/index/view/swag_update_menu.js'); } }
/** * Do http caching jobs * * @param Enlight_Controller_ActionEventArgs $args */ public function onPreDispatch(\Enlight_Controller_ActionEventArgs $args) { $this->action = $args->getSubject(); $this->request = $args->getRequest(); $this->response = $args->getResponse(); $this->Application()->Events()->registerListener(new Enlight_Event_Handler_Default('Enlight_Controller_Action_PostDispatch', array($this, 'onPostDispatch'), 399)); }
/** * @param \Enlight_Controller_ActionEventArgs $args */ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $args) { $request = $args->getRequest(); /** @var \Shopware_Controllers_Frontend_PaymentPaypal $controller */ $controller = $args->getSubject(); if ($request->getActionName() != 'return') { return; } $paymentId = $request->get('paymentId'); if (!$paymentId) { return; } $payerId = $request->getParam('PayerID'); $uri = 'payments/payment/' . $paymentId; $payment = array(); try { $payment = $this->restClient->get($uri, array('payer_id' => $payerId)); } catch (Exception $e) { $this->logException('An error occurred on getting the payment on returning from PayPal', $e); } if (!empty($payment['transactions'][0]['amount']['total'])) { $ppAmount = floatval($payment['transactions'][0]['amount']['total']); $ppCurrency = floatval($payment['transactions'][0]['amount']['currency']); } else { $ppAmount = 0; $ppCurrency = ''; } $swAmount = $controller->getAmount(); $swCurrency = $controller->getCurrencyShortName(); if (abs($swAmount - $ppAmount) >= 0.01 || $ppCurrency != $swCurrency) { $controller->redirect(array('controller' => 'checkout', 'action' => 'confirm')); return; } $paypalConfig = $this->paypalBootstrap->Config(); $orderNumber = null; if ($payment['state'] == 'created') { if ($paypalConfig->get('paypalSendInvoiceId')) { $orderNumber = $controller->saveOrder($payment['id'], sha1($payment['id'])); $params = array(array('op' => 'add', 'path' => '/transactions/0/invoice_number', 'value' => $orderNumber)); $prefix = $paypalConfig->get('paypalPrefixInvoiceId'); if ($prefix) { // Set prefixed invoice id - Remove special chars and spaces $prefix = str_replace(' ', '', $prefix); $prefix = preg_replace('/[^A-Za-z0-9\\_]/', '', $prefix); $params[0]['value'] = $prefix . $orderNumber; } $uri = 'payments/payment/' . $paymentId; try { $this->restClient->patch($uri, $params); } catch (Exception $e) { $this->logException('An error occurred on patching the order number to the payment', $e); } } $uri = "payments/payment/{$paymentId}/execute"; try { $payment = $this->restClient->create($uri, array('payer_id' => $payerId)); } catch (Exception $e) { $this->logException('An error occurred on executing the payment', $e); } } if ($payment['state'] == 'approved') { if (!empty($payment['transactions'][0]['related_resources'][0]['sale']['id'])) { $transactionId = $payment['transactions'][0]['related_resources'][0]['sale']['id']; } else { $transactionId = $payment['id']; } if (!$orderNumber) { $orderNumber = $controller->saveOrder($transactionId, sha1($payment['id'])); } else { $sql = 'UPDATE s_order SET transactionID = ? WHERE ordernumber = ?;'; $controller->get('db')->query($sql, array($transactionId, $orderNumber)); } if (!empty($payment['transactions'][0]['related_resources'][0]['sale']['state'])) { $paymentStatus = ucfirst($payment['transactions'][0]['related_resources'][0]['sale']['state']); $this->paypalBootstrap->setPaymentStatus($transactionId, $paymentStatus); } if ($payment['payment_instruction']) { $this->saveInvoiceInstructions($orderNumber, $payment); } try { $sql = ' INSERT INTO s_order_attributes (orderID, swag_payal_express) SELECT id, 2 FROM s_order WHERE ordernumber = ? ON DUPLICATE KEY UPDATE swag_payal_express = 2 '; $controller->get('db')->query($sql, array($orderNumber)); } catch (Exception $e) { } $controller->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => sha1($payment['id']))); } }