diff --git a/Model/FieldMapping/GigyaFromMagento.php b/Model/FieldMapping/GigyaFromMagento.php index d83d339..e2ad79c 100644 --- a/Model/FieldMapping/GigyaFromMagento.php +++ b/Model/FieldMapping/GigyaFromMagento.php @@ -85,4 +85,20 @@ public function run($customer, $gigyaUser) ); } } + + /** + * Get data file fieldMapping + * @return mixed|string + */ + public function getFieldsMappingFile(){ + return $this->getFieldMappingFile(); + } + + /** + * Get magento custom attribute user overide by observer DefaultGigyaSyncFieldMapping + * @return \Magento\Framework\Api\AttributeInterface[]|null + */ + public function getMagentoUserObserver(){ + return $this->customerFieldsUpdater->getMagentoUser()->getCustomAttributes(); + } } \ No newline at end of file diff --git a/Observer/AbstractGigyaAccountEnricher.php b/Observer/AbstractGigyaAccountEnricher.php index e5321de..d1cfa9f 100644 --- a/Observer/AbstractGigyaAccountEnricher.php +++ b/Observer/AbstractGigyaAccountEnricher.php @@ -162,6 +162,25 @@ protected function enrichGigyaAccount($magentoCustomer) $gigyaAccountData->setCustomerEntityId($magentoCustomer->getEntityId()); $gigyaAccountData->setCustomerEntityEmail($magentoCustomer->getEmail()); + $customerDatas = $this->gigyaFromMagento->getMagentoUserObserver(); + $fields = file_get_contents($this->gigyaFromMagento->getFieldsMappingFile()); + if($fields && !empty($fields)){ + $dataFiles = json_decode($fields,true); + $dataArray = []; + foreach($dataFiles as $dataFile){ + if(isset($dataFile['cmsName']) && isset($dataFile['direction']) && isset($dataFile['gigyaName'])) { + if (array_key_exists(preg_replace('/custom_/','',$dataFile['cmsName']),$customerDatas)){ + if($dataFile['direction'] == 'both' || $dataFile['direction'] == 'cms2g' ){ + $dataArray[preg_replace('/data./','',$dataFile['gigyaName'])]=$customerDatas[preg_replace('/custom_/','',$dataFile['cmsName'])]->getValue(); + } + } + } + } + $gigyaAccountData->setData($dataArray); + } + + + return $gigyaAccountData; } diff --git a/Observer/DefaultCMSSyncFieldMapping.php b/Observer/DefaultCMSSyncFieldMapping.php index b9385d2..f718770 100644 --- a/Observer/DefaultCMSSyncFieldMapping.php +++ b/Observer/DefaultCMSSyncFieldMapping.php @@ -40,7 +40,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) default: $customer->setGender('3'); } - + // 'Translate' the date of birth code from Gigya to Magento value $birthDay = $gigyaProfile->getBirthDay(); $birthMonth = $gigyaProfile->getBirthMonth(); $birthYear = $gigyaProfile->getBirthYear(); @@ -49,5 +49,19 @@ public function execute(\Magento\Framework\Event\Observer $observer) { $customer->setDob(sprintf('%s-%s-%s', $birthYear, str_pad($birthMonth, 2, "0", STR_PAD_LEFT), str_pad($birthDay, 2, "0", STR_PAD_LEFT))); } + + // 'Translate' the subscribe boolean code from Gigya to Magento value + $gigyaUser = $observer->getData('gigya_user'); + $customerData = $observer->getData('gigya_user')->getData('subscribe'); + if(isset($customerData['subscribe'] )){ + if($customerData['subscribe'] == 'false'){ + $gigyaUser->setData(array_merge($customerData,array('subscribe'=>0,'data'=>array('subscribe'=>0)))); + } + if($customerData['subscribe'] == 'true'){ + $gigyaUser->setData(array_merge($customerData,array('subscribe'=>1,'data'=>array('subscribe'=>1)))); + } + } + + } } \ No newline at end of file diff --git a/Observer/DefaultGigyaSyncFieldMapping.php b/Observer/DefaultGigyaSyncFieldMapping.php index 06c4263..e6de789 100644 --- a/Observer/DefaultGigyaSyncFieldMapping.php +++ b/Observer/DefaultGigyaSyncFieldMapping.php @@ -40,7 +40,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) default: $gigyaProfile->setGender('u'); } - + // 'Translate' the date of birth code from Gigya to Magento value $dob = $magentoCustomer->getDob(); if ($dob != null && trim($dob) != '') { @@ -54,5 +54,13 @@ public function execute(\Magento\Framework\Event\Observer $observer) $gigyaProfile->setBirthMonth($birthMonth); $gigyaProfile->setBirthYear($birthYear); } + + // 'Translate' the subscribe boolean code from Gigya to Magento value + if($magentoCustomer->getCustomAttribute('gigya_subscribe')->getValue() == '0'){ + $magentoCustomer->setCustomAttribute('gigya_subscribe','false'); + } + if($magentoCustomer->getCustomAttribute('gigya_subscribe')->getValue() == '1'){ + $magentoCustomer->setCustomAttribute('gigya_subscribe','true'); + } } } \ No newline at end of file diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 838e38a..14541a7 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -122,5 +122,41 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $attribute->save(); } + + if (version_compare($context->getVersion(), '5.0.7') < 0) { + + /** @var CustomerSetup $customerSetup */ + $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); + + $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); + $attributeSetId = $customerEntity->getDefaultAttributeSetId(); + + /** @var $attributeSet AttributeSe */ + $attributeSet = $this->attributeSetFactory->create(); + $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); + + $customerSetup->addAttribute(Customer::ENTITY, 'gigya_subscribe', [ + 'type' => 'int', + 'label' => 'Subscribe', + 'input' => 'select', + 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', + 'global' => 'Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL', + 'required' => false, + 'visible' => true, + 'user_defined' => true, + 'sort_order' => 1020, + 'position' => 1020, + 'system' => 0, + ]); + + $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'gigya_subscribe') + ->addData([ + 'attribute_set_id' => $attributeSetId, + 'attribute_group_id' => $attributeGroupId, + 'used_in_forms' => ['adminhtml_customer'], + ]); + + $attribute->save(); + } } } \ No newline at end of file diff --git a/composer.json b/composer.json index bbf41f8..92616ee 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "gigya/magento2-im", "description": "Gigya Identity Management for Magento 2", "type": "magento2-module", - "version": "5.0.3", + "version": "5.0.4", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/events.xml b/etc/events.xml index d6f5ef5..74b45b5 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -8,11 +8,11 @@ - + - + diff --git a/etc/module.xml b/etc/module.xml index 550c29a..1e07c4a 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +