Exemplo n.º 1
0
 /**
  * Checks if we are the payment module for the order, and if the order is paid,
  * then send a confirmation email to the customer.
  *
  * @params OrderEvent $order
  */
 public function update_status(OrderEvent $event)
 {
     $payzen = new Payzen();
     if ($event->getOrder()->isPaid() && $payzen->isPaymentModuleFor($event->getOrder())) {
         $contact_email = ConfigQuery::read('store_email', false);
         Tlog::getInstance()->debug("Sending confirmation email from store contact e-mail {$contact_email}");
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName(Payzen::CONFIRMATION_MESSAGE_NAME)->findOne();
             if (false === $message) {
                 throw new \Exception(sprintf("Failed to load message '%s'.", Payzen::CONFIRMATION_MESSAGE_NAME));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->getMailer()->send($instance);
             Tlog::getInstance()->debug("Confirmation email sent to customer " . $customer->getEmail());
         }
     } else {
         Tlog::getInstance()->debug("No confirmation email sent (order not paid, or not the proper payement module.");
     }
 }
Exemplo n.º 2
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $paidStatusId = OrderStatusQuery::create()->filterByCode(OrderStatus::CODE_PAID)->select('Id')->findOne();
     if ($order->hasVirtualProduct() && $event->getStatus() == $paidStatusId) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'mail_virtualproduct'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Virtual product download message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Virtual product download message no contact email customer_id", $customer->getId());
         }
     }
 }
