Skip to content

Commit

Permalink
Merge pull request #15 from gigya/origin/feature/GIG-12-GIG-13
Browse files Browse the repository at this point in the history
Origin/feature/gig 12 gig 13
  • Loading branch information
sbrancoCleverAge authored Dec 14, 2017
2 parents 385a796 + 1d33772 commit fce135c
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 6 deletions.
16 changes: 16 additions & 0 deletions Model/FieldMapping/GigyaFromMagento.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
19 changes: 19 additions & 0 deletions Observer/AbstractGigyaAccountEnricher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 15 additions & 1 deletion Observer/DefaultCMSSyncFieldMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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))));
}
}


}
}
10 changes: 9 additions & 1 deletion Observer/DefaultGigyaSyncFieldMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) != '') {
Expand All @@ -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');
}
}
}
36 changes: 36 additions & 0 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

<event name="gigya_pre_field_mapping">
<!-- default implementation of g2cms field mapping : for now only gender attribute (it will effectively be mapped only if the field mapping file declares it) -->
<!-- default implementation of g2cms field mapping : for now only gender attribute, dob attribute, subscribe attribute -->
<observer name="defaultCMSSyncFieldMapping" instance="Gigya\GigyaIM\Observer\DefaultCMSSyncFieldMapping" />
</event>
<event name="pre_sync_to_gigya">
<!-- default implementation of cms2g field mapping : for now only gender attribute (it will effectively be mapped only if the field mapping file declares it) -->
<!-- default implementation of cms2g field mapping : for now only gender attribute, dob attribute, subscribe attribute -->
<observer name="defaultGigyaSyncFieldMapping" instance="Gigya\GigyaIM\Observer\DefaultGigyaSyncFieldMapping" />
</event>

Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Gigya_GigyaIM" setup_version="5.0.6">
<module name="Gigya_GigyaIM" setup_version="5.0.7">
<sequence>
<module name="Magento_Customer"/>
</sequence>
Expand Down

0 comments on commit fce135c

Please sign in to comment.