示例#1
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     $target = 'MShop_Common_Manager_Interface';
     $manager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext(), 'NotExist');
     $this->assertInstanceOf($target, $manager);
 }
示例#2
0
 public function testSaveDeleteItem()
 {
     $manager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $typeManager = $manager->getSubManager('type');
     $search = $typeManager->createSearch();
     $search->setConditions($search->compare('==', 'service.type.code', 'delivery'));
     $result = $typeManager->searchItems($search);
     if (($type = reset($result)) === false) {
         throw new Exception('No service type found');
     }
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('service.position' => 1, 'service.label' => 'test service', 'service.status' => 1, 'service.code' => 'testcode', 'service.provider' => 'Default', 'service.config' => array('default.url' => 'www.url.de', 'default.project' => 'test'), 'service.typeid' => $type->getId()));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => array('==' => (object) array('service.code' => 'testcode')))));
     $saved = $this->_object->saveItems($saveParams);
     $searched = $this->_object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'service.id'});
     $this->_object->deleteItems($deleteParams);
     $result = $this->_object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'service.id'});
     $this->assertEquals($saved['items']->{'service.id'}, $searched['items'][0]->{'service.id'});
     $this->assertEquals($saved['items']->{'service.position'}, $searched['items'][0]->{'service.position'});
     $this->assertEquals($saved['items']->{'service.label'}, $searched['items'][0]->{'service.label'});
     $this->assertEquals($saved['items']->{'service.status'}, $searched['items'][0]->{'service.status'});
     $this->assertEquals($saved['items']->{'service.code'}, $searched['items'][0]->{'service.code'});
     $this->assertEquals($saved['items']->{'service.provider'}, $searched['items'][0]->{'service.provider'});
     $this->assertEquals($saved['items']->{'service.config'}, $searched['items'][0]->{'service.config'});
     $this->assertEquals($saved['items']->{'service.typeid'}, $searched['items'][0]->{'service.typeid'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
示例#3
0
 /**
  * Initializes the service list type controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Service_List_Type');
     $manager = MShop_Service_Manager_Factory::createManager($context);
     $listManager = $manager->getSubManager('list');
     $this->_manager = $listManager->getSubManager('type');
 }
示例#4
0
 public function testProcessOK()
 {
     $controller = Controller_Frontend_Basket_Factory::createController($this->_context);
     $baseManager = MShop_Order_Manager_Factory::createManager($this->_context)->getSubManager('base');
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', 'unitpaymentcode'));
     $result = $serviceManager->searchItems($search);
     if (($serviceItem = reset($result)) === false) {
         throw new Exception('No service item found');
     }
     $controller->setService('payment', $serviceItem->getId());
     $controller->setAddress('payment', array('order.base.address.languageid' => 'en'));
     $this->_context->setUserId('-1');
     $view = TestHelper::getView();
     $param = array('cs_order' => 1);
     $helper = new MW_View_Helper_Parameter_Default($view, $param);
     $view->addHelper('param', $helper);
     $this->_object->setView($view);
     $this->_object->process();
     $search = $baseManager->createSearch();
     $search->setConditions($search->compare('==', 'order.base.customerid', '-1'));
     $result = $baseManager->searchItems($search);
     if (($item = reset($result)) === false) {
         throw new Exception('No order placed');
     }
     $baseManager->deleteItem($item->getId());
     $this->assertInstanceOf('MShop_Order_Item_Interface', $view->orderItem);
     $this->assertEquals($item->getId(), $view->orderItem->getBaseId());
 }
示例#5
0
 public function testSaveDeleteItem()
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.label', 'unitlabel'));
     $resultService = $serviceManager->searchItems($search);
     if (($item = reset($resultService)) === false) {
         throw new Exception('No service item found');
     }
     $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('service.list.type.domain' => 'product')))), 'start' => 0, 'limit' => 1);
     $serviceListTypeManager = Controller_ExtJS_Service_List_Type_Factory::createController(TestHelper::getContext());
     $resultType = $serviceListTypeManager->searchItems($params);
     $saveParams = (object) array('site' => 'unittest', 'items' => (object) array('service.list.parentid' => $item->getId(), 'service.list.typeid' => $resultType['items'][0]->{'service.list.type.id'}, 'service.list.domain' => 'product', 'service.list.refid' => -1, 'service.list.datestart' => '2000-01-01 00:00:00', 'service.list.dateend' => '2001-01-01 00:00:00', 'service.list.config' => array('test' => 'unit'), 'service.list.position' => 1, 'service.list.status' => 1));
     $searchParams = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('==' => (object) array('service.list.refid' => -1)))));
     $saved = $this->_object->saveItems($saveParams);
     $searched = $this->_object->searchItems($searchParams);
     $deleteParams = (object) array('site' => 'unittest', 'items' => $saved['items']->{'service.list.id'});
     $this->_object->deleteItems($deleteParams);
     $result = $this->_object->searchItems($searchParams);
     $this->assertInternalType('object', $saved['items']);
     $this->assertNotNull($saved['items']->{'service.list.id'});
     $this->assertEquals($saved['items']->{'service.list.id'}, $searched['items'][0]->{'service.list.id'});
     $this->assertEquals($saved['items']->{'service.list.parentid'}, $searched['items'][0]->{'service.list.parentid'});
     $this->assertEquals($saved['items']->{'service.list.typeid'}, $searched['items'][0]->{'service.list.typeid'});
     $this->assertEquals($saved['items']->{'service.list.domain'}, $searched['items'][0]->{'service.list.domain'});
     $this->assertEquals($saved['items']->{'service.list.refid'}, $searched['items'][0]->{'service.list.refid'});
     $this->assertEquals($saved['items']->{'service.list.datestart'}, $searched['items'][0]->{'service.list.datestart'});
     $this->assertEquals($saved['items']->{'service.list.dateend'}, $searched['items'][0]->{'service.list.dateend'});
     $this->assertEquals($saved['items']->{'service.list.config'}, $searched['items'][0]->{'service.list.config'});
     $this->assertEquals($saved['items']->{'service.list.position'}, $searched['items'][0]->{'service.list.position'});
     $this->assertEquals($saved['items']->{'service.list.status'}, $searched['items'][0]->{'service.list.status'});
     $this->assertEquals(1, count($searched['items']));
     $this->assertEquals(0, count($result['items']));
 }
示例#6
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $serviceManager = MShop_Service_Manager_Factory::createManager($context);
     $serviceItem = $serviceManager->createItem();
     $this->_object = new MShop_Service_Provider_Delivery_Manual($context, $serviceItem);
 }
 /**
  * Adds the service test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @throws MW_Setup_Exception If a required ID is not available
  */
 private function _addServiceData(array $testdata)
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_additional, 'Default');
     $serviceTypeManager = $serviceManager->getSubManager('type', 'Default');
     $typeIds = array();
     $type = $serviceTypeManager->createItem();
     $this->_conn->begin();
     foreach ($testdata['service/type'] as $key => $dataset) {
         $type->setId(null);
         $type->setCode($dataset['code']);
         $type->setDomain($dataset['domain']);
         $type->setLabel($dataset['label']);
         $type->setStatus($dataset['status']);
         $serviceTypeManager->saveItem($type);
         $typeIds[$key] = $type->getId();
     }
     $parent = $serviceManager->createItem();
     foreach ($testdata['service'] as $key => $dataset) {
         if (!isset($typeIds[$dataset['typeid']])) {
             throw new MW_Setup_Exception(sprintf('No service type ID found for "%1$s"', $dataset['typeid']));
         }
         $parent->setId(null);
         $parent->setTypeId($typeIds[$dataset['typeid']]);
         $parent->setPosition($dataset['pos']);
         $parent->setCode($dataset['code']);
         $parent->setLabel($dataset['label']);
         $parent->setProvider($dataset['provider']);
         $parent->setConfig($dataset['config']);
         $parent->setStatus($dataset['status']);
         $serviceManager->saveItem($parent, false);
     }
     $this->_conn->commit();
 }
