/** * @param Integration $integration * * @return ChannelObjectBuilder */ public function createBuilderForIntegration(Integration $integration) { $channel = new Channel(); $settingsProvider = $this->settingsProvider; $type = $this->getChannelTypeForIntegration($this->settingsProvider, $integration->getType()); $connectors = $integration->getConnectors(); $entities = array_filter($settingsProvider->getEntitiesByChannelType($type), function ($entityName) use($settingsProvider, &$connectors) { $connector = $settingsProvider->getIntegrationConnectorName($entityName); $key = array_search($connector, $connectors); $enabled = $key !== false; if ($enabled) { unset($connectors[$key]); } return $enabled; }); // disable connectors without correspondent entity $connectors = array_diff($integration->getConnectors(), $connectors); $identity = $settingsProvider->getCustomerIdentityFromConfig($type); if (!in_array($identity, $entities, true)) { array_unshift($entities, $identity); $connector = $settingsProvider->getIntegrationConnectorName($identity); if (false !== $connector) { array_unshift($connectors, $connector); } } $integration->setEditMode(Integration::EDIT_MODE_DISALLOW); $integration->setConnectors($connectors); $builder = new ChannelObjectBuilder($this->registry->getManager(), $this->settingsProvider, $channel); $builder->setChannelType($type)->setEntities($entities); return $builder; }
/** * {@inheritDoc} */ public function load(ObjectManager $om) { $this->organization = $this->getReference('default_organization'); $this->users = $om->getRepository('OroUserBundle:User')->findAll(); $website = new Website(); $website->setCode('admin')->setName('Admin'); $om->persist($website); $store = new Store(); $store->setCode('admin')->setName('Admin')->setWebsite($website); $om->persist($store); $transport = new MagentoSoapTransport(); $transport->setApiUser('api_user'); $transport->setApiKey('api_key'); $transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION); $transport->setIsExtensionInstalled(true); $transport->setMagentoVersion('1.9.1.0'); $transport->setWsdlUrl('http://magento.domain'); $om->persist($transport); $integration = new Integration(); $integration->setType('magento'); $integration->setConnectors(['customer', 'cart', 'order', 'newsletter_subscriber']); $integration->setName(self::INTEGRATION_NAME); $integration->setTransport($transport); $integration->setOrganization($this->organization); $om->persist($integration); $builder = $this->factory->createBuilderForIntegration($integration); $builder->setOwner($integration->getOrganization()); $builder->setDataSource($integration); $builder->setStatus($integration->isEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE); $this->dataChannel = $builder->getChannel(); $om->persist($this->dataChannel); $group = new CustomerGroup(); $group->setName('General'); $group->setOriginId(15000); $group->setChannel($integration); $om->persist($group); $om->flush(); $this->persistDemoCustomers($om, $website, $store, $group, $integration); $om->flush(); $this->persistDemoCarts($om, $store, $integration); $om->flush(); $this->persistDemoOrders($om, $store, $integration); $om->flush(); $this->persistDemoRFM($om); $om->flush(); }
/** * @return $this */ protected function createIntegration() { $integration = new Integration(); $integration->setName('Demo Web store'); $integration->setType('magento'); $integration->setConnectors(["customer", "order", "cart", "region"]); $integration->setTransport($this->transport); $integration->setOrganization($this->organization); $this->em->persist($integration); $this->integration = $integration; return $this; }
/** * @return $this */ protected function createIntegration() { $integration = new Integration(); $integration->setName('Demo Web store'); $integration->setType('magento'); $integration->setConnectors(['customer', 'order', 'cart']); $integration->setTransport($this->transport); $integration->setOrganization($this->organization); $synchronizationSettings = Object::create(['isTwoWaySyncEnabled' => true]); $integration->setSynchronizationSettings($synchronizationSettings); $this->em->persist($integration); $this->integration = $integration; return $this; }
public function testExceptionOutput() { $channel = new Channel(); $channel->setConnectors(['customer', 'cart']); /** @var CartExpirationSyncCommand|\PHPUnit_Framework_MockObject_MockObject $command */ $command = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Command\\CartExpirationSyncCommand', ['isJobRunning']); $command->setContainer($this->container); $input = new ArrayInput([], $command->getDefinition()); $output = new MemoryOutput(); $processor = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Provider\\CartExpirationProcessor')->disableOriginalConstructor()->getMock(); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $repo = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Repository\\ChannelRepository')->disableOriginalConstructor()->getMock(); $this->container->expects($this->at(0))->method('get')->with('orocrm_magento.provider.cart_expiration_processor')->will($this->returnValue($processor)); $this->container->expects($this->at(1))->method('get')->with('doctrine.orm.entity_manager')->will($this->returnValue($em)); $em->expects($this->once())->method('getRepository')->with('OroIntegrationBundle:Channel')->will($this->returnValue($repo)); $repo->expects($this->once())->method('getConfiguredChannelsForSync')->will($this->returnValue([$channel])); $errorMessage = 'testErrorMessage'; $processor->expects($this->once())->method('process')->will($this->throwException(new \Exception($errorMessage))); $command->execute($input, $output); $this->assertContains($errorMessage, $output->getOutput()); }