Ejemplo n.º 1
0
 /**
  * Executes the job.
  *
  * @throws \Aimeos\Controller\Jobs\Exception If an error occurs
  */
 public function run()
 {
     $context = $this->getContext();
     $controller = \Aimeos\Controller\Common\Order\Factory::createController($context);
     $baseManager = \Aimeos\MShop\Factory::createManager($context, 'order/base');
     $manager = \Aimeos\MShop\Factory::createManager($context, 'order');
     /** controller/jobs/order/cleanup/unfinished/keep-hours
      * Release the ordered products after the configured time if no payment was confirmed
      *
      * After a customer creates an order and before he is redirected to the
      * payment provider (if necessary), the ordered products, coupon codes,
      * etc. are blocked for that customer. Normally, they should be released
      * a certain amount of time if no payment confirmation arrives so
      * customers can order the products and use the coupon codes again.
      *
      * The configured number of hours should be high enough to avoid releasing
      * products and coupon codes in case of temporary technical problems!
      *
      * The unfinished orders are deleted afterwards to keep the database clean.
      *
      * @param integer Number of hours
      * @since 2014.07
      * @category User
      */
     $hours = $context->getConfig()->get('controller/jobs/order/cleanup/unfinished/keep-hours', 24);
     $limit = date('Y-m-d H:i:s', time() - 3600 * $hours);
     $search = $manager->createSearch();
     $expr = array($search->compare('<', 'order.mtime', $limit), $search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED));
     $search->setConditions($search->combine('&&', $expr));
     $start = 0;
     do {
         $baseIds = array();
         $items = $manager->searchItems($search);
         foreach ($items as $item) {
             $controller->unblock($item);
             $baseIds[] = $item->getBaseId();
         }
         $baseManager->deleteItems($baseIds);
         $count = count($items);
         $start += $count;
         $search->setSlice($start);
     } while ($count >= $search->getSliceSize());
 }
Ejemplo n.º 2
0
 /**
  * Executes the job.
  *
  * @throws \Aimeos\Controller\Jobs\Exception If an error occurs
  */
 public function run()
 {
     $context = $this->getContext();
     $controller = \Aimeos\Controller\Common\Order\Factory::createController($context);
     $baseManager = \Aimeos\MShop\Factory::createManager($context, 'order/base');
     $manager = \Aimeos\MShop\Factory::createManager($context, 'order');
     /** controller/jobs/order/cleanup/unpaid/keep-days
      * Removes all orders from the database that are unpaid
      *
      * Orders with a payment status of deleted, canceled or refused are only
      * necessary for the records for a certain amount of time. Afterwards,
      * they can be deleted from the database most of the time.
      *
      * The number of days should be high enough to ensure that you keep the
      * orders as long as your customers will be asking what happend to their
      * orders.
      *
      * @param integer Number of days
      * @since 2014.07
      * @category User
      */
     $days = $context->getConfig()->get('controller/jobs/order/cleanup/unpaid/keep-days', 3);
     $limit = date('Y-m-d H:i:s', time() - 86400 * $days);
     $search = $manager->createSearch();
     $expr = array($search->compare('<', 'order.mtime', $limit), $search->compare('<', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_REFUND));
     $search->setConditions($search->combine('&&', $expr));
     $start = 0;
     do {
         $baseIds = array();
         $items = $manager->searchItems($search);
         foreach ($items as $item) {
             $controller->unblock($item);
             $baseIds[] = $item->getBaseId();
         }
         $baseManager->deleteItems($baseIds);
         $count = count($items);
         $start += $count;
         $search->setSlice($start);
     } while ($count >= $search->getSliceSize());
 }
Ejemplo n.º 3
0
 public function testCreateControllerNotExisting()
 {
     $this->setExpectedException('\\Aimeos\\Controller\\Common\\Exception');
     \Aimeos\Controller\Common\Order\Factory::createController(\TestHelperCntl::getContext(), 'notexist');
 }
Ejemplo n.º 4
0
 /**
  * Blocks or frees the resources listed in the order if necessary.
  *
  * After payment status updates, the resources like products or coupon
  * codes listed in the order must be blocked or unblocked. This method
  * cares about executing the appropriate action depending on the payment
  * status.
  *
  * It's save to call this method multiple times for one order. In this case,
  * the actions will be executed only once. All subsequent calls will do
  * nothing as long as the payment status hasn't changed in the meantime.
  *
  * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
  */
 public function update(\Aimeos\MShop\Order\Item\Iface $orderItem)
 {
     \Aimeos\Controller\Common\Order\Factory::createController($this->getContext())->update($orderItem);
 }