示例#8
0
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_editor = TestHelper::getContext()->getEditor();
     $manager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $listManager = $manager->getSubManager('list');
     $this->_object = $listManager->getSubManager('type');
 }
示例#9
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $serviceManager = MShop_Service_Manager_Factory::createManager($context);
     $serviceItem = $serviceManager->createItem();
     $serviceItem->setCode('test');
     $this->_object = new MShop_Service_Provider_Payment_PostPay($context, $serviceItem);
 }
示例#10
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $serviceManager = MShop_Service_Manager_Factory::createManager($context);
     $serviceItem = $serviceManager->createItem();
     $serviceItem->setCode('test');
     $this->_object = $this->getMockBuilder('MShop_Service_Provider_Payment_PrePay')->setMethods(array('_getOrder', '_getOrderBase', '_saveOrder', '_saveOrderBase'))->setConstructorArgs(array($context, $serviceItem))->getMock();
 }
示例#11
0
 protected function setUp()
 {
     $this->_context = TestHelper::getContext();
     $servManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $this->_servItem = $servManager->createItem();
     $this->_mockProvider = $this->getMockBuilder('MShop_Service_Provider_Decorator_OrderCheck')->disableOriginalConstructor()->getMock();
     $this->_basket = MShop_Order_Manager_Factory::createManager($this->_context)->getSubManager('base')->createItem();
     $this->_object = new MShop_Service_Provider_Decorator_OrderCheck($this->_context, $this->_servItem, $this->_mockProvider);
 }
