/** * Executes the job. * * @throws Controller_Jobs_Exception If an error occurs */ public function run() { $context = $this->_getContext(); $controller = Controller_Common_Order_Factory::createController($context); $baseManager = MShop_Factory::createManager($context, 'order/base'); $manager = 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', MShop_Order_Item_Abstract::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()); }
/** * Executes the job. * * @throws Controller_Jobs_Exception If an error occurs */ public function run() { $context = $this->_getContext(); $controller = Controller_Common_Order_Factory::createController($context); $baseManager = MShop_Factory::createManager($context, 'order/base'); $manager = 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', MShop_Order_Item_Abstract::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()); }
/** * 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 MShop_Order_Item_Interface $orderItem Order item object */ public function update(MShop_Order_Item_Interface $orderItem) { Controller_Common_Order_Factory::createController($this->_getContext())->update($orderItem); }
public function testCreateControllerNotExisting() { $this->setExpectedException('Controller_Common_Exception'); Controller_Common_Order_Factory::createController(TestHelper::getContext(), 'notexist'); }