Beispiel #1
0
 /**
  * Remove temporary order
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return void
  */
 protected function removeTemporaryOrder(\XLite\Model\Order $order)
 {
     foreach ($order->getItems() as $item) {
         foreach ($item->getPinCodes() as $pin) {
             \XLite\Core\Database::getEM()->remove($pin);
         }
     }
     parent::removeTemporaryOrder($order);
 }
Beispiel #2
0
 /**
  * A "change status" handler
  *
  * @return void
  */
 protected function processProcess()
 {
     foreach ($this->getPrivateAttachments() as $attachment) {
         $attachment->renew();
     }
     parent::processProcess();
 }
Beispiel #3
0
 /**
  * Exclude Express Checkout from the list of available for checkout payment methods
  * if Payflow Link or Paypal Advanced are avavilable
  * 
  * @return array
  */
 public function getPaymentMethods()
 {
     $list = parent::getPaymentMethods();
     $transaction = $this->getFirstOpenPaymentTransaction();
     $paymentMethod = $transaction ? $transaction->getPaymentMethod() : null;
     if (!isset($paymentMethod) || !$this->isExpressCheckout($paymentMethod)) {
         $expressCheckoutKey = null;
         $found = false;
         foreach ($list as $k => $method) {
             if ($this->isExpressCheckout($method)) {
                 $expressCheckoutKey = $k;
             }
             if (in_array($method->getServiceName(), array('PayflowLink', 'PaypalAdvanced'))) {
                 $found = true;
             }
             if (isset($expressCheckoutKey) && $found) {
                 break;
             }
         }
         if (isset($expressCheckoutKey) && $found) {
             unset($list[$expressCheckoutKey]);
         }
     }
     return $list;
 }
Beispiel #4
0
 /**
  * Increase / decrease item product inventory
  *
  * @param \XLite\Model\OrderItem $item Order item
  * @param integer                $sign Flag; "1" or "-1"
  *
  * @return void
  */
 protected function changeItemInventory($item, $sign)
 {
     $amount = parent::changeItemInventory($item, $sign);
     if ((bool) $item->getVariant()) {
         $history = \XLite\Core\OrderHistory::getInstance();
         $history->registerChangeVariantAmount($this->getOrderId(), $item->getVariant(), $amount);
     }
 }