示例#12
0
 protected function setUp()
 {
     $this->_context = TestHelper::getContext();
     $servManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $search = $servManager->createSearch();
     $search->setConditions($search->compare('==', 'service.provider', 'Default'));
     $result = $servManager->searchItems($search, array('price'));
     if (($item = reset($result)) === false) {
         throw new Exception('No order base item found');
     }
     $this->_object = new MShop_Service_Provider_Payment_Test($this->_context, $item);
 }
示例#13
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.provider', 'Default'));
     $result = $serviceManager->searchItems($search, array('price'));
     if (($item = reset($result)) === false) {
         throw new Exception('No order base item found');
     }
     $item->setConfig(array('default.project' => '8502_TEST'));
     $item->setCode('test');
     $this->_object = new MShop_Service_Provider_Delivery_Default(TestHelper::getContext(), $item);
 }
示例#14
0
 protected function setUp()
 {
     $this->_context = TestHelper::getContext();
     $servManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $search = $servManager->createSearch();
     $search->setConditions($search->compare('==', 'service.provider', 'Default'));
     $result = $servManager->searchItems($search, array('price'));
     if (($item = reset($result)) === false) {
         throw new Exception('No order base item found');
     }
     $this->_mock = $this->getMockBuilder('MShop_Service_Provider_Payment_PrePay')->setConstructorArgs(array($this->_context, $item))->setMethods(array('calcPrice', 'checkConfigBE', 'checkConfigFE', 'getConfigBE', 'getConfigFE', 'injectGlobalConfigBE', 'isAvailable', 'isImplemented', 'query', 'setCommunication', 'setConfigFE', 'updateAsync', 'updateSync'))->getMock();
     $this->_object = new MShop_Service_Provider_Decorator_Test($this->_context, $item, $this->_mock);
 }
