Пример #1
0
 /**
  * Return status handlers list
  *
  * @return array
  */
 public static function getStatusHandlers()
 {
     $handlers = parent::getStatusHandlers();
     array_unshift($handlers[static::STATUS_QUEUED][static::STATUS_DECLINED], 'declinePIN');
     array_unshift($handlers[static::STATUS_QUEUED][static::STATUS_CANCELED], 'declinePIN');
     return $handlers;
 }
Пример #2
0
 /**
  * Prepares query builder object to get bestsell products
  *
  * @param \XLite\Core\CommonCell $cnd   Search condition
  * @param integer                $count Number of products to get
  * @param integer                $cat   Category identificator
  *
  * @return \Doctrine\ORM\QueryBuilder Query builder object
  */
 protected function defineBestsellersQuery(\XLite\Core\CommonCell $cnd, $count, $cat)
 {
     list($sort, $order) = $cnd->{self::P_ORDER_BY};
     $qb = $this->createQueryBuilder()->linkInner('p.order_items', 'o')->linkInner('o.order', 'ord')->linkInner('ord.paymentStatus', 'ps')->addSelect('sum(o.amount) as product_amount');
     $qb->andWhere($qb->expr()->in('ps.code', \XLite\Model\Order\Status\Payment::getPaidStatuses()))->groupBy('o.object')->addOrderBy('product_amount', 'desc')->addOrderBy($sort, $order);
     if (0 < $count) {
         $qb->setMaxResults($count);
     }
     if (0 < $cat) {
         $qb->linkLeft('p.categoryProducts', 'cp')->linkLeft('cp.category', 'c');
         \XLite\Core\Database::getRepo('XLite\\Model\\Category')->addSubTreeCondition($qb, $cat);
     }
     return \XLite\Core\Database::getRepo('XLite\\Model\\Product')->assignExternalEnabledCondition($qb, 'p');
 }
Пример #3
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();
         }
     }
 }
Пример #4
0
 /**
  * Prepare top sellers search condition
  *
  * @param \XLite\Core\CommonCell $cnd Conditions
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function prepareTopSellersCondition(\XLite\Core\CommonCell $cnd)
 {
     list($start, $end) = $cnd->date;
     $qb = $this->createQueryBuilder();
     $qb->addSelect('SUM(o.amount) as cnt')->innerJoin('o.order', 'o1')->innerJoin('o1.paymentStatus', 'ps')->addSelect('o1.date')->andWhere($qb->expr()->in('ps.code', \XLite\Model\Order\Status\Payment::getPaidStatuses()))->setMaxResults($cnd->limit)->addGroupBy('o.sku')->addOrderBy('cnt', 'desc')->addOrderBy('o.name', 'asc');
     if ($cnd->currency) {
         $qb->innerJoin('o1.currency', 'currency', 'WITH', 'currency.currency_id = :currency_id')->setParameter('currency_id', $cnd->currency);
     }
     if (0 < $start) {
         $qb->andWhere('o1.date >= :start')->setParameter('start', $start);
     }
     if (0 < $end) {
         $qb->andWhere('o1.date < :end')->setParameter('end', $end);
     }
     return $qb;
 }
Пример #5
0
 /**
  * Create a QueryBuilder instance for getFistOpenOrderDate()
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function defineGetFistOpenOrderDateQuery()
 {
     $qb = $this->createQueryBuilder()->select('MIN(o.date) as order_date');
     $this->prepareCndPaymentStatus($qb, \XLite\Model\Order\Status\Payment::getOpenStatuses());
     return $qb;
 }
Пример #6
0
 /**
  * Process callback
  *
  * @param \XLite\Model\Payment\Transaction $transaction Callback-owner transaction
  *
  * @return void
  */
 public function processCallback(\XLite\Model\Payment\Transaction $transaction)
 {
     $request = \XLite\Core\Request::getInstance();
     if (!$request->txnId || !$this->updateData) {
         // This is not X-Payments callback. We should not be here actually
         return;
     }
     $updateData = $this->updateData;
     if (isset($updateData['status'])) {
         $status = $this->getTransactionStatus($updateData, $transaction);
         if ($status && in_array($status, \XLite\Model\Order\Status\Payment::getPaidStatuses())) {
             $transaction->setStatus($status);
             $this->registerBackendTransaction($transaction, $updateData);
             // Hack against check in Controller\Customer\Callback.
             // In X-Payments Connector status should be always set by transaction.
             $transaction->getOrder()->setPaymentStatusByTransaction($transaction);
         }
     }
     if (isset($updateData['advinfo']) && is_array($updateData['advinfo'])) {
         if (!empty($updateData['advinfo']['Error'])) {
             $transaction->setDataCell('status', $updateData['advinfo']['Error'], 'X-Payments error', 'C');
             $transaction->setNote($updateData['advinfo']['Error']);
         }
         if (!empty($updateData['advinfo']['Message'])) {
             $transaction->setDataCell('status', $updateData['advinfo']['Message'], 'X-Payments message', 'C');
             $transaction->setNote($updateData['advinfo']['Message']);
         }
     }
     $this->processCallbackData($transaction, $updateData);
     \XLite\Core\Database::getEM()->flush();
 }
