forked from DivanteLtd/magento1-vsbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make mapping more flexible (based on DivanteLtd#25)
- Loading branch information
cewald
committed
Nov 14, 2019
1 parent
e10dd2f
commit 2c46678
Showing
17 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* Class Divante_VueStorefrontBridge_Model_Config_Mapper | ||
*/ | ||
class Divante_VueStorefrontBridge_Model_Config_Mapper | ||
{ | ||
/** | ||
* Mapper xml config path | ||
*/ | ||
const MAPPER_CONFIG_ROOT_NODE = 'global/vsf_bridge/mapper/types'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $config = array(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function __construct() | ||
{ | ||
$mappingConfigTypes = Mage::getConfig()->getNode(self::MAPPER_CONFIG_ROOT_NODE)->asArray(); | ||
foreach ($mappingConfigTypes as $mappingIdentifier => $mapper) { | ||
$this->config[$mappingIdentifier] = $mapper['mapper']; | ||
} | ||
|
||
return $this->config; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param array $initialDto | ||
* @return array | ||
*/ | ||
public function applyExtendedMapping($type, &$initialDto) | ||
{ | ||
if ($this->config[$type] && !empty($this->config[$type])) { | ||
foreach ($this->config[$type] as $name => $className) { | ||
$model = Mage::getModel($className); | ||
if (!$model || !$model instanceof Divante_VueStorefrontBridge_Helper_Mapper_Abstract) { | ||
$error = 'Class "%s" is not an instance on "Divante_VueStorefrontBridge_Helper_Mapper_Abstract".'; | ||
Mage::log(sprintf($error, $className), 'system.log', true); | ||
continue; | ||
} | ||
|
||
$initialDto = $model->filterDto($initialDto); | ||
} | ||
} | ||
|
||
return $initialDto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters