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);
         }
     }
 }
 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);
     }
 }
示例#3
0
 /**
  * @param  OrderEvent                                     $event
  * @throws \Thelia\Form\Exception\FormValidationException
  */
 public function cellphoneCheck(OrderEvent $event)
 {
     if (Predict::getModuleId() === $event->getDeliveryModule()) {
         $cellphone = $this->request->request->get("predict_cellphone");
         $cellphone = str_replace(array(' ', '.', '-', ',', ';', '/', '\\', '(', ')'), '', $cellphone);
         $partial_number = "";
         if (empty($cellphone) || !preg_match('#^[0|\\+33][6-7]([0-9]{8})$#', $cellphone, $partial_number)) {
             throw new FormValidationException(Translator::getInstance()->trans("You must give a cellphone number in order to use Predict services", [], Predict::MESSAGE_DOMAIN));
         }
         $cellphone = str_replace("+33", "0", $cellphone);
         $banned_cellphones = array('00000000', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678', '23456789', '98765432');
         if (in_array($partial_number[1], $banned_cellphones)) {
             throw new FormValidationException(Translator::getInstance()->trans("This phone number is not valid", [], Predict::MESSAGE_DOMAIN));
         }
         /** @var \Thelia\Model\Customer $customer */
         $customer = $this->getRequest()->getSession()->getCustomerUser();
         $address = $customer->getDefaultAddress();
         $addressEvent = new AddressCreateOrUpdateEvent($address->getLabel(), $address->getTitleId(), $address->getFirstname(), $address->getLastname(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $address->getCountryId(), $cellphone, $address->getPhone(), $address->getCompany());
         $addressEvent->setAddress($address);
         $dispatcher = $event->getDispatcher();
         $dispatcher->dispatch(TheliaEvents::ADDRESS_UPDATE, $addressEvent);
     }
 }
 /**
  * @param  OrderEvent $event
  * @throws \Exception
  */
 public function update_address(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         $address_id = $event->getOrder()->getDeliveryOrderAddressId();
         $address = OrderAddressQuery::create()->findPk($address_id);
         if ($address !== null) {
             $config = new ConfigQuery();
             $address1 = $config->read("store_address1");
             $address2 = $config->read("store_address2");
             $address3 = $config->read("store_address3");
             $zipcode = $config->read("store_zipcode");
             $city = $config->read("store_city");
             $country = $config->read("store_country");
             $name = $config->read("store_name");
             if ($address1 !== null && $zipcode !== null && $city !== null && $country !== null) {
                 $address_event = new OrderAddressEvent($address->getCustomerTitleId(), $address->getFirstname(), $address->getLastname(), $address1, $address2, $address3, $zipcode, $city, $country, $address->getPhone(), $name);
                 $address_event->setOrderAddress($address);
                 $event->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_ADDRESS, $address_event);
             }
         } else {
             throw new \Exception("Error: order deliery address doesn't exists");
         }
     }
 }
示例#5
0
 public function setModuleDelivery(OrderEvent $event)
 {
     if ($event->getDeliveryModule() == TNTFrance::getModuleId()) {
         $request = $this->getRequest();
         $id = $request->getSession()->getSessionCart()->getId();
         $address = TNTFrance::getCartDeliveryAddress($this->getRequest());
         $data = TNTFrance::getExtraOrderData($id);
         try {
             $this->saveExtraInformation($data, $event->getOrder(), $address);
             //We must recalcul postage when this informations are saved :(
             if (array_key_exists('tnt_serviceCode', $data)) {
                 $cartEvent = new CartEvent($this->getRequest()->getSession()->getSessionCart($event->getDispatcher()));
                 $event->getDispatcher()->dispatch(OrderAction::TNT_CALCUL_CART_WEIGHT, $cartEvent);
                 $postage = TNTFrance::calculPriceForService($data['tnt_serviceCode'], $cartEvent->getCart()->getVirtualColumn('total_package'), $cartEvent->getCart()->getVirtualColumn('total_weight'));
                 $event->getOrder()->setPostage($postage);
                 $event->setPostage($postage);
             }
         } catch (\Exception $ex) {
             throw $ex;
         }
         TNTFrance::setExtraOrderData($id, $data);
     }
 }