示例#15
0
 public function testRunExceptionProcess()
 {
     $context = TestHelper::getContext();
     $arcavias = TestHelper::getArcavias();
     $name = 'ControllerJobsServiceAsyncProcessDefaultRun';
     $context->getConfig()->set('classes/service/manager/name', $name);
     $serviceManagerStub = $this->getMockBuilder('MShop_Service_Manager_Default')->setMethods(array('getProvider', 'searchItems'))->setConstructorArgs(array($context))->getMock();
     MShop_Service_Manager_Factory::injectManager('MShop_Service_Manager_' . $name, $serviceManagerStub);
     $serviceItem = $serviceManagerStub->createItem();
     $serviceManagerStub->expects($this->once())->method('searchItems')->will($this->onConsecutiveCalls(array($serviceItem), array()));
     $serviceManagerStub->expects($this->once())->method('getProvider')->will($this->throwException(new MShop_Service_Exception()));
     $object = new Controller_Jobs_Order_Service_Async_Default($context, $arcavias);
     $object->run();
 }
 /**
  * Insert product data.
  */
 protected function _process()
 {
     $this->_msg('Adding service base performance data', 0);
     $manager = MShop_Service_Manager_Factory::createManager($this->_getContext());
     $typeManager = $manager->getSubManager('type');
     $search = $typeManager->createSearch();
     $expr = array($search->compare('==', 'service.type.domain', 'service'), $search->compare('==', 'service.type.code', 'payment'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $typeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new Exception('Service type item "payment" not found');
     }
     $item = $manager->createItem();
     $item->setTypeId($typeItem->getId());
     $item->setProvider('PrePay');
     $item->setStatus(1);
     $this->_txBegin();
     for ($i = 0; $i < 100; $i++) {
         $code = 'perf-' . str_pad($i, 3, '0', STR_PAD_LEFT);
         $item->setId(null);
         $item->setCode($code);
         $item->setLabel('Payment service ' . $code);
         $item->setPosition($i);
         $manager->saveItem($item, false);
     }
     $this->_txCommit();
     $search = $typeManager->createSearch();
     $expr = array($search->compare('==', 'service.type.domain', 'service'), $search->compare('==', 'service.type.code', 'delivery'));
     $search->setConditions($search->combine('&&', $expr));
     $types = $typeManager->searchItems($search);
     if (($typeItem = reset($types)) === false) {
         throw new Exception('Service type item "delivery" not found');
     }
     $item = $manager->createItem();
     $item->setTypeId($typeItem->getId());
     $item->setProvider('Manual');
     $item->setStatus(1);
     $this->_txBegin();
     for ($i = 0; $i < 100; $i++) {
         $code = 'perf-' . str_pad($i, 3, '0', STR_PAD_LEFT);
         $item->setId(null);
         $item->setCode($code);
         $item->setLabel('Delivery service ' . $code);
         $item->setPosition($i);
         $manager->saveItem($item, false);
     }
     $this->_txCommit();
     $this->_status('done');
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $context = TestHelper::getContext();
     $serviceManager = MShop_Service_Manager_Factory::createManager($context);
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', 'paypalexpress'));
     $serviceItems = $serviceManager->searchItems($search);
     if (($this->_serviceItem = reset($serviceItems)) === false) {
         throw new Exception('No paypalexpress service item available');
     }
     $this->_object = new MShop_Service_Provider_Payment_PayPalExpress($context, $this->_serviceItem);
     $orderManager = MShop_Order_Manager_Factory::createManager(TestHelper::getContext());
     $search = $orderManager->createSearch();
     $expr = array($search->compare('==', 'order.type', MShop_Order_Item_Abstract::TYPE_WEB), $search->compare('==', 'order.statuspayment', MShop_Order_Item_Abstract::PAY_AUTHORIZED));
     $search->setConditions($search->combine('&&', $expr));
     $orderItems = $orderManager->searchItems($search);
     if (($this->_order = reset($orderItems)) === false) {
         throw new Exception(sprintf('No Order found with statuspayment "%1$s" and type "%2$s"', MShop_Order_Item_Abstract::PAY_AUTHORIZED, MShop_Order_Item_Abstract::TYPE_WEB));
     }
 }
示例#18
0
 public function testProcessPrePay()
 {
     $orderManager = MShop_Order_Manager_Factory::createManager($this->_context);
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', 'unitpaymentcode'));
     $result = $serviceManager->searchItems($search);
     if (($serviceItem = reset($result)) === false) {
         throw new Exception('No service item found');
     }
     $basketCntl = Controller_Frontend_Basket_Factory::createController($this->_context);
     $basketCntl->setService('payment', $serviceItem->getId());
     $orderItem = $orderManager->createItem();
     $orderItem->setId(-1);
     $view = TestHelper::getView();
     $view->orderItem = $orderItem;
     $view->orderBasket = $basketCntl->get();
     $this->_object->setView($view);
     $this->_object->process();
     $this->assertEquals(0, count($view->get('standardErrorList', array())));
     $this->assertInstanceOf('MShop_Common_Item_Helper_Form_Interface', $view->get('paymentForm'));
     $this->assertEquals('REDIRECT', $view->paymentForm->getMethod());
     $this->assertEquals('paymenturl', $view->paymentForm->getUrl());
 }
示例#19
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     MShop_Service_Manager_Factory::createManager(TestHelper::getContext(), 'unknown');
 }
