-
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.
Add support for Google Product Category
- Loading branch information
1 parent
5c2fc9b
commit 92effd5
Showing
12 changed files
with
11,018 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/** | ||
* Customizable datafeeds extension for Magento 2 | ||
* | ||
* @category LCB | ||
* @package LCB_Feeds | ||
* @author Silpion Tomasz Gregorczyk <tom@leftcurlybracket.com> | ||
*/ | ||
|
||
namespace LCB\Feeds\Model\Config\Source; | ||
|
||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; | ||
|
||
class GoogleCategory extends AbstractSource | ||
{ | ||
|
||
/** | ||
* @var \Magento\Framework\Module\Dir\Reader | ||
*/ | ||
protected $moduleReader; | ||
|
||
/** | ||
* @var \Magento\Backend\Model\Auth\Session $authSession | ||
*/ | ||
protected $authSession; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $categories; | ||
|
||
/** | ||
* @param \Magento\Framework\Module\Dir\Reader $moduleReader | ||
* @param \Magento\Backend\Model\Auth\Session $authSession | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Module\Dir\Reader $moduleReader, | ||
\Magento\Backend\Model\Auth\Session $authSession | ||
) { | ||
$this->moduleReader = $moduleReader; | ||
$this->authSession = $authSession; | ||
} | ||
|
||
/** | ||
* Get Ceneo Categories | ||
* | ||
* @return array | ||
*/ | ||
public function getAllOptions() | ||
{ | ||
|
||
if ($this->categories) { | ||
return $this->categories; | ||
} | ||
|
||
$locale = $this->authSession->getUser()->getInterfaceLocale(); | ||
$googleTaxonomy = $this->getGoogleTaxonomy($locale); | ||
$categories = [['label' => __('Please select'), 'value' => '']]; | ||
|
||
$taxonomyArray = []; | ||
foreach($googleTaxonomy as $taxonomyRow) { | ||
$taxonomyRow = explode(" - ", trim($taxonomyRow)); | ||
if(isset($taxonomyRow[0]) && isset($taxonomyRow[1])) { | ||
$categories[] = ['label' => $taxonomyRow[1], 'value' => $taxonomyRow[0]]; | ||
} | ||
} | ||
|
||
$this->categories = $categories; | ||
|
||
return $this->categories; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getGoogleTaxonomy($locale = 'en_US') | ||
{ | ||
$sourceDir = $this->moduleReader->getModuleDir( | ||
\Magento\Framework\Module\Dir::MODULE_ETC_DIR, 'LCB_Feeds' | ||
); | ||
|
||
if (!file_exists($sourceDir . "/source/google/$locale.txt")) { | ||
$locale = 'en_US'; | ||
} | ||
|
||
$taxonomyRaw = file_get_contents($sourceDir . "/source/google/$locale.txt", true); | ||
$taxonomyArray = []; | ||
return (array) explode("\n", trim($taxonomyRaw)); | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
} | ||
], | ||
"type": "magento2-module", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"license": [ | ||
"OSL-3.0" | ||
], | ||
|
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
Oops, something went wrong.