-
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.
Merge pull request #13 from alpin11/feature/dynamic-google-options-se…
…lect Google shopping category provider
- Loading branch information
Showing
3 changed files
with
5,520 additions
and
13 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/Pimcore/DynamicOptionsProvider/ProductCategoryOptionsProvider.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,75 @@ | ||
<?php | ||
|
||
|
||
namespace CoreShop\Bundle\GoogleShoppingBundle\Pimcore\DynamicOptionsProvider; | ||
|
||
|
||
use Pimcore\Cache; | ||
use Pimcore\Model\DataObject\ClassDefinition\Data; | ||
use Pimcore\Model\DataObject\ClassDefinition\DynamicOptionsProvider\SelectOptionsProviderInterface; | ||
use Symfony\Component\Config\FileLocatorInterface; | ||
|
||
class ProductCategoryOptionsProvider implements SelectOptionsProviderInterface | ||
{ | ||
const CACHE_KEY = "google_shopping_taxonomy_with_ids"; | ||
|
||
/** | ||
* @var FileLocatorInterface | ||
*/ | ||
private FileLocatorInterface $fileLocator; | ||
|
||
public function __construct(FileLocatorInterface $fileLocator) | ||
{ | ||
$this->fileLocator = $fileLocator; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getOptions($context, $fieldDefinition) | ||
{ | ||
$options = []; | ||
|
||
if (($fromCache = Cache::load(self::CACHE_KEY))) { | ||
return $fromCache; | ||
} | ||
|
||
$sourcePath = $this->fileLocator->locate('@CoreShopGoogleShoppingBundle/Resources/google/taxonomy-with-ids.txt'); | ||
$handle = fopen($sourcePath, 'r'); | ||
|
||
if ($handle) { | ||
while (($line = fgets($handle)) !== false) { | ||
$result = []; | ||
|
||
preg_match('/(\d+) - (.+)/', $line, $result); | ||
|
||
$options[] = [ | ||
'key' => $result[2], | ||
'value' => $result[1] | ||
]; | ||
} | ||
|
||
fclose($handle); | ||
} | ||
|
||
Cache::save($options, self::CACHE_KEY); | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function hasStaticOptions($context, $fieldDefinition) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getDefaultValue($context, $fieldDefinition) | ||
{ | ||
return $fieldDefinition->getDefaultValue(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
imports: | ||
- { resource: services/data_collector.yml } | ||
- { resource: services/object_filter.yml } | ||
- { resource: services/object_transformer.yml } | ||
- { resource: services/distributor.yml } | ||
- { resource: services/data_collector.yml } | ||
- { resource: services/object_filter.yml } | ||
- { resource: services/object_transformer.yml } | ||
- { resource: services/distributor.yml } | ||
|
||
services: | ||
_defaults: | ||
public: true | ||
_defaults: | ||
public: true | ||
|
||
CoreShop\Bundle\GoogleShoppingBundle\Command\GoogleShoppingCommand: | ||
arguments: | ||
- '@coreshop.google_shopping.data_collector.default' | ||
- '@coreshop.google_shopping.object_transformer' | ||
- '@coreshop.google_shopping.distributor' | ||
tags: | ||
- { name: console.command } | ||
CoreShop\Bundle\GoogleShoppingBundle\Command\GoogleShoppingCommand: | ||
arguments: | ||
- '@coreshop.google_shopping.data_collector.default' | ||
- '@coreshop.google_shopping.object_transformer' | ||
- '@coreshop.google_shopping.distributor' | ||
tags: | ||
- { name: console.command } | ||
|
||
coreshop.google_shopping.dynamic_options_provider.product_category: '@CoreShop\Bundle\GoogleShoppingBundle\Pimcore\DynamicOptionsProvider\ProductCategoryOptionsProvider' | ||
CoreShop\Bundle\GoogleShoppingBundle\Pimcore\DynamicOptionsProvider\ProductCategoryOptionsProvider: | ||
arguments: | ||
- '@file_locator' |
Oops, something went wrong.