示例#20
0
 protected function _getListItems()
 {
     $manager = MShop_Service_Manager_Factory::createManager($this->_context, 'Default');
     $search = $manager->createSearch();
     $expr = array($search->compare('==', 'service.code', 'unitcode'), $search->compare('==', 'service.type.code', 'delivery'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSlice(0, 1);
     $results = $manager->searchItems($search);
     if (($item = reset($results)) === false) {
         throw new Exception('No service item found');
     }
     $search = $this->_object->createSearch();
     $expr = array($search->compare('==', 'service.list.parentid', $item->getId()), $search->compare('==', 'service.list.domain', 'text'), $search->compare('==', 'service.list.editor', $this->_editor), $search->compare('==', 'service.list.type.code', 'default'));
     $search->setConditions($search->combine('&&', $expr));
     $search->setSortations(array($search->sort('+', 'service.list.position')));
     return $this->_object->searchItems($search);
 }
示例#21
0
 /**
  * @return MShop_Order_Item_Base_Interface
  */
 protected function _getServiceItem()
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $search = $serviceManager->createSearch(true);
     $expr = array($search->getConditions(), $search->compare('==', 'service.provider', 'Default'), $search->compare('==', 'service.type.domain', 'service'), $search->compare('==', 'service.type.code', 'delivery'));
     $search->setConditions($search->combine('&&', $expr));
     $services = $serviceManager->searchItems($search);
     if (($service = reset($services)) === false) {
         throw new Exception('No service item found');
     }
     return $service;
 }
 /**
  * Adds the service-list test data.
  *
  * @param array $testdata Associative list of key/list pairs
  * @param array $refIds Associative list of domains and the keys/IDs of the inserted items
  * @throws MW_Setup_Exception If a required ID is not available
  */
 protected function _addServiceListData(array $testdata, array $refIds)
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_additional, 'Default');
     $serviceTypeManager = $serviceManager->getSubManager('type', 'Default');
     $serviceListManager = $serviceManager->getSubManager('list', 'Default');
     $serviceListTypeManager = $serviceListManager->getSubmanager('type', 'Default');
     $typeDomain = $typeCode = $itemCode = array();
     foreach ($testdata['service/list'] as $dataset) {
         $exp = explode('/', $dataset['parentid']);
         if (count($exp) != 3) {
             throw new MW_Setup_Exception(sprintf('Some keys for parentid are set wrong "%1$s"', $dataset['parentid']));
         }
         $typeDomain[] = $exp[0];
         $typeCode[] = $exp[1];
         $itemCode[] = $exp[2];
     }
     $search = $serviceTypeManager->createSearch();
     $expr = array($search->compare('==', 'service.type.domain', $typeDomain), $search->compare('==', 'service.type.code', $typeCode));
     $search->setConditions($search->combine('&&', $expr));
     $typeids = array();
     foreach ($serviceTypeManager->searchItems($search) as $item) {
         $typeids[] = $item->getId();
     }
     $search = $serviceManager->createSearch();
     $expr = array($search->compare('==', 'service.code', $itemCode), $search->compare('==', 'service.typeid', $typeids));
     $search->setConditions($search->combine('&&', $expr));
     $parentIds = array();
     foreach ($serviceManager->searchItems($search) as $item) {
         $parentIds['service/' . $item->getType() . '/' . $item->getCode()] = $item->getId();
     }
     $listItemTypeIds = array();
     $listItemType = $serviceListTypeManager->createItem();
     $this->_conn->begin();
     foreach ($testdata['service/list/type'] as $key => $dataset) {
         $listItemType->setId(null);
         $listItemType->setCode($dataset['code']);
         $listItemType->setDomain($dataset['domain']);
         $listItemType->setLabel($dataset['label']);
         $listItemType->setStatus($dataset['status']);
         $serviceListTypeManager->saveItem($listItemType);
         $listItemTypeIds[$key] = $listItemType->getId();
     }
     $listItem = $serviceListManager->createItem();
     foreach ($testdata['service/list'] as $dataset) {
         if (!isset($parentIds[$dataset['parentid']])) {
             throw new MW_Setup_Exception(sprintf('No service ID found for "%1$s"', $dataset['parentid']));
         }
         if (!isset($listItemTypeIds[$dataset['typeid']])) {
             throw new MW_Setup_Exception(sprintf('No service list type ID found for "%1$s"', $dataset['typeid']));
         }
         if (!isset($refIds[$dataset['domain']][$dataset['refid']])) {
             throw new MW_Setup_Exception(sprintf('No "%1$s" ref ID found for "%2$s"', $dataset['refid'], $dataset['domain']));
         }
         $listItem->setId(null);
         $listItem->setParentId($parentIds[$dataset['parentid']]);
         $listItem->setTypeId($listItemTypeIds[$dataset['typeid']]);
         $listItem->setRefId($refIds[$dataset['domain']][$dataset['refid']]);
         $listItem->setDomain($dataset['domain']);
         $listItem->setDateStart($dataset['start']);
         $listItem->setDateEnd($dataset['end']);
         $listItem->setConfig($dataset['config']);
         $listItem->setPosition($dataset['pos']);
         $listItem->setStatus($dataset['status']);
         $serviceListManager->saveItem($listItem, false);
     }
     $this->_conn->commit();
 }
