public function testUpdate() { $context = TestHelper::getContext(); $name = 'ControllerFrontendOrderUpdate'; $context->getConfig()->set('classes/controller/common/order/name', $name); $orderCntlStub = $this->getMockBuilder('Controller_Common_Order_Default')->setMethods(array('update'))->setConstructorArgs(array($context))->getMock(); Controller_Common_Order_Factory::injectController('Controller_Common_Order_' . $name, $orderCntlStub); $orderCntlStub->expects($this->once())->method('update'); $object = new Controller_Frontend_Order_Default($context); $object->update(MShop_Factory::createManager($context, 'order')->createItem()); }
/** * 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()); }
public function testRun() { $context = TestHelper::getContext(); $arcavias = TestHelper::getArcavias(); $name = 'ControllerJobsOrderCleanupUnfinishedDefaultRun'; $context->getConfig()->set('classes/order/manager/name', $name); $context->getConfig()->set('classes/controller/common/order/name', $name); $orderManagerStub = $this->getMockBuilder('MShop_Order_Manager_Default')->setMethods(array('searchItems', 'getSubManager'))->setConstructorArgs(array($context))->getMock(); $orderBaseManagerStub = $this->getMockBuilder('MShop_Order_Manager_Base_Default')->setMethods(array('deleteItems'))->setConstructorArgs(array($context))->getMock(); $orderCntlStub = $this->getMockBuilder('Controller_Common_Order_Default')->setMethods(array('unblock'))->setConstructorArgs(array($context))->getMock(); MShop_Order_Manager_Factory::injectManager('MShop_Order_Manager_' . $name, $orderManagerStub); Controller_Common_Order_Factory::injectController('Controller_Common_Order_' . $name, $orderCntlStub); $orderItem = $orderManagerStub->createItem(); $orderItem->setBaseId(1); $orderItem->setId(2); $orderManagerStub->expects($this->once())->method('getSubManager')->will($this->returnValue($orderBaseManagerStub)); $orderManagerStub->expects($this->once())->method('searchItems')->will($this->returnValue(array($orderItem->getId() => $orderItem))); $orderBaseManagerStub->expects($this->once())->method('deleteItems'); $orderCntlStub->expects($this->once())->method('unblock'); $object = new Controller_Jobs_Order_Cleanup_Unfinished_Default($context, $arcavias); $object->run(); }
/** * 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'); }