Пример #7
0
 /**
  * Prepare query for countItemsPurchasedByCustomer() method
  *
  * @param integer              $productId Product Id
  * @param \XLite\Model\Profile $profile   Customer profile
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function defineCountItemsPurchasedByCustomer($productId, $profile)
 {
     $qb = $this->createQueryBuilder('i');
     $qb->select('COUNT(i.item_id)')->innerJoin('i.object', 'p')->innerJoin('i.order', 'o')->innerJoin('o.orig_profile', 'profile')->innerJoin('o.paymentStatus', 'ps')->andWhere('p.product_id = :productId')->andWhere('profile.profile_id = :profileId')->andWhere($qb->expr()->in('ps.code', \XLite\Model\Order\Status\Payment::getPaidStatuses()))->setParameter('productId', $productId)->setParameter('profileId', $profile->getProfileId());
     return $qb;
 }
Пример #8
0
 /**
  * Get search condition
  *
  * @return \XLite\Core\CommonCell
  */
 protected function getSearchCondition()
 {
     $cnd = new \XLite\Core\CommonCell();
     $cnd->{\XLite\Model\Repo\Order::P_ORDER_BY} = array(array('o.date', 'o.order_id'), array('DESC', 'DESC'));
     $cnd->{\XLite\Model\Repo\Order::P_PAYMENT_STATUS} = \XLite\Model\Order\Status\Payment::getOpenStatuses();
     return $cnd;
 }
Пример #9
0
 /**
  * Return action
  *
  * @return void
  */
 public function doActionReturn()
 {
     $profile = $this->detectProfile();
     $transaction = $this->detectTransaction();
     if ($profile && $transaction) {
         $status = $transaction->getOrder()->getPaymentStatus()->getCode();
         $request = \XLite\Core\Request::getInstance();
         if ($request->last_4_cc_num && $request->card_type && !$transaction->getCard()) {
             $transaction->saveCard('******', $request->last_4_cc_num, $request->card_type);
         }
         if (in_array($status, \XLite\Model\Order\Status\Payment::getPaidStatuses())) {
             $transaction->getXpcData()->setUseForRecharges('Y');
             \XLite\Core\TopMessage::addInfo('Card saved');
         } else {
             \XLite\Core\TopMessage::addError('Card was not saved due to payment processor error');
         }
         \XLite\Core\Database::getEM()->flush();
         echo $this->getRediectCode($profile);
         // Cleanup pending zero-auth data
         $this->cleanupZeroAuthPendingData($profile);
         // Cleanup fake carts from session
         self::cleanupFakeCarts($profile);
         exit;
     } else {
         die('Error occured when saving card. Customer profile not found');
         // Just in case show error inside iframe. However this should not happen
     }
 }
Пример #10
0
 /**
  * Find sales by product
  *
  * @param \XLite\Model\Product $product Product
  *
  * @return \Doctrine\ORM\QueryBuilder Query builder object
  */
 public function findSalesByProduct(\XLite\Model\Product $product)
 {
     $qb = $this->createPureQueryBuilder()->linkInner('p.order_items', 'o')->linkInner('o.order', 'ord')->linkInner('ord.paymentStatus', 'ps')->select('sum(o.amount) as product_amount')->andWhere('o.object = :product')->setParameter('product', $product);
     return (int) $qb->andWhere($qb->expr()->in('ps.code', \XLite\Model\Order\Status\Payment::getPaidStatuses()))->getSingleScalarResult();
 }
 /**
  * {@inheritDoc}
  */
 public function prepareEntityBeforeCommit($type)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type));
     return parent::prepareEntityBeforeCommit($type);
 }