示例#23
0
 /**
  * Executes the job.
  *
  * @throws Controller_Jobs_Exception If an error occurs
  */
 public function run()
 {
     $context = $this->_getContext();
     /** @deprecated Only for compatibility reasons */
     $days = $context->getConfig()->get('controller/jobs/service/delivery/process/limit-days', 90);
     /** controller/jobs/order/service/delivery/limit-days
      * Only start the delivery process of orders that were created in the past within the configured number of days
      *
      * The delivery process is normally started immediately after the
      * notification about a successful payment arrived. This option prevents
      * orders from being shipped in case anything went wrong or an update
      * failed and old orders would have been shipped now.
      *
      * @param integer Number of days
      * @since 2014.03
      * @category User
      * @category Developer
      * @see controller/jobs/order/email/payment/default/limit-days
      * @see controller/jobs/order/email/delivery/default/limit-days
      */
     $days = $context->getConfig()->get('controller/jobs/order/service/delivery/limit-days', $days);
     $date = date('Y-m-d 00:00:00', time() - 86400 * $days);
     $serviceManager = MShop_Service_Manager_Factory::createManager($context);
     $serviceSearch = $serviceManager->createSearch();
     $serviceSearch->setConditions($serviceSearch->compare('==', 'service.type.code', 'delivery'));
     $orderManager = MShop_Order_Manager_Factory::createManager($context);
     $orderSearch = $orderManager->createSearch();
     $start = 0;
     do {
         $serviceItems = $serviceManager->searchItems($serviceSearch);
         foreach ($serviceItems as $serviceItem) {
             try {
                 $serviceProvider = $serviceManager->getProvider($serviceItem);
                 $expr = array($orderSearch->compare('==', 'order.siteid', $serviceItem->getSiteId()), $orderSearch->compare('>', 'order.datepayment', $date), $orderSearch->compare('>', 'order.statuspayment', MShop_Order_Item_Abstract::PAY_PENDING), $orderSearch->compare('==', 'order.statusdelivery', MShop_Order_Item_Abstract::STAT_UNFINISHED), $orderSearch->compare('==', 'order.base.service.code', $serviceItem->getCode()), $orderSearch->compare('==', 'order.base.service.type', 'delivery'));
                 $orderSearch->setConditions($orderSearch->combine('&&', $expr));
                 $orderStart = 0;
                 do {
                     $orderItems = $orderManager->searchItems($orderSearch);
                     foreach ($orderItems as $orderItem) {
                         try {
                             $serviceProvider->process($orderItem);
                             $orderManager->saveItem($orderItem);
                         } catch (Exception $e) {
                             $str = 'Error while processing order with ID "%1$s": %2$s';
                             $context->getLogger()->log(sprintf($str, $orderItem->getId(), $e->getMessage()));
                         }
                     }
                     $orderCount = count($orderItems);
                     $orderStart += $orderCount;
                     $orderSearch->setSlice($orderStart);
                 } while ($orderCount >= $orderSearch->getSliceSize());
             } catch (Exception $e) {
                 $str = 'Error while processing service with ID "%1$s": %2$s';
                 $context->getLogger()->log(sprintf($str, $serviceItem->getId(), $e->getMessage()));
             }
         }
         $count = count($serviceItems);
         $start += $count;
         $serviceSearch->setSlice($start);
     } while ($count >= $serviceSearch->getSliceSize());
 }
