/** * 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); } }
/** * Register transaction in order history * * @param string $suffix Suffix text to add to the end of event description * * @return \XLite\Model\Payment\BackendTransaction */ public function registerTransactionInOrderHistory($suffix = null) { $descrSuffix = !empty($suffix) ? ' [' . static::t($suffix) . ']' : ''; \XLite\Core\OrderHistory::getInstance()->registerTransaction($this->getPaymentTransaction()->getOrder()->getOrderId(), static::t($this->getHistoryEventDescription(), $this->getHistoryEventDescriptionData()) . $descrSuffix, $this->getEventData()); return $this; }
/** * Increase / decrease item product inventory * * @param \XLite\Model\OrderItem $item Order item * @param integer $sign Flag; "1" or "-1" * * @return integer */ protected function changeItemInventory($item, $sign) { $history = \XLite\Core\OrderHistory::getInstance(); $amount = $this->getItemInventoryAmount($item, $sign); $history->registerChangeAmount($this->getOrderId(), $item->getProduct(), $amount); $item->changeAmount($amount); return $amount; }
/** * doActionUpdate * * @return void */ protected function doActionUpdate() { $changes = $this->getOrdersChanges(); $this->getItemsList()->processQuick(); foreach ($changes as $orderId => $change) { \XLite\Core\OrderHistory::getInstance()->registerOrderChanges($orderId, $change); } }
protected function placeAmazonOrder($payment_method_text) { $cart = $this->getCart(); if (isset(\XLite\Core\Request::getInstance()->notes)) { $cart->setNotes(\XLite\Core\Request::getInstance()->notes); } $cart->setDate(\XLite\Core\Converter::time()); $cart->assignOrderNumber(); $cart->setPaymentStatus(\XLite\Model\Order\Status\Payment::STATUS_QUEUED); $cart->setShippingStatus(\XLite\Model\Order\Status\Shipping::STATUS_NEW); // apply $payment_method_text payment method $_tmp_method = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findBy(array('service_name' => 'PayWithAmazon')); if ($_tmp_method) { $_tmp_method = $_tmp_method[0]; } else { // auto create it $_tmp_method = new \XLite\Model\Payment\Method(); $_tmp_method->setClass('Model\\Payment\\Processor\\Offline'); $_tmp_method->setServiceName('PayWithAmazon'); $_tmp_method->setName($payment_method_text); $_tmp_method->setModuleName('Amazon_PayWithAmazon'); } $this->getCart()->setPaymentMethod($_tmp_method); $this->getCart()->markAsOrder(); // $this->updateCart(); // old way produce fingerprint warning in logs $this->getCart()->updateOrder(); \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->update($this->getCart()); // Register 'Place order' event in the order history \XLite\Core\OrderHistory::getInstance()->registerPlaceOrder($this->getCart()->getOrderId()); \XLite\Core\Database::getEM()->flush(); return $this->getCart()->getOrderId(); }
/** * Checkout * TODO: to revise * * @return void */ protected function doActionCheckout() { $itemsBeforeUpdate = $this->getCart()->getItemsFingerprint(); $this->updateCart(); $itemsAfterUpdate = $this->getCart()->getItemsFingerprint(); if ($this->get('absence_of_product') || $this->getCart()->isEmpty() || $itemsAfterUpdate != $itemsBeforeUpdate) { // Cart is changed $this->set('absence_of_product', true); $this->redirect($this->buildURL('cart')); } elseif (!$this->checkCheckoutAction()) { // Check access $this->redirect($this->buildURL('checkout')); } else { $data = is_array(\XLite\Core\Request::getInstance()->payment) ? \XLite\Core\Request::getInstance()->payment : array(); $errors = array(); $firstOpenTransaction = $this->getCart()->getFirstOpenPaymentTransaction(); if ($firstOpenTransaction) { $errors = $firstOpenTransaction->getPaymentMethod()->getProcessor()->getInputErrors($data); } if ($errors) { foreach ($errors as $error) { \XLite\Core\TopMessage::addError($error); } $this->redirect($this->buildURL('checkout')); } else { // Register 'Place order' event in the order history \XLite\Core\OrderHistory::getInstance()->registerPlaceOrder($this->getCart()->getOrderId()); // Make order payment step $this->doPayment(); } } }
/** * Checkout * TODO: to revise * * @return void */ protected function doActionCheckout() { $itemsBeforeUpdate = $this->getCart()->getItemsFingerprint(); $this->updateCart(); $itemsAfterUpdate = $this->getCart()->getItemsFingerprint(); if ($itemsAfterUpdate !== $itemsBeforeUpdate || $this->get('absence_of_product') || $this->getCart()->isEmpty()) { // Cart is changed $this->set('absence_of_product', true); $this->redirect($this->buildURL('cart')); } elseif (!$this->checkCheckoutAction()) { // Check access $this->redirect($this->buildURL('checkout')); } else { $data = is_array(\XLite\Core\Request::getInstance()->payment) ? \XLite\Core\Request::getInstance()->payment : array(); $errors = array(); $firstOpenTransaction = $this->getCart()->getFirstOpenPaymentTransaction(); if ($firstOpenTransaction) { $errors = $firstOpenTransaction->getPaymentMethod()->getProcessor()->getInputErrors($data); } if ($errors) { foreach ($errors as $error) { \XLite\Core\TopMessage::addError($error); } $this->redirect($this->buildURL('checkout')); } else { $shippingMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findOneBy(array('method_id' => $this->getCart()->getShippingId())); if ($shippingMethod) { $this->getCart()->setShippingMethodName($shippingMethod->getName()); } else { $this->getCart()->setShippingMethodName(null); } // Register 'Place order' event in the order history \XLite\Core\OrderHistory::getInstance()->registerPlaceOrder($this->getCart()->getOrderId()); // Register 'Order packaging' event in the order history \XLite\Core\OrderHistory::getInstance()->registerOrderPackaging($this->getCart()->getOrderId(), $this->getCart()->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING')); $this->getCart()->setPaymentStatus(\XLite\Model\Order\Status\Payment::STATUS_QUEUED); $this->getCart()->decreaseInventory(); // Clean widget cache (for products lists widgets) \XLite\Core\WidgetCache::getInstance()->deleteAll(); // Make order payment step $this->doPayment(); } } }
/** * doActionUpdate * * @return void */ protected function doActionUpdate() { $changes = $this->getOrdersChanges(); $list = new \XLite\View\ItemsList\Model\Order\Admin\Search(); $list->processQuick(); foreach ($changes as $orderId => $change) { \XLite\Core\OrderHistory::getInstance()->registerOrderChanges($orderId, $change); } }
/** * @param \XLite\Module\XC\PitneyBowes\Model\PBOrder $pbOrder Pitney Bowes order model * @param mixed $confirmOrderResult ConfirmOrder api call result * * @return void */ protected function confirmOrderHistoryEvent(\XLite\Module\XC\PitneyBowes\Model\PBOrder $pbOrder, $confirmOrderResult) { \XLite\Core\OrderHistory::getInstance()->registerEvent($this->getOrderId(), 'PB_SHIPPING', 'PitneyBowes shipping order confirmed', array(), '', array(array('name' => 'Transaction ID', 'value' => $confirmOrderResult->transactionId), array('name' => 'Order ID', 'value' => $confirmOrderResult->orderId), array('name' => 'Result', 'value' => $confirmOrderResult->result))); }
/** * Quick process * * @param array $parameters Parameters OPTIONAL * * @return void */ public function processQuick(array $parameters = array()) { $data = \XLite\Core\Request::getInstance()->getData(); $new = $data[$this->getCreateDataPrefix()]; unset($new[0]); $update = isset($data[$this->getDataPrefix()]) ? $data[$this->getDataPrefix()] : array(); $delete = isset($data[$this->getRemoveDataPrefix()]) ? $data[$this->getRemoveDataPrefix()] : array(); // Prepare information about the added numbers $added = array(); foreach ($new as $id => $value) { if (!empty($value['value'])) { $added[$id] = $value['value']; } } // Prepare information about removed numbers (we remove them from the changed ones) $removed = array(); foreach ($delete as $id => $value) { $removed[$id] = $update[$id]['value']; unset($update[$id]); } // Prepare information about changed numbers $changed = array(); $repo = \XLite\Core\Database::getRepo('XLite\\Model\\OrderTrackingNumber'); foreach ($update as $id => $value) { $oldValue = $repo->find($id)->getValue(); if ($oldValue !== $value['value']) { $changed[$id] = array('old' => $oldValue, 'new' => $value['value']); } } if ($added || $removed || $changed) { \XLite\Core\OrderHistory::getInstance()->registerTrackingInfoUpdate($this->getOrder()->getOrderId(), $added, $removed, $changed); } parent::processQuick($parameters); }
/** * Register the change amount inventory * * @param integer $orderId Order identifier * @param \XLite\Model\Product $product Product object * @param integer $delta Inventory delta changes * * @return void */ public function registerChangeAmount($orderId, $product, $delta) { if (!$product->hasVariants()) { parent::registerChangeAmount($orderId, $product, $delta); } }
/** * Update staff note * * @return void */ protected function doActionUpdateStaffNote() { $notes = \XLite\Core\Request::getInstance()->adminNotes; if (is_array($notes)) { $notes = reset($notes); } $changes = array('old' => $this->getOrder()->getAdminNotes(), 'new' => $notes); \XLite\Core\OrderHistory::getInstance()->registerOrderChangeAdminNotes($this->getOrder()->getOrderId(), $changes); $this->getOrder()->setAdminNotes($notes); \XLite\Core\Database::getEM()->flush(); $this->restoreFormId(); }
/** * Send canceled order mail to Customer * * @param \XLite\Model\Order $order Order model * * @return void */ public static function sendOrderCanceledCustomer(\XLite\Model\Order $order) { static::register('order', $order); static::register('recipientName', $order->getProfile()->getName()); $result = static::compose(static::TYPE_ORDER_CANCELED_CUSTOMER, static::getOrdersDepartmentMail(), $order->getProfile()->getLogin(), 'order_canceled', array(), true, \XLite::CUSTOMER_INTERFACE, static::getMailer()->getLanguageCode(\XLite::CUSTOMER_INTERFACE, $order->getProfile()->getLanguage())); if ($result) { \XLite\Core\OrderHistory::getInstance()->registerCustomerEmailSent($order->getOrderId(), 'Order is canceled'); } elseif (static::$errorMessage) { \XLite\Core\OrderHistory::getInstance()->registerCustomerEmailFailed($order->getOrderId(), static::$errorMessage); } }
/** * Process callback * * @param \XLite\Model\Payment\Transaction $transaction Callback-owner transaction * @param \XLite\Model\Payment\Base\Processor $processor Payment processor object * * @return void */ public function processCallbackIPN($transaction, $processor) { $request = \XLite\Core\Request::getInstance(); \XLite\Module\CDev\Paypal\Main::addLog('processCallbackIPN()', $request->getData()); $status = $transaction::STATUS_FAILED; switch ($this->getIPNVerification()) { case self::IPN_DECLINED: $status = $transaction::STATUS_FAILED; $processor->markCallbackRequestAsInvalid(static::t('IPN verification failed')); break; case self::IPN_REQUEST_ERROR: $status = $transaction::STATUS_PENDING; $processor->markCallbackRequestAsInvalid(static::t('IPN HTTP error')); break; case self::IPN_VERIFIED: $backendTransaction = null; if (!empty($request->parent_txn_id)) { // Received IPN is related to the backend transaction $ppref = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\BackendTransactionData')->findOneBy(array('name' => 'PPREF', 'value' => $request->txn_id)); if ($ppref) { $backendTransaction = $ppref->getTransaction(); } } switch ($request->payment_status) { case 'Completed': case 'Canceled_Reversal': case 'Processed': $status = $transaction::STATUS_SUCCESS; if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_CAPTURE); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; } break; case 'Pending': if ('authorization' == $request->pending_reason && \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_SUCCESS; if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_SUCCESS; } } else { $status = $transaction::STATUS_PENDING; } break; case 'Expired': if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_FAILED; if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_FAILED; } } break; case 'Voided': if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_VOID; } if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_VOID); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; break; case 'Denied': case 'Reversed': $status = $transaction::STATUS_FAILED; break; case 'Failed': if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_FAILED; } break; case 'Refunded': if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_REFUND); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; $status = $transaction::STATUS_FAILED; break; default: // No default actions } default: // No default actions } if ($transaction->getStatus() != $status) { $transaction->setStatus($status); } if (isset($backendTransactionStatus)) { if ($backendTransaction->getStatus() != $backendTransactionStatus) { $backendTransaction->setStatus($backendTransactionStatus); } $processor->updateInitialBackendTransaction($transaction, $status); } elseif (!empty($request->parent_txn_id)) { \XLite\Core\OrderHistory::getInstance()->registerTransaction($transaction->getOrder()->getOrderNumber(), sprintf('IPN received [method: %s, amount: %s, payment status: %s]', $transaction->getPaymentMethod()->getName(), $request->transaction_entity, $request->mc_gross, $request->payment_status), $this->getRequestData(), 'Note: received IPN does not relate to any backend transaction registered with the order. It is possible if you update payment directly on PayPal site or if your customer or PayPal updated the payment.'); } }
/** * Send failed order mail to Customer * * @param \XLite\Model\Order $order Order model * * @return void */ public static function sendFailedOrderCustomer(\XLite\Model\Order $order) { static::setMailInterface(\XLite::CUSTOMER_INTERFACE); if ($order->getProfile()) { static::compose(\XLite\Core\Config::getInstance()->Company->orders_department, $order->getProfile()->getLogin(), 'order_failed'); \XLite\Core\OrderHistory::getInstance()->registerCustomerEmailSent($order->getOrderId()); } }
/** * doActionUpdate * * @return void */ protected function doActionUpdate() { $data = $this->getRequestData(); $orderId = \XLite\Core\Request::getInstance()->order_id; $changes = $this->getOrderChanges($orderId, $data); \XLite\Core\Database::getRepo('\\XLite\\Model\\Order')->updateById($orderId, $data); \XLite\Core\OrderHistory::getInstance()->registerOrderChanges($orderId, $changes); }