Exemplo n.º 3
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_colissimo')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'order_confirmation'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::getStoreName());
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
Exemplo n.º 4
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === DpdClassic::getModuleId()) {
         if ($event->getOrder()->getStatusId() === DpdClassic::STATUS_SENT) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_dpdclassic')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_dpdclassic'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('order_date', $order->getCreatedAt());
                 $this->parser->assign('update_date', $order->getUpdatedAt());
                 $this->parser->assign('package', $order->getDeliveryRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
Exemplo n.º 5
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_localpickup')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_localpickup'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $store = ConfigQuery::create();
                 $country = CountryQuery::create()->findPk($store->read("store_country"));
                 $country = CountryI18nQuery::create()->filterById($country->getId())->findOneByLocale($order->getLang()->getLocale())->getTitle();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('store_name', $store->read("store_name"));
                 $this->parser->assign('store_address1', $store->read("store_address1"));
                 $this->parser->assign('store_address2', $store->read("store_address2"));
                 $this->parser->assign('store_address3', $store->read("store_address3"));
                 $this->parser->assign('store_zipcode', $store->read("store_zipcode"));
                 $this->parser->assign('store_city', $store->read("store_city"));
                 $this->parser->assign('store_country', $country);
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
Exemplo n.º 6
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $Predict = new Predict();
     if ($order->isSent() && $order->getDeliveryModuleId() == $Predict->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_predict')->findOne();
             if (false === $message) {
                 throw new \Exception(Translator::getInstance()->trans("Failed to load message '%mail_tpl_name'.", ["%mail_tpl_name" => "mail_predict"], Predict::MESSAGE_DOMAIN));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Predict shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Predict shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 /**
  * @param OrderEvent $event
  *
  * Check if we're the payment module, and send the payment confirmation email to the customer if it's the case.
  */
 public function sendConfirmationEmail(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Cheque::getModuleId()) {
         if ($event->getOrder()->isPaid(true)) {
             $order = $event->getOrder();
             $this->mailer->sendEmailToCustomer('order_confirmation_cheque', $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Send the confirmation message only if the order is paid.
  *
  * @param OrderEvent $event
  */
 public function checkSendOrderConfirmationMessageToCustomer(OrderEvent $event)
 {
     if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
         $paybox = new Paybox();
         if ($paybox->isPaymentModuleFor($event->getOrder())) {
             if (!$event->getOrder()->isPaid()) {
                 $event->stopPropagation();
             }
         }
     }
 }
 public function verifyCreditUsage(OrderEvent $event)
 {
     $session = $this->request->getSession();
     if ($session->get('creditAccount.used') == 1) {
         $customer = $event->getOrder()->getCustomer();
         $amount = $session->get('creditAccount.amount');
         $creditEvent = new CreditAccountEvent($customer, $amount * -1, $event->getOrder()->getId());
         $creditEvent->setWhoDidIt(Translator::getInstance()->trans('Customer', [], CreditAccount::DOMAIN))->setOrderId($event->getOrder()->getId());
         $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         $session->set('creditAccount.used', 0);
         $session->set('creditAccount.amount', 0);
     }
 }
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === FreeShipping::getModuleId()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::getStoreEmail();
             if ($contact_email) {
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->mailer->sendEmailToCustomer(FreeShipping::MESSAGE_SEND_CONFIRMATION, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'customer_id' => $customer->getId(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             }
         }
     }
 }
Exemplo n.º 11
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->mailer->sendEmailToCustomer('mail_colissimo', $customer, ['customer_id' => $customer->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
Exemplo n.º 12
0
 /**
  * @depends testCreate
  *
  * @param OrderModel $order
  */
 public function testUpdateDeliveryRef(OrderModel $order)
 {
     $deliveryRef = uniqid('DELREF');
     $this->orderEvent->setDeliveryRef($deliveryRef);
     $this->orderEvent->setOrder($order);
     $this->orderAction->updateDeliveryRef($this->orderEvent);
     $this->assertEquals($deliveryRef, $this->orderEvent->getOrder()->getDeliveryRef());
     $this->assertEquals($deliveryRef, OrderQuery::create()->findPk($order->getId())->getDeliveryRef());
 }
Exemplo n.º 13
0
 /**
  * Send email to notify customer that files for virtual products are available
  *
  * @param OrderEvent $event
  * @throws \Exception
  */
 public function sendEmail(OrderEvent $event)
 {
     $order = $event->getOrder();
     // Be sure that we have a document to download
     $virtualProductCount = OrderProductQuery::create()->filterByOrderId($order->getId())->filterByVirtual(true)->filterByVirtualDocument(null, Criteria::NOT_EQUAL)->count();
     if ($virtualProductCount > 0) {
         $customer = $order->getCustomer();
         $this->mailer->sendEmailToCustomer('mail_virtualproduct', $customer, ['customer_id' => $customer->getId(), 'order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt()]);
     } else {
         Tlog::getInstance()->warning("Virtual product download message not sent to customer: there's nothing to downnload");
     }
 }
Exemplo n.º 14
0
 public function saveComment(OrderEvent $orderEvent)
 {
     $comment = $this->request->getSession()->get('order-comment');
     $order = $orderEvent->getOrder();
     $orderId = $order->getId();
     if ($orderId != null && $comment != null) {
         $orderComment = new OrderComment();
         $orderComment->setOrderId($orderId);
         $orderComment->setComment($comment);
         $orderComment->save();
         $this->request->getSession()->set('order-comment', '');
     }
 }
Exemplo n.º 15
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid() && $order->getPaymentModuleId() == Atos::getModuleId()) {
         if (Atos::getConfigValue('send_payment_confirmation_message')) {
             $this->mailer->sendEmailToCustomer(Atos::CONFIRMATION_MESSAGE_NAME, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
         // Send confirmation email if required.
         if (Atos::getConfigValue('send_confirmation_message_only_if_paid')) {
             $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
         }
         Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
     }
 }
Exemplo n.º 16
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Paypal::getModCode()) {
         if ($event->getOrder()->isPaid()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('payment_confirmation_paypal')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'payment_confirmation_paypal'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
Exemplo n.º 17
0
 public function updateCreditAccount(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid(true)) {
         $total = $order->getTotalAmount();
         $loyaltySlice = LoyaltyQuery::create()->filterByMin($total, Criteria::LESS_EQUAL)->filterByMax($total, Criteria::GREATER_EQUAL)->findOne();
         if ($loyaltySlice) {
             $amount = $loyaltySlice->getAmount();
             $creditEvent = new CreditAccountEvent($order->getCustomer(), $amount, $order->getId());
             $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         }
     } else {
         // Remove any credited amount
         $entryList = CreditAmountHistoryQuery::create()->findByOrderId($order->getId());
         /** @var CreditAmountHistory $entry */
         foreach ($entryList as $entry) {
             $creditEvent = new CreditAccountEvent($order->getCustomer(), -$entry->getAmount(), $order->getId());
             $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         }
     }
 }
Exemplo n.º 18
0
 public function setOrderDelivery(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() == TNTFrance::getModuleId()) {
         // we have the order id
         $data = TNTFrance::getExtraOrderData($event->getOrder()->getCartId());
         TNTFrance::setExtraOrderData($event->getOrder()->getId(), $data, false);
     }
 }
Exemplo n.º 19
0
 /**
  * @param OrderEvent $event
  */
 public function updateDeliveryRef(OrderEvent $event)
 {
     $order = $event->getOrder();
     $order->setDeliveryRef($event->getDeliveryRef());
     $order->save();
     $event->setOrder($order);
 }
Exemplo n.º 20
0
 /**
  * @param OrderEvent $event
  */
 public function updateTransactionRef(OrderEvent $event)
 {
     $order = $event->getOrder();
     $order->setTransactionRef($event->getTransactionRef());
     $order->save();
     $event->setOrder($order);
 }
Exemplo n.º 21
0
 /**
  * @param \Thelia\Core\Event\Order\OrderEvent $event
  *
  * @throws \Exception if something goes wrong.
  */
 public function afterOrder(OrderEvent $event)
 {
     $consumedCoupons = $this->request->getSession()->getConsumedCoupons();
     if (is_array($consumedCoupons)) {
         $con = Propel::getWriteConnection(OrderCouponTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             foreach ($consumedCoupons as $couponCode) {
                 $couponQuery = CouponQuery::create();
                 $couponModel = $couponQuery->findOneByCode($couponCode);
                 $couponModel->setLocale($this->request->getSession()->getLang()->getLocale());
                 /* decrease coupon quantity */
                 $this->couponManager->decrementQuantity($couponModel, $event->getOrder()->getCustomerId());
                 /* memorize coupon */
                 $orderCoupon = new OrderCoupon();
                 $orderCoupon->setOrder($event->getOrder())->setCode($couponModel->getCode())->setType($couponModel->getType())->setAmount($couponModel->getAmount())->setTitle($couponModel->getTitle())->setShortDescription($couponModel->getShortDescription())->setDescription($couponModel->getDescription())->setExpirationDate($couponModel->getExpirationDate())->setIsCumulative($couponModel->getIsCumulative())->setIsRemovingPostage($couponModel->getIsRemovingPostage())->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())->setSerializedConditions($couponModel->getSerializedConditions())->setPerCustomerUsageCount($couponModel->getPerCustomerUsageCount());
                 $orderCoupon->save();
                 // Copy order coupon free shipping data for countries and modules
                 $couponCountries = CouponCountryQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponCountry $couponCountry */
                 foreach ($couponCountries as $couponCountry) {
                     $occ = new OrderCouponCountry();
                     $occ->setCouponId($orderCoupon->getId())->setCountryId($couponCountry->getCountryId())->save();
                 }
                 $couponModules = CouponModuleQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponModule $couponModule */
                 foreach ($couponModules as $couponModule) {
                     $ocm = new OrderCouponModule();
                     $ocm->setCouponId($orderCoupon->getId())->setModuleId($couponModule->getModuleId())->save();
                 }
             }
             $con->commit();
         } catch (\Exception $ex) {
             $con->rollBack();
             throw $ex;
         }
     }
     // Clear all coupons.
     $event->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
 }
 public function set_address(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         $event->setDeliveryAddress(null);
     }
 }
Exemplo n.º 23
0
 public function checkStockForAdmin(OrderEvent $event)
 {
     $order = $event->getOrder();
     $config = StockAlert::getConfig();
     $pseIds = [];
     foreach ($order->getOrderProducts() as $orderProduct) {
         $pseIds[] = $orderProduct->getProductSaleElementsId();
     }
     if ($config['enabled']) {
         $threshold = $config['threshold'];
         $productIds = ProductQuery::create()->useProductSaleElementsQuery()->filterById($pseIds, Criteria::IN)->filterByQuantity($threshold, Criteria::LESS_EQUAL)->filterByWeight(0, Criteria::NOT_EQUAL)->endUse()->select('Id')->find()->toArray();
         if (!empty($productIds)) {
             $this->sendEmailForAdmin($config['emails'], $productIds);
         }
     }
 }
Exemplo n.º 24
0
 /**
  * Cancels order coupons usage when order is canceled or refunded,
  * or use canceled coupons again if the order is no longer canceled or refunded
  *
  * @param OrderEvent $event
  * @param string $eventName
  * @param EventDispatcherInterface $dispatcher
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function orderStatusChange(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     // The order has been canceled or refunded ?
     if ($event->getOrder()->isCancelled() || $event->getOrder()->isRefunded()) {
         // Cancel usage of all coupons for this order
         $usedCoupons = OrderCouponQuery::create()->filterByUsageCanceled(false)->findByOrderId($event->getOrder()->getId());
         $customerId = $event->getOrder()->getCustomerId();
         /** @var OrderCoupon $usedCoupon */
         foreach ($usedCoupons as $usedCoupon) {
             if (null !== ($couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode()))) {
                 // If the coupon still exists, restore one usage to the usage count.
                 $this->couponManager->incrementQuantity($couponModel, $customerId);
             }
             // Mark coupon usage as canceled in the OrderCoupon table
             $usedCoupon->setUsageCanceled(true)->save();
         }
     } else {
         // Mark canceled coupons for this order as used again
         $usedCoupons = OrderCouponQuery::create()->filterByUsageCanceled(true)->findByOrderId($event->getOrder()->getId());
         $customerId = $event->getOrder()->getCustomerId();
         /** @var OrderCoupon $usedCoupon */
         foreach ($usedCoupons as $usedCoupon) {
             if (null !== ($couponModel = CouponQuery::create()->findOneByCode($usedCoupon->getCode()))) {
                 // If the coupon still exists, mark the coupon as used
                 $this->couponManager->decrementQuantity($couponModel, $customerId);
             }
             // The coupon is no longer canceled
             $usedCoupon->setUsageCanceled(false)->save();
         }
     }
 }
Exemplo n.º 25
0
 public function updateDeliveryAddress(OrderEvent $event)
 {
     if ($this->check_module($event->getOrder()->getDeliveryModuleId())) {
         $request = $this->getRequest();
         $tmp_address = AddressIcirelaisQuery::create()->findPk($request->getSession()->get('DpdPickupDeliveryId'));
         if ($tmp_address === null) {
             throw new \ErrorException("Got an error with DpdPickup module. Please try again to checkout.");
         }
         $savecode = new OrderAddressIcirelais();
         $savecode->setId($event->getOrder()->getDeliveryOrderAddressId())->setCode($tmp_address->getCode())->save();
         $update = OrderAddressQuery::create()->findPK($event->getOrder()->getDeliveryOrderAddressId())->setCompany($tmp_address->getCompany())->setAddress1($tmp_address->getAddress1())->setAddress2($tmp_address->getAddress2())->setAddress3($tmp_address->getAddress3())->setZipcode($tmp_address->getZipcode())->setCity($tmp_address->getCity())->save();
         $tmp_address->delete();
     }
 }
Exemplo n.º 26
0
 public function processUpdateOrders(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() == $this->shoppingFluxPaymentModuleId) {
         $status = $event->getStatus();
         $allowedStatus = [$sentStatusId = OrderStatusQuery::getSentStatus()->getId(), OrderStatusQuery::getCancelledStatus()->getId()];
         if (in_array($status, $allowedStatus)) {
             $order = $event->getOrder();
             $mode = ShoppingFluxConfigQuery::getProd() ? UpdateOrders::REQUEST_MODE_PRODUCTION : UpdateOrders::REQUEST_MODE_SANDBOX;
             $api = new UpdateOrders(ShoppingFluxConfigQuery::getToken(), $mode);
             $request = new Request("UpdateOrders");
             $request->addOrder(["IdOrder" => $order->getRef(), "Marketplace" => $order->getTransactionRef(), "Status" => $status === $sentStatusId ? "Shipped" : "Canceled"]);
             $response = $api->setRequest($request)->getResponse();
             if ($response->isInError()) {
                 $this->logger->error($response->getFormattedError());
             }
             if (!$api->compareResponseRequest()) {
                 $errorMessage = "Bad response from ShoppingFlux: " . $response->getGroup("UpdateOrders")->C14N();
                 $this->logger->error($errorMessage);
             }
         }
     }
 }
Exemplo n.º 27
0
 public function updateDeliveryAddress(OrderEvent $event)
 {
     if ($this->check_module($event->getOrder()->getDeliveryModuleId())) {
         $request = $this->getRequest();
         if ($request->getSession()->get('SoColissimoDomicile') == 1) {
             $tmp_address = AddressSoColissimoQuery::create()->findPk($request->getSession()->get('SoColissimoDeliveryId'));
             if ($tmp_address === null) {
                 throw new \ErrorException("Got an error with So Colissimo module. Please try again to checkout.");
             }
             $savecode = new OrderAddressSocolissimo();
             $savecode->setId($event->getOrder()->getDeliveryOrderAddressId())->setCode(0)->setType($tmp_address->getType())->save();
             $update = OrderAddressQuery::create()->findPK($event->getOrder()->getDeliveryOrderAddressId())->setCompany($tmp_address->getCompany())->setAddress1($tmp_address->getAddress1())->setAddress2($tmp_address->getAddress2())->setAddress3($tmp_address->getAddress3())->setZipcode($tmp_address->getZipcode())->setCity($tmp_address->getCity())->save();
         } elseif ($request->getSession()->get('SoColissimoRdv') == 1) {
             $tmp_address = AddressSoColissimoQuery::create()->findPk($request->getSession()->get('SoColissimoDeliveryId'));
             if ($tmp_address === null) {
                 throw new \ErrorException("Got an error with So Colissimo module. Please try again to checkout.");
             }
             $savecode = new OrderAddressSocolissimo();
             $savecode->setId($event->getOrder()->getDeliveryOrderAddressId())->setCode(0)->setType($tmp_address->getType())->save();
             $update = OrderAddressQuery::create()->findPK($event->getOrder()->getDeliveryOrderAddressId())->setCompany($tmp_address->getCompany())->setAddress1($tmp_address->getAddress1())->setAddress2($tmp_address->getAddress2())->setAddress3($tmp_address->getAddress3())->setZipcode($tmp_address->getZipcode())->setCity($tmp_address->getCity())->setPhone($tmp_address->getCellphone())->save();
         } else {
             $tmp_address = AddressSoColissimoQuery::create()->findPk($request->getSession()->get('SoColissimoDeliveryId'));
             if ($tmp_address === null) {
                 throw new \ErrorException("Got an error with So Colissimo module. Please try again to checkout.");
             }
             $savecode = new OrderAddressSocolissimo();
             $savecode->setId($event->getOrder()->getDeliveryOrderAddressId())->setCode($tmp_address->getCode())->setType($tmp_address->getType())->save();
             $update = OrderAddressQuery::create()->findPK($event->getOrder()->getDeliveryOrderAddressId())->setCompany($tmp_address->getCompany())->setAddress1($tmp_address->getAddress1())->setAddress2($tmp_address->getAddress2())->setAddress3($tmp_address->getAddress3())->setZipcode($tmp_address->getZipcode())->setCity($tmp_address->getCity())->save();
         }
     }
 }