示例#24
0
 public function testCopyFrom()
 {
     $serviceCopy = new MShop_Order_Item_Base_Service_Default($this->_price);
     $manager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'service.provider', 'default'));
     $services = $manager->searchItems($search);
     if (($service = reset($services)) !== false) {
         $serviceCopy->copyFrom($service);
     }
     $this->assertEquals('unitcode', $serviceCopy->getCode());
     $this->assertEquals('unitlabel', $serviceCopy->getName());
     $this->assertEquals('delivery', $serviceCopy->getType());
     $this->assertEquals('', $serviceCopy->getMediaUrl());
     $this->assertTrue($serviceCopy->isModified());
 }
示例#25
0
 /**
  * Initializes the service controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Service');
     $this->_manager = MShop_Service_Manager_Factory::createManager($context);
     $this->_context = $context;
 }
示例#26
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_context = TestHelper::getContext();
     $serviceItem = MShop_Service_Manager_Factory::createManager($this->_context)->createItem();
     $this->_object = new Test_MShop_Service_Provider_Abstract($this->_context, $serviceItem);
 }
示例#27
0
 /**
  * Returns the service item IDs for the given test data.
  *
  * @param array $testdata Test data
  * @return array List of service IDs
  */
 protected function _getServiceIds(array $testdata)
 {
     $services = $servIds = array();
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_additional, 'Default');
     foreach ($testdata['order/base/service'] as $key => $dataset) {
         if (isset($dataset['servid'])) {
             $services[$key] = $dataset['servid'];
         }
     }
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', $services));
     $servicesResult = $serviceManager->searchItems($search);
     foreach ($servicesResult as $id => $service) {
         $servIds[$service->getCode()] = $id;
     }
     return $servIds;
 }