示例#6
0
文件: Order.php 项目: badelas/thelia
 /**
  * Clear the cart and the order in the customer session once the order is placed,
  * and the payment performed.
  *
  * @param OrderEvent $event
  */
 public function orderCartClear(OrderEvent $event)
 {
     // Empty cart and clear current order
     $session = $this->getSession();
     $session->clearSessionCart($event->getDispatcher());
     $session->setOrder(new OrderModel());
 }
示例#7
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);
 }
 /**
  * Set paid status to the order
  * @param OrderEvent $orderEvent
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function changeOrderStatus(OrderEvent $orderEvent)
 {
     $paidStatusId = OrderStatusQuery::create()->filterByCode('paid')->select('ID')->findOne();
     $event = new OrderEvent($orderEvent->getPlacedOrder());
     $event->setStatus($paidStatusId);
     $orderEvent->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
 }
示例#9
0
 /**
  * @param OrderEvent $event
  *
  * @throws \Thelia\Exception\TheliaProcessException
  */
 public function create(OrderEvent $event)
 {
     $session = $this->getSession();
     $placedOrder = $this->createOrder($event->getDispatcher(), $event->getOrder(), $session->getCurrency(), $session->getLang(), $session->getCart(), $this->securityContext->getCustomerUser());
     $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
     /* but memorize placed order */
     $event->setOrder(new \Thelia\Model\Order());
     $event->setPlacedOrder($placedOrder);
     /* empty cart */
     $dispatcher = $event->getDispatcher();
     /* call pay method */
     $payEvent = new OrderPaymentEvent($placedOrder);
     $dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);
     if ($payEvent->hasResponse()) {
         $event->setResponse($payEvent->getResponse());
     }
 }
示例#10
0
 /**
  * @depends testCreate
  *
  * @param OrderModel $order
  */
 public function testCreateManual(OrderModel $order)
 {
     $orderCopy = $order->copy();
     $validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
     $validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
     $orderManuelEvent = new OrderManualEvent($orderCopy, $this->cart->getCurrency(), $this->request->getSession()->getLang(), $this->cart, $this->customer);
     $orderManuelEvent->setDispatcher($this->orderEvent->getDispatcher());
     $orderManuelEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
     $orderManuelEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
     $deliveryModuleId = $orderCopy->getDeliveryModuleId();
     $paymentModuleId = $orderCopy->getPaymentModuleId();
     $this->orderAction->createManual($orderManuelEvent);
     $placedOrder = $orderManuelEvent->getPlacedOrder();
     $this->assertNotNull($placedOrder);
     $this->assertNotNull($placedOrder->getId());
     /* check customer */
     $this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not  match');
     /* check delivery address */
     $deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
     $this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
     $this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
     $this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
     $this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
     $this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
     $this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
     $this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
     $this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
     $this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
     /* check invoice address */
     $invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
     $this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
     $this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
     $this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
     $this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
     $this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
     $this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
     $this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
     $this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
     $this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
     /* check currency */
     $this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not  match');
     $this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not  match');
     /* check delivery module */
     $this->assertEquals(20, $placedOrder->getPostage(), 'postage does not  match');
     $this->assertEquals($deliveryModuleId, $placedOrder->getDeliveryModuleId(), 'delivery module does not  match');
     /* check payment module */
     $this->assertEquals($paymentModuleId, $placedOrder->getPaymentModuleId(), 'payment module does not  match');
     /* check status */
     $this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not  match');
     /* check lang */
     $this->assertEquals($this->request->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not  match');
     // without address duplication
     $copyOrder = $order->copy();
     $orderManuelEvent->setOrder($copyOrder)->setUseOrderDefinedAddresses(true);
     $validDeliveryAddressId = $orderCopy->getDeliveryOrderAddressId();
     $validInvoiceAddressId = $orderCopy->getInvoiceOrderAddressId();
     $this->orderAction->createManual($orderManuelEvent);
     $placedOrder = $orderManuelEvent->getPlacedOrder();
     $this->assertNotNull($placedOrder);
     $this->assertNotNull($placedOrder->getId());
     /* check delivery address */
     $deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
     $this->assertEquals($validDeliveryAddressId, $deliveryOrderAddress->getId(), 'delivery address title does not match');
     /* check invoice address */
     $invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
     $this->assertEquals($validInvoiceAddressId, $invoiceOrderAddress->getId(), 'invoice address title does not match');
     return $placedOrder;
 }