Beispiel #5
0
 /**
  * Add item to order
  *
  * @param \XLite\Model\OrderItem $newItem Item to add
  *
  * @return boolean
  */
 public function addItem(\XLite\Model\OrderItem $newItem)
 {
     $result = parent::addItem($newItem);
     if ($result && $newItem->isValid()) {
         $minQuantity = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Wholesale\\Model\\MinQuantity')->getMinQuantity($newItem->getProduct(), $this->getProfile() ? $this->getProfile()->getMembership() : null);
         if ($minQuantity && $newItem->getAmount() < $minQuantity->getQuantity()) {
             $newItem->setAmount($minQuantity->getQuantity());
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Restore order
  *
  * @return void
  */
 protected function restoreOrder()
 {
     \XLite\Core\Session::getInstance()->checkoutCanceled = true;
     $this->doActionAddOrder();
     if ($this->addedOrder && !$this->addedOrder instanceof \XLite\Model\Cart && !\XLite\Core\Auth::getInstance()->isLogged()) {
         $cart = $this->getCart();
         $profile = $this->addedOrder->getProfile()->cloneEntity();
         $profile->setOrder($cart);
         $profile->setAnonymous(true);
         $cart->setOrigProfile($this->addedOrder->getOrigProfile());
         $cart->setProfile($profile);
         $this->updateCart();
     }
     $this->setReturnURL($this->buildURL('checkout'));
 }
Beispiel #7
0
 /**
  * Add order surcharge
  *
  * @param string  $code      Surcharge code
  * @param float   $value     Value
  * @param boolean $include   Include flag OPTIONAL
  * @param boolean $available Availability flag OPTIONAL
  *
  * @return \XLite\Model\Order\Surcharge
  */
 protected function addOrderSurcharge($code, $value, $include = false, $available = true)
 {
     $surcharge = new \XLite\Model\Order\Surcharge();
     $surcharge->setType($this->type);
     $surcharge->setCode($code);
     $surcharge->setValue($value);
     $surcharge->setInclude($include);
     $surcharge->setAvailable($available);
     $surcharge->setClass(get_called_class());
     $info = $this->getSurchargeInfo($surcharge);
     $surcharge->setName($info->name);
     $this->order->getSurcharges()->add($surcharge);
     $surcharge->setOwner($this->order);
     return $surcharge;
 }
Beispiel #8
0
 /**
  * Get Kount data
  *
  * @return object
  */
 public function getKountData(\XLite\Model\Order $order)
 {
     if (!isset($this->kountData[$order->getOrderId()])) {
         $this->kountData[$order->getOrderId()] = false;
         $transactions = $order->getPaymentTransactions();
         foreach ($transactions as $transaction) {
             if ($transaction->getDataCell('xpc_kount') && $transaction->getDataCell('xpc_kount')->getValue()) {
                 $this->kountData[$order->getOrderId()] = unserialize($transaction->getDataCell('xpc_kount')->getValue());
                 break;
             }
         }
     }
     return $this->kountData[$order->getOrderId()];
 }
Beispiel #9
0
 /**
  * Check inventory
  *
  * @throws \Doctrine\ORM\OptimisticLockException
  *
  * @return boolean
  */
 public function checkInventory()
 {
     parent::checkInventory();
     $newStatus = $this->getPaymentStatusCode();
     $oldStatus = $this->oldPaymentStatus && $this->oldPaymentStatus->getCode() ? $this->oldPaymentStatus->getCode() : '';
     $paidStatuses = \XLite\Model\Order\Status\Payment::getPaidStatuses();
     if ($newStatus) {
         $delta = null;
         if (in_array($newStatus, $paidStatuses) && (!$oldStatus || !in_array($oldStatus, $paidStatuses))) {
             $delta = 1;
         } elseif (!in_array($newStatus, $paidStatuses) && $oldStatus && in_array($oldStatus, $paidStatuses)) {
             $delta = -1;
         }
         if (null !== $delta) {
             foreach ($this->getItems() as $item) {
                 $product = $item->getObject();
                 if ($product) {
                     $product->setSales($product->getSales() + $delta * $item->getAmount());
                 }
             }
             \XLite\Core\Database::getEM()->flush();
         }
     }
 }
Beispiel #10
0
 /**
  * Common method to update cart/order
  *
  * @return void
  */
 public function updateOrder()
 {
     parent::updateOrder();
     $this->renewCapostOffice();
 }
Beispiel #11
0
 /**
  * Return true if item amount limit is reached
  *
  * @param \XLite\Model\OrderItem $item Order item
  *
  * @return boolean
  */
 protected function isItemLimitReached($item)
 {
     $result = false;
     $product = $item->getObject();
     if ($product && $product->mustHaveVariants()) {
         $variant = $item->getVariant();
         $result = $variant && $variant->getAmount() <= $item->getAmount();
     } else {
         $result = parent::isItemLimitReached($item);
     }
     return $result;
 }
Beispiel #12
0
 /**
  * Do Recharge the difference request.
  * Returns false on failure or redirects admin back to the order page
  * the necessary actions with the backend transaction are taken in the
  * Callback request processing
  *
  * @param \XLite\Model\Order $order Order which is recharged
  * @param \XLite\Model\Payment\Transaction $parentCardTransaction Trandaction with saved card
  * @param float $amount Amount to recharge
  *
  * @return boolean
  */
 public function doRecharge(\XLite\Model\Order $order, \XLite\Model\Payment\Transaction $parentCardTransaction, $amount)
 {
     $newTransaction = new \XLite\Model\Payment\Transaction();
     $newTransaction->setPaymentMethod($this->getSavedCardsPaymentMethod());
     $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_INPROGRESS);
     $newTransaction->setDataCell('is_recharge', 'Y', null, 'C');
     $newTransaction->setValue($amount);
     $order->addPaymentTransactions($newTransaction);
     $newTransaction->setOrder($order);
     foreach ($this->paymentSettingsToSave as $field) {
         $key = 'xpc_can_do_' . $field;
         if ($parentCardTransaction->getDataCell($key) && $parentCardTransaction->getDataCell($key)->getValue()) {
             $newTransaction->setDataCell($key, $parentCardTransaction->getDataCell($key)->getValue(), null, 'C');
         }
     }
     $this->copyMaskedCard($parentCardTransaction, $newTransaction);
     $recharge = $this->client->requestPaymentRecharge($parentCardTransaction->getDataCell('xpc_txnid')->getValue(), $newTransaction);
     if ($recharge->isSuccess()) {
         $response = $recharge->getResponse();
         if (self::STATUS_AUTH == $response['status'] || self::STATUS_CHARGED == $response['status']) {
             \XLite\Core\TopMessage::getInstance()->addInfo($response['message'] ? $response['message'] : 'Operation successfull');
             if ($response['transaction_id']) {
                 $newTransaction->setDataCell('xpc_txnid', $response['transaction_id'], 'X-Payments transaction ID', 'C');
             }
         } else {
             \XLite\Core\TopMessage::getInstance()->addError($response['error'] ? $response['error'] : 'Operation failed');
             $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
         }
     } else {
         $message = 'Operation failed';
         if ($recharge->getError()) {
             $message .= '. ' . $recharge->getError();
         }
         \XLite\Core\TopMessage::getInstance()->addError($message);
         $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
     }
     \XLite\Core\Database::getEM()->flush();
 }
Beispiel #13
0
 /**
  * Check - payment type is allowed for specified order or not
  *
  * @param string             $type  Payment type
  * @param \XLite\Model\Order $order Order
  *
  * @return boolean
  */
 protected function isPaymentTypeAllowed($type, \XLite\Model\Order $order)
 {
     $result = isset($this->paymentTypeCountries[$type]) && $order->getProfile() && $order->getProfile()->getBillingAddress() && $order->getProfile()->getBillingAddress()->getCountry();
     if ($result && true !== $this->paymentTypeCountries[$type]) {
         $result = in_array($order->getProfile()->getBillingAddress()->getCountry()->getCode3(), $this->paymentTypeCountries[$type]);
     }
     return $result;
 }
Beispiel #14
0
 /**
  * Get the errors related to categories of products in order
  *
  * @param \XLite\Model\Order $order
  *
  * @return array
  */
 protected function getCategoryErrors(\XLite\Model\Order $order)
 {
     $found = true;
     // Categories
     if (0 < count($this->getCategories())) {
         $found = false;
         foreach ($order->getItems() as $item) {
             foreach ($item->getProduct()->getCategories() as $cat) {
                 if ($this->getCategories()->contains($cat)) {
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 break;
             }
         }
     }
     return $found ? array() : array(static::ERROR_CATEGORY);
 }
Beispiel #15
0
 /**
  * A "change status" handler
  *
  * @return void
  */
 protected function processUncheckout()
 {
     parent::processUncheckout();
     foreach ($this->getUsedCoupons() as $usedCoupons) {
         $usedCoupons->unmarkAsUsed();
     }
 }
Beispiel #16
0
 /**
  * Return default options list
  *
  * @return array
  */
 protected function getDefaultOptions()
 {
     $list = \XLite\Model\Order::getAllowedStatuses();
     unset($list[\XLite\Model\Order::STATUS_TEMPORARY]);
     unset($list[\XLite\Model\Order::STATUS_INPROGRESS]);
     foreach ($list as $k => $v) {
         $list[$k] = static::t($v);
     }
     return $list;
 }
Beispiel #17
0
 /**
  * Check coupon product class
  *
  * @param \XLite\Model\Order $order Order
  *
  * @throws \XLite\Module\CDev\Coupons\Core\CompatibilityException
  *
  * @return void
  */
 protected function checkProductClass(\XLite\Model\Order $order)
 {
     if ($this->getProductClasses()->count()) {
         $found = false;
         foreach ($order->getItems() as $item) {
             if ($item->getProduct()->getProductClass() && $this->getProductClasses()->contains($item->getProduct()->getProductClass())) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $this->throwCompatibilityException('', 'There is no such a coupon, please check the spelling: X', array('code' => $this->getCode()));
         }
     }
 }
Beispiel #18
0
 /**
  * Check - order's profile removed or not
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return boolean
  */
 protected function isProfileRemoved(\XLite\Model\Order $order)
 {
     return !$order->getOrigProfile() || $order->getOrigProfile()->getOrder();
 }
Beispiel #19
0
 /**
  * Get discount amount
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return float
  */
 public function getAmount(\XLite\Model\Order $order)
 {
     $discount = $this->isAbsolute() ? $this->getValue() : $order->getSubtotal() * $this->getValue() / 100;
     return min($discount, $order->getSubtotal());
 }
Beispiel #20
0
 /**
  * Get items sum quantity
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return integer
  */
 protected function getItemsQuantity(\XLite\Model\Order $order)
 {
     return $order->countQuantity();
 }
Beispiel #21
0
 /**
  * Get used coupon by id
  *
  * @param \XLite\Model\Order $cart Cart
  * @param integer            $id   Used coupon id
  *
  * @return \XLite\Module\CDev\Coupons\Model\UsedCoupon
  */
 protected function getUsedCoupon($cart, $id)
 {
     return array_reduce($cart->getUsedCoupons()->toArray(), function ($carry, $item) use($id) {
         return $carry ?: ($item->getId() === $id ? $item : null);
     }, null);
 }
Beispiel #22
0
 /**
  * Called when an order successfully placed by a client
  *
  * @return void
  */
 public function processSucceed()
 {
     parent::processSucceed();
     if ($this->isPitneyBowesSelected() && $this->getPbOrder()) {
         $this->createOrderHistoryEvent($this->getPbOrder());
         $this->confirmOrderApiCall();
     }
 }
Beispiel #23
0
 /**
  * Prepare shopping cart data
  *
  * @param \XLite\Model\Order            $cart           X-Cart shopping cart
  * @param \XLite\Model\Payment\Method   $paymentMethod  Payment method
  * @param integer                       $refId          Transaction ID OPTIONAL
  * @param boolean                       $forceAuth      Force enable AUTH mode OPTIONAL
  *
  * @return array
  */
 public function prepareCart(\XLite\Model\Order $cart, \XLite\Model\Payment\Method $paymentMethod, $refId = null, $forceAuth = false)
 {
     $config = \XLite\Core\Config::getInstance()->CDev->XPaymentsConnector;
     $profile = $cart->getProfile();
     if ($cart->getOrderNumber()) {
         $description = 'Order #' . $cart->getOrderNumber();
     } elseif ($cart->getFirstOpenPaymentTransaction() && $cart->getFirstOpenPaymentTransaction()->getPublicId()) {
         $description = 'Payment transaction: ' . $cart->getFirstOpenPaymentTransaction()->getPublicId();
     } else {
         $description = '';
     }
     $result = array('login' => $profile->getLogin() . ' (User ID #' . $profile->getProfileId() . ')', 'items' => array(), 'currency' => $this->getCurrencyCode($paymentMethod), 'shippingCost' => 0.0, 'taxCost' => 0.0, 'discount' => 0.0, 'totalCost' => 0.0, 'description' => $description, 'merchantEmail' => \XLite\Core\Config::getInstance()->Company->orders_department, 'forceTransactionType' => $forceAuth ? 'A' : '');
     // Send customer unique Id for Kount UNIQ field (API v1.6 and higher)
     if (version_compare($config->xpc_api_version, '1.6') >= 0) {
         $result['kountCustomerUniq'] = $this->getKountCustomerUniq($cart);
     }
     $result['billingAddress'] = $this->prepareAddress($profile);
     if ($profile->getShippingAddress()) {
         $result['shippingAddress'] = $this->prepareAddress($profile, 'shipping');
     } else {
         $result['shippingAddress'] = $result['billingAddress'];
     }
     // Set items
     if ($cart->getItems()) {
         foreach ($cart->getItems() as $item) {
             $itemElement = array('sku' => strval($item->getSku() ? $item->getSku() : $item->getName()), 'name' => strval($item->getName() ? $item->getName() : $item->getSku()), 'price' => $this->roundCurrency($item->getPrice()), 'quantity' => $item->getAmount());
             if (!$itemElement['sku']) {
                 $itemElement['sku'] = 'N/A';
             }
             if (!$itemElement['name']) {
                 $itemElement['name'] = 'N/A';
             }
             $result['items'][] = $itemElement;
         }
     }
     // Set costs
     $result['shippingCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, false));
     $result['taxCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_TAX, false));
     $result['totalCost'] = $this->roundCurrency($cart->getTotal());
     $result['discount'] = $this->roundCurrency(abs($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_DISCOUNT, false)));
     return $result;
 }
Beispiel #24
0
 /**
  * Prepare order before remove operation
  *
  * @return void
  * @PreRemove
  */
 public function prepareBeforeRemove()
 {
     parent::prepareBeforeRemove();
     unset(\XLite\Core\Session::getInstance()->order_id);
 }
Beispiel #25
0
 /**
  * Check if the re-order button is shown
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return boolean
  */
 protected function showReorder(\XLite\Model\Order $order)
 {
     $items = $order->getItems();
     return (bool) \Includes\Utils\ArrayManager::findValue($items, array($this, 'checkIsAvailableToOrder'), false);
 }
Beispiel #26
0
 /**
  * Process coupons 
  * 
  * @param \XLite\Model\Order $order Order
  *  
  * @return void
  */
 protected function processCoupons(\XLite\Model\Order $order)
 {
     $request = \XLite\Core\Request::getInstance();
     // Remove coupon
     foreach ($order->getUsedCoupons() as $coupon) {
         $hash = md5($coupon->getCode());
         if ($coupon->getCode() && !empty($request->removeCoupons[$hash])) {
             // Register order change
             static::setOrderChanges('Removed coupons:' . $coupon->getId(), $coupon->getCode());
             // Remove used coupon from order
             $order->getUsedCoupons()->removeElement($coupon);
             \XLite\Core\Database::getEM()->remove($coupon);
         }
     }
     // Add coupon
     if (!empty($request->newCoupon) && is_array($request->newCoupon)) {
         foreach ($request->newCoupon as $code) {
             if ($code) {
                 $coupon = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Coupons\\Model\\Coupon')->findOneByCode($code);
                 if ($coupon) {
                     $usedCoupon = new \XLite\Module\CDev\Coupons\Model\UsedCoupon();
                     $usedCoupon->setOrder($order);
                     $order->addUsedCoupons($usedCoupon);
                     $usedCoupon->setCoupon($coupon);
                     $coupon->addUsedCoupons($usedCoupon);
                     \XLite\Core\Database::getEM()->persist($usedCoupon);
                     // Register order change
                     static::setOrderChanges('Added coupons:' . $coupon->getId(), $coupon->getCode());
                 }
             }
         }
     }
 }
Beispiel #27
0
 /**
  * Get shipping cost for set express checkout
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return float
  */
 protected function getShippingCost($order)
 {
     $result = null;
     $shippingModifier = $order->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING');
     if ($shippingModifier && $shippingModifier->canApply()) {
         /** @var \XLite\Model\Currency $currency */
         $currency = $order->getCurrency();
         $result = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_SHIPPING));
     }
     return $result;
 }
Beispiel #28
0
 /**
  * Check - payment processor is applicable for specified order or not
  *
  * @param \XLite\Model\Order          $order  Order
  * @param \XLite\Model\Payment\Method $method Payment method
  *
  * @return boolean
  */
 public function isApplicable(\XLite\Model\Order $order, \XLite\Model\Payment\Method $method)
 {
     $controller = \XLite::getController();
     return $order->getProfile() && $order->getProfile()->getSavedCards() && method_exists($controller, 'isLogged') && $controller->isLogged() && parent::isApplicable($order, $method);
 }
Beispiel #29
0
 /**
  * getValue
  *
  * @return string
  */
 public function getValue()
 {
     return \XLite\Model\Order::getAllowedStatuses(parent::getValue());
 }
Beispiel #30
0
 /**
  * Mark cart as order
  *
  * @return void
  */
 public function markAsOrder()
 {
     parent::markAsOrder();
     if ($this instanceof \XLite\Model\Cart) {
         $this->assignOrderNumber();
     }
     $this->getRepository()->markAsOrder($this->getOrderId());
 }