示例#28
0
 public function testProcessNotExistingAttributes()
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager($this->_context);
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', 'unitpaymentcode'));
     $result = $serviceManager->searchItems($search);
     if (($service = reset($result)) === false) {
         throw new Exception('Service item not found');
     }
     $view = TestHelper::getView();
     $param = array('c_paymentoption' => $service->getId(), 'c_payment' => array($service->getId() => array('notexisting' => 'invalid value')));
     $helper = new MW_View_Helper_Parameter_Default($view, $param);
     $view->addHelper('param', $helper);
     $this->_object->setView($view);
     $this->setExpectedException('Controller_Frontend_Basket_Exception');
     $this->_object->process();
 }
示例#29
0
 /**
  * @param string $code
  */
 protected function _getService($code)
 {
     $serviceManager = MShop_Service_Manager_Factory::createManager(TestHelper::getContext());
     $search = $serviceManager->createSearch();
     $search->setConditions($search->compare('==', 'service.code', $code));
     $result = $serviceManager->searchItems($search, array('text'));
     if (($item = reset($result)) === false) {
         throw new Exception(sprintf('No service item with code "%1$s" found', $code));
     }
     return $item;
 }
 public function testUpdateNotAvailable()
 {
     $context = TestHelper::getContext();
     $object = new MShop_Plugin_Provider_Order_ServicesUpdate($context, $this->_plugin);
     $priceManager = MShop_Factory::createManager($context, 'price');
     $localeManager = MShop_Factory::createManager($context, 'locale');
     $orderBaseProductManager = MShop_Factory::createManager($context, 'order/base/product');
     $orderBaseServiceManager = MShop_Factory::createManager($context, 'order/base/service');
     $priceItem = $priceManager->createItem();
     $localeItem = $localeManager->createItem();
     $orderProduct = $orderBaseProductManager->createItem();
     $serviceDelivery = $orderBaseServiceManager->createItem();
     $serviceDelivery->setServiceId(1);
     $servicePayment = $orderBaseServiceManager->createItem();
     $servicePayment->setServiceId(2);
     $orderStub = $this->getMockBuilder('MShop_Order_Item_Base_Default')->setConstructorArgs(array($priceItem, $localeItem))->setMethods(array('getProducts'))->getMock();
     $serviceStub = $this->getMockBuilder('MShop_Service_Manager_Default')->setConstructorArgs(array($context))->setMethods(array('searchItems', 'getProvider'))->getMock();
     MShop_Service_Manager_Factory::injectManager('MShop_Service_Manager_PluginServicesUpdate', $serviceStub);
     $context->getConfig()->set('classes/service/manager/name', 'PluginServicesUpdate');
     $orderStub->setService($serviceDelivery, 'delivery');
     $orderStub->setService($servicePayment, 'payment');
     $serviceItemDelivery = new MShop_Service_Item_Default(array('type' => 'delivery'));
     $serviceItemPayment = new MShop_Service_Item_Default(array('type' => 'payment'));
     $providerStub = $this->getMockBuilder('MShop_Service_Provider_Delivery_Manual')->setConstructorArgs(array($context, $serviceStub->createItem()))->setMethods(array('isAvailable'))->getMock();
     $orderStub->expects($this->once())->method('getProducts')->will($this->returnValue(array($orderProduct)));
     $serviceStub->expects($this->once())->method('searchItems')->will($this->returnValue(array(1 => $serviceItemDelivery, 2 => $serviceItemPayment)));
     $serviceStub->expects($this->exactly(2))->method('getProvider')->will($this->returnValue($providerStub));
     $providerStub->expects($this->exactly(2))->method('isAvailable')->will($this->returnValue(false));
     $this->assertTrue($object->update($orderStub, 'addProduct.after'));
     $this->assertEquals(array(), $orderStub->getServices());
 }