Forums › Forums › OroCRM › OroCRM – How do I? Questions › How do I sync Magento Customer "On-Demand"?
This topic contains 13 replies, has 2 voices, and was last updated by Mike Kudelya 7 years, 2 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- January 1, 2017 at 9:56 pm #29193
Hello,
Is it possible to use the Magento’s SOAP API or any other way so that I can pass the customer ID to Magento and it syncs all the details of that particular customer?
Although having the integration sync running all the time can get me all the details of all the customers, syncing “On-Demand” for a particular customer seems to be a good option to add too. Is this currently possible?
Also, as a side question, how does the integration sync work? I mean when there’s a new customer in Magento, how does OroCRM know when to pull this detail because I don’t find the integration sync command running on its own.
Thank you for your support!
- CreatorTopic
- AuthorReplies
- January 4, 2017 at 3:23 am #29194
Hi
Is it possible to use the Magento’s SOAP API or any other way so that I can pass the customer ID to Magento and it syncs all the details of that particular customer?
Yes, it is possible, i have modified CustomerBridgeIterator.php and add additional filter on this line.
PHP12345678910$this->filter->addComplexFilter($this->getIdFieldName(),['key' => $this->getIdFieldName(),'value' => ['key' => 'eq','value' => 145,],]);Also, as a side question, how does the integration sync work? I mean when there’s a new customer in Magento, how does OroCRM know when to pull this detail because I don’t find the integration sync command running on its own.
Magento customer has own customer id, orocrm saves it to orocrm_magento_customer::origin_id field and findExistingEntity function is searching by this field and decides – new entity or not.
January 4, 2017 at 4:25 am #29195Hi Mike,
Thanks for the reply. So I understood that we need to add the customer ID filter to get details of that particular customer. How do I do this based on a button-click? should I override the CustomerBridgeIterator.php while passing an option ID parameter to applyFilter()? And then call the applyFilter() method?
As for the integration sync, what I really meant was I don’t see the cron for integration running unless I click the ‘Schedule Sync’ button so I was wondering how the cron is actually supposed to be configured for the sync to run on a regular basis without me clicking.
Thanks again!
January 4, 2017 at 7:44 am #29196Hi
If you want to sync only one customer, just override original CustomerBridgeIterator.php and paste this function in your new file:
PHP123456789101112131415161718/*** {@inheritdoc}*/protected function applyFilter(){parent::applyFilter();$this->filter->addComplexFilter($this->getIdFieldName(),['key' => $this->getIdFieldName(),'value' => ['key' => 'eq','value' => 145,],]);}In other case, if you want to specify list of customers which should be synchronized from UI, you should add to MagentoSoapTransport entity Many-To-Many relation to Magento Customer, add to settings your filtered array of customers, modify SoapTransportSettingFormType form. After that add array of customers to AbstractPageableSoapIterator, for example what this did with $this->websiteId and change call from “‘value’ => 145” to new variable “‘value’ => $this->filtered_customers”. Don’t forget change ‘key’ from ‘eq’ to ‘in’. In this case you can create many integrations with different list of customers which will be synchronized.
To run on a regular basis try to add this command to cron:
Shell1app/console oro:cron --env=prodJanuary 5, 2017 at 4:45 am #29197Thank you Mike.
It was well explained. I’ll try and let you know how it goes.
January 16, 2017 at 5:47 am #29198Hi again Mike,
Here’s how I override the CustomerBridgeIterator.php:
PHP1234567891011121314151617181920212223242526272829303132333435<?phpnamespace Custom\Bundle\MagentoBundle\Provider\Iterator;use OroCRM\Bundle\MagentoBundle\Provider\BatchFilterBag;use OroCRM\Bundle\MagentoBundle\Provider\Transport\SoapTransport;use OroCRM\Bundle\MagentoBundle\Provider\Iterator\CustomerBridgeIterator as OroMagentoCustomerBridgeIterator;class CustomerBridgeIterator extends OroMagentoCustomerBridgeIterator{/*** {@inheritdoc}*/protected function applyFilter(){var_dump('method overridden');exit;}/*** {@inheritdoc}*/protected function getEntityIds(){parent::getEntityIds();}/*** {@inheritdoc}*/protected function getIdFieldName(){parent::getIdFieldName();}}So if you see while I’m running the integration sync it should give me an output ‘method overridden’ which it isn’t. I even completely removed the cache folder and ran clear:cache.
Do you think I’m doing something wrong or is the above meant to be? Thank you.
January 16, 2017 at 7:28 am #29199Hi
Please read my topic about overriding. There is two ways to override.
January 16, 2017 at 11:28 pm #29200Hi Mike,
I followed your guide and declared the CustomerBridgeIterator as a service in service.yml:
YAML12parameters:oro_custom.magento.provider.iterator.customerbridgeiterator: Custom\Bundle\MagentoBundle\Provider\Iterator\CustomerBridgeIteratorAnd the service.yml is being loaded in CustomMagentoExtension.php but the overridden class is still not being picked. I tried the above with an iterator.yml too.
I noticed that the way the original CustomerBridgeIterator is being used not through a service call but by direct class call. Do you think this is the issue?
Thank you.
January 17, 2017 at 1:04 am #29201I found my mistake. The problem was not with overriding but I was calling the base function because of this:
PHP1234protected function getEntityIds(){parent::getEntityIds();}I was calling the parent getEntityIds() which calls $this->applyFilter() and thus the base function was being called.
Changed to this:
PHP123456789/*** {@inheritdoc}*/protected function getEntityIds(){$this->applyFilter();parent::getEntityIds();}But now I seem to be getting another error:
PHP1Fatal error: Call to a member function reset() on null in OroCRM\Bundle\MagentoBundle\Provider\Iterator\AbstractPageableSoapIterator.php on line 164Any ideas? Thank you.
January 17, 2017 at 3:32 am #29202Please excuse my answer above. I thought that fixed the issue but it actually didn’t. My file is still not being overridden. I feel I’m either missing something very silly or very crucial.
January 17, 2017 at 6:06 am #29203Hi
I think I understood what was wrong. SoapTransport creates CustomerBridgeIterator via new operator, not call service. Override getCustomers function and create there your custom CustomerBridgeIterator class. Please note, ‘orocrm_magento.transport.soap_transport.class’ parameter in your custom bundle must be the same that in original MagentoBundle, just change path to class.
YAML12parameters:orocrm_magento.transport.soap_transport.class: Custom\Bundle\MagentoBundle\Provider\Transport\CustomSoapTransportJanuary 17, 2017 at 10:24 pm #29204Hi Mike,
You were perfectly correct. The reason is exactly as you said. My overridden function now works! Thank you so much.
January 18, 2017 at 10:06 pm #29205Hello Mike,
So all my code is set up but the intended response is not showing through SOAP. When I apply the filter for a single customer_id it returns no records. However, if I remove the filter it returns all the customers. Here’s the filter being passed:
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556array(1) {["filters"]=>array(1) {["complex_filter"]=>array(4) {[0]=>array(2) {["key"]=>string(9) "customer_id"["value"]=>array(2) {["key"]=>string(2) "eq"["value"]=>int(9503)}}[1]=>array(2) {["key"]=>string(10) "website_id"["value"]=>array(2) {["key"]=>string(2) "in"["value"]=>string(1) "7"}}[2]=>array(2) {["key"]=>string(10) "updated_at"["value"]=>array(2) {["key"]=>string(2) "gt"["value"]=>string(19) "2016-01-01 12:00:00"}}[3]=>array(2) {["key"]=>string(10) "updated_at"["value"]=>array(2) {["key"]=>string(3) "lte"["value"]=>string(19) "2017-01-19 05:51:56"}}}}}However, this works returning all customers for that website:
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344array(1) {["filters"]=>array(1) {["complex_filter"]=>array(3) {[0]=>array(2) {["key"]=>string(10) "website_id"["value"]=>array(2) {["key"]=>string(2) "in"["value"]=>string(1) "7"}}[1]=>array(2) {["key"]=>string(10) "updated_at"["value"]=>array(2) {["key"]=>string(2) "gt"["value"]=>string(19) "2016-01-01 12:00:00"}}[2]=>array(2) {["key"]=>string(10) "updated_at"["value"]=>array(2) {["key"]=>string(3) "lte"["value"]=>string(19) "2017-01-19 05:57:42"}}}}}Customer ID 9503 belongs to Website 7, this has already been verified. This is the empty SOAP response that I receive with the Customer ID:
XHTML12345678<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:oroCustomerListResponse><result SOAP-ENC:arrayType="ns1:oroCustomerEntity[0]" xsi:type="ns1:oroCustomerEntityArray"/></ns1:oroCustomerListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>Maybe the filters are not configured to work for this action with OroBridge? Or there’s another way to insert this filter? I tried using action ‘OroCustomerInfo’ too.
Thank you in advance!
January 19, 2017 at 6:00 am #29206Hi
Here is my customer filter from applyFilter function:
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344array ('filters' =>array ('complex_filter' =>array (0 =>array ('key' => 'website_id','value' =>array ('key' => 'in','value' => '1',),),1 =>array ('key' => 'updated_at','value' =>array ('key' => 'from','value' => '2017-01-19 13:38:56',),),2 =>array ('key' => 'updated_at','value' =>array ('key' => 'to','value' => '2017-01-19 13:45:56',),),3 =>array ('key' => 'customer_id','value' =>array ('key' => 'eq','value' => 153,),),),),)I think they are the same with your filter, but i can update my customer. Are you sure that field updated_at in customer_entity magento table contain value between ‘2016-01-01 12:00:00’ and ‘2017-01-19 05:57:42’ ? Also try to print all filters on magento side.
- AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.