Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Merge c7c384d into 11cc727
Browse files Browse the repository at this point in the history
  • Loading branch information
flagbird committed Feb 11, 2020
2 parents 11cc727 + c7c384d commit 3342660
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 15 deletions.
11 changes: 9 additions & 2 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ abstract protected function getNormalizer() : NormalizerInterface;

abstract protected function getAttributeRepository() : AttributeRepositoryInterface;

abstract protected function getAttributeCodeBlacklist() : array;

protected function normalizeProduct(EntityWithFamilyVariantInterface $product)
{
$normalizedProduct = $this->getNormalizer()->normalize($product, 'external_api');
Expand All @@ -25,9 +27,14 @@ protected function normalizeProduct(EntityWithFamilyVariantInterface $product)
unset($normalizedProduct['values'][$value->getAttributeCode()]);
}
$product = $parent;
};
}

$ignoredAttributeCodes = array_merge(
$this->getAttributeRepository()->findUniqueAttributeCodes(),
$this->getAttributeCodeBlacklist()
);

foreach ($this->getAttributeRepository()->findUniqueAttributeCodes() as $attributeCode) {
foreach ($ignoredAttributeCodes as $attributeCode) {
unset($normalizedProduct['values'][$attributeCode]);
}
unset($normalizedProduct['identifier']);
Expand Down
29 changes: 28 additions & 1 deletion src/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,72 @@ class ProductController extends AbstractController
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* @var ObjectUpdaterInterface
*/
private $productUpdater;

/**
* @var SaverInterface
*/
private $productSaver;

/**
* @var NormalizerInterface
*/
private $normalizer;

/**
* @var ValidatorInterface
*/
private $validator;

/**
* @var UserContext
*/
private $userContext;

/**
* @var ProductBuilderInterface
*/
private $productBuilder;

/**
* @var AttributeConverterInterface
*/
private $localizedConverter;

/**
* @var FilterInterface
*/
private $emptyValuesFilter;

/**
* @var ConverterInterface
*/
private $productValueConverter;

/**
* @var NormalizerInterface
*/
private $constraintViolationNormalizer;

/**
* @var ProductBuilderInterface
*/
private $variantProductBuilder;

/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;

/**
* @var string[]
*/
private $attributeCodeBlacklist;

public function __construct(
ProductRepositoryInterface $productRepository,
AttributeRepositoryInterface $attributeRepository,
Expand All @@ -87,7 +104,8 @@ public function __construct(
FilterInterface $emptyValuesFilter,
ConverterInterface $productValueConverter,
NormalizerInterface $constraintViolationNormalizer,
ProductBuilderInterface $variantProductBuilder
ProductBuilderInterface $variantProductBuilder,
array $attributeCodeBlacklist
) {

$this->productRepository = $productRepository;
Expand All @@ -103,6 +121,7 @@ public function __construct(
$this->constraintViolationNormalizer = $constraintViolationNormalizer;
$this->variantProductBuilder = $variantProductBuilder;
$this->attributeRepository = $attributeRepository;
$this->attributeCodeBlacklist = $attributeCodeBlacklist;
}

/**
Expand Down Expand Up @@ -216,6 +235,14 @@ private function updateProduct(ProductInterface $product, array $data)
$this->productUpdater->update($product, $data);
}

/**
* @return string[]
*/
protected function getAttributeCodeBlacklist() : array
{
return $this->attributeCodeBlacklist;
}

protected function getNormalizer() : NormalizerInterface
{
return $this->normalizer;
Expand Down
28 changes: 16 additions & 12 deletions src/Controller/ProductModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,17 @@ class ProductModelController extends AbstractController
* @var NormalizerInterface
*/
private $violationNormalizer;

/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;

/**
* DefaultController constructor.
*
* @param ProductModelRepositoryInterface $productModelRepository
* @param NormalizerInterface $normalizer
* @param SimpleFactoryInterface $productModelFactory
* @param ObjectUpdaterInterface $productModelUpdater
* @param SaverInterface $productModelSaver
* @param ValidatorInterface $validator
* @param NormalizerInterface $violiationNormalizer
* @param AttributeRepositoryInterface $attributeRepository
* @var string[]
*/
private $attributeCodeBlacklist;

public function __construct(
ProductModelRepositoryInterface $productModelRepository,
AttributeRepositoryInterface $attributeRepository,
Expand All @@ -75,16 +69,18 @@ public function __construct(
ObjectUpdaterInterface $productModelUpdater,
SaverInterface $productModelSaver,
ValidatorInterface $validator,
NormalizerInterface $violiationNormalizer
NormalizerInterface $violationNormalizer,
array $attributeCodeBlacklist
) {
$this->productModelRepository = $productModelRepository;
$this->normalizer = $normalizer;
$this->productModelFactory = $productModelFactory;
$this->productModelUpdater = $productModelUpdater;
$this->productModelSaver = $productModelSaver;
$this->validator = $validator;
$this->violationNormalizer = $violiationNormalizer;
$this->violationNormalizer = $violationNormalizer;
$this->attributeRepository = $attributeRepository;
$this->attributeCodeBlacklist = $attributeCodeBlacklist;
}

/**
Expand Down Expand Up @@ -153,6 +149,14 @@ public function cloneAction(Request $request) : JsonResponse
}
}

/**
* @return string[]
*/
protected function getAttributeCodeBlacklist() : array
{
return $this->attributeCodeBlacklist;
}

protected function getNormalizer() : NormalizerInterface
{
return $this->normalizer;
Expand Down
36 changes: 36 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Flagbit\Bundle\ProductClonerBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see
* {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$root = $treeBuilder->root('flagbit_product_cloner');

$root->children()
->arrayNode('attribute_blacklist')
->info('A list of attribute codes that need to be left out for the clone')
->defaultValue([])
->scalarPrototype()
->info('Valid attribute codes')
->end()
->end()
->end();

return $treeBuilder;
}
}
5 changes: 5 additions & 0 deletions src/DependencyInjection/FlagbitProductClonerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class FlagbitProductClonerExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$processedConfig = $this->processConfiguration($configuration, $configs);

$container->setParameter('flagbit_product_cloner.attribute_blacklist', $processedConfig['attribute_blacklist']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- '@pim_catalog.saver.product_model'
- '@pim_catalog.validator.product'
- '@pim_enrich.normalizer.violation'
- '%flagbit_product_cloner.attribute_blacklist%'
flagbit_product_cloner.controller.product:
class: Flagbit\Bundle\ProductClonerBundle\Controller\ProductController
arguments:
Expand All @@ -26,3 +27,4 @@ services:
- '@pim_enrich.converter.enrich_to_standard.product_value'
- '@pim_enrich.normalizer.product_violation'
- '@pim_catalog.builder.product'
- '%flagbit_product_cloner.attribute_blacklist%'

0 comments on commit 3342660

Please sign in to comment.