Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update 5.0.4 beta #15

Open
wants to merge 17 commits into
base: feature/update-5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PHP Composer

on:
push:
branches: [ master 4.2 4.1 3.1 1.6 ]
branches: [ master 5.0 4.2 4.1 3.1 1.6 ]
pull_request:

jobs:
Expand All @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Install dependencies
run: php -r "copy('https://cs.symfony.com/download/php-cs-fixer-v3.phar', 'php-cs-fixer.phar');"
- name: Install dependencies
run: php -r "copy('https://cs.symfony.com/download/php-cs-fixer-v3.phar', 'php-cs-fixer.phar');"

- name: Run php-cs-fixer
run: php php-cs-fixer.phar fix --dry-run --config=.php_cs.php --cache-file=.php_cs.cache --verbose --show-progress=dots --diff --allow-risky=yes
- name: Run php-cs-fixer
run: php php-cs-fixer.phar fix --dry-run --config=.php_cs.php --cache-file=.php_cs.cache --verbose --show-progress=dots --diff --allow-risky=yes
3 changes: 2 additions & 1 deletion Command/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CleanupCommand extends Command implements CronCommandInterface
{
/** @var string */
protected static $defaultName = 'oro:akeneo:cleanup';
protected static $defaultName = 'oro:cron:akeneo:cleanup';

/** @var DoctrineHelper */
private $doctrineHelper;
Expand Down Expand Up @@ -46,6 +46,7 @@ public function configure()
<<<'HELP'
The <info>%command.name%</info> command clears fields changes for complete job records
from <comment>oro_integration_fields_changes</comment> table.

<info>php %command.full_name%</info>
HELP
);
Expand Down
2 changes: 1 addition & 1 deletion Controller/ValidateConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function validateConnectionAction(Request $request, Channel $channel = nu
'akeneoLocales' => $akeneoLocales,
'success' => $success,
'message' => $message,
'currencyList' => $this->currencyProvider->getCurrencies(),
'currencyList' => $this->currencyProvider->getCurrencyList(),
]
);
}
Expand Down
26 changes: 26 additions & 0 deletions Entity/AkeneoSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class AkeneoSettings extends Transport
* @ORM\Column(name="akeneo_product_filter", type="text", nullable=true)
*/
protected $productFilter;
/**
* @var string
*
* @ORM\Column(name="akeneo_conf_product_filter", type="text", nullable=true)
*/
protected $configurableProductFilter;
/**
* @var string
*
Expand Down Expand Up @@ -282,6 +288,26 @@ public function setProductFilter($productFilter)
return $this;
}

/**
* @return string
*/
public function getConfigurableProductFilter()
{
return $this->configurableProductFilter;
}

/**
* @param string $configurableProductFilter
*
* @return self
*/
public function setConfigurableProductFilter($configurableProductFilter)
{
$this->configurableProductFilter = $configurableProductFilter;

return $this;
}

/**
* @return ParameterBag
*/
Expand Down
4 changes: 2 additions & 2 deletions EntityConfig/ImportexportFieldConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function configure(NodeBuilder $nodeBuilder): void
{
$nodeBuilder
->scalarNode('source')
->info('`string` source of field.')
->info('`string` source of field.')
->end()
->scalarNode('source_name')
->info('`string` source name of field.')
->info('`string` source name of field.')
->end();
}
}
2 changes: 2 additions & 0 deletions Form/Extension/ChannelTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class ChannelTypeExtension extends AbstractTypeExtension
* @var array
*/
protected $connectorsOrder = [
'brand',
'category',
'attribute',
'attribute_family',
'product',
'configurable_product',
];

/**
Expand Down
9 changes: 9 additions & 0 deletions Form/Type/AkeneoSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]
)
->add(
'configurableProductFilter',
TextareaType::class,
[
'required' => false,
'label' => 'oro.akeneo.integration.settings.akeneo_configurable_product_filter.label',
'constraints' => [new JsonConstraint()],
]
)
->add(
'priceList',
PriceListSelectType::class,
Expand Down
2 changes: 1 addition & 1 deletion ImportExport/EventListener/OwnerStrategyEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function onProcessBefore(StrategyEvent $event)

protected function getChannel(ContextInterface $context)
{
if (!$this->channel) {
if (!$this->channel && $context->getOption('channel')) {
$this->channel = $this->doctrineHelper->getEntityReference(
Channel::class,
$context->getOption('channel')
Expand Down
43 changes: 0 additions & 43 deletions ImportExport/Processor/AsyncProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,8 @@

class AsyncProcessor implements ProcessorInterface
{
use CacheProviderAwareProcessor;

/** @var array */
private $variants = [];

public function process($item)
{
$this->updateVariants($item);

return $item;
}

private function updateVariants(array &$item)
{
$sku = $item['sku'];

if (!empty($item['family_variant'])) {
if (isset($item['parent'], $this->variants[$sku])) {
$parent = $item['parent'];
foreach (array_keys($this->variants[$sku]) as $sku) {
$this->variants[$parent][$sku] = ['parent' => $parent, 'variant' => $sku];
}
}

return;
}

if (empty($item['parent'])) {
return;
}

$parent = $item['parent'];

$this->variants[$parent][$sku] = ['parent' => $parent, 'variant' => $sku];
}

public function initialize()
{
$this->variants = [];
$this->cacheProvider->delete('product_variants');
}

public function flush()
{
$this->cacheProvider->save('product_variants', $this->variants);
$this->variants = [];
}
}
56 changes: 56 additions & 0 deletions ImportExport/Processor/BuildVariantCacheProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Oro\Bundle\AkeneoBundle\ImportExport\Processor;

use Oro\Bundle\ImportExportBundle\Processor\ProcessorInterface;

class BuildVariantCacheProcessor implements ProcessorInterface
{
use CacheProviderAwareProcessor;

/** @var array */
private $variants = [];

public function process($item)
{
$this->updateVariants($item);

return $item;
}

private function updateVariants(array &$item)
{
$sku = $item['sku'];

if (!empty($item['family_variant'])) {
if (isset($item['parent'], $this->variants[$sku])) {
$parent = $item['parent'];
foreach (array_keys($this->variants[$sku]) as $sku) {
$this->variants[$parent][$sku] = ['parent' => $parent, 'variant' => $sku];
}
}

return;
}

if (empty($item['parent'])) {
return;
}

$parent = $item['parent'];

$this->variants[$parent][$sku] = ['parent' => $parent, 'variant' => $sku];
}

public function initialize()
{
$this->variants = [];
$this->cacheProvider->delete('product_variants');
}

public function flush()
{
$this->cacheProvider->save('product_variants', $this->variants);
$this->variants = [];
}
}
43 changes: 39 additions & 4 deletions ImportExport/Processor/ProductVariantProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Oro\Bundle\ImportExportBundle\Context\ContextRegistry;
use Oro\Bundle\ImportExportBundle\Processor\ProcessorInterface;
use Oro\Bundle\ImportExportBundle\Strategy\Import\ImportStrategyHelper;
use Oro\Bundle\IntegrationBundle\Entity\Channel;
use Oro\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\ProductBundle\Entity\ProductVariantLink;
use Oro\Bundle\ProductBundle\Entity\Repository\ProductRepository;
Expand All @@ -30,6 +31,9 @@ class ProductVariantProcessor implements ProcessorInterface, StepExecutionAwareI
/** @var TranslatorInterface */
private $translator;

/** @var int */
private $organizationId;

public function __construct(
ManagerRegistry $registry,
ImportStrategyHelper $strategyHelper,
Expand Down Expand Up @@ -67,7 +71,7 @@ public function process($items)
/** @var ProductRepository $productRepository */
$productRepository = $objectManager->getRepository(Product::class);

$parentProduct = $productRepository->findOneBySku($parentSku);
$parentProduct = $this->findProductBySku($productRepository,$parentSku);
if (!$parentProduct instanceof Product) {
$context->incrementErrorEntriesCount();
$errorMessages = [
Expand Down Expand Up @@ -110,7 +114,7 @@ function ($variantSku) {
continue;
}

$variantProduct->setStatus(Product::STATUS_ENABLED);
// $variantProduct->setStatus(Product::STATUS_ENABLED);

unset($variantSkusUppercase[$variantProduct->getSkuUppercase()]);
}
Expand Down Expand Up @@ -139,7 +143,7 @@ function ($variantSku) {
$variantProduct->addParentVariantLink($variantLink);
$parentProduct->addVariantLink($variantLink);

$variantProduct->setStatus(Product::STATUS_ENABLED);
// $variantProduct->setStatus(Product::STATUS_ENABLED);

$context->incrementAddCount();

Expand All @@ -153,7 +157,7 @@ function ($variantSku) {

$objectManager->clear();

$parentProduct = $productRepository->findOneBySku($parentSku);
$parentProduct = $this->findProductBySku($productRepository,$parentSku);
if (!$parentProduct instanceof Product) {
return null;
}
Expand Down Expand Up @@ -181,4 +185,35 @@ function ($variantSku) {

return $parentProduct;
}

private function findProductBySku(ProductRepository $productRepository, $parentSku)
{
$organizationId = $this->getOrganizationId();

$qb = $productRepository->getBySkuQueryBuilder($parentSku);
$qb->andWhere($qb->expr()->eq('product.organization', ':organization'))
->setParameter('organization', $organizationId);

return $qb->getQuery()->getOneOrNullResult();
}

private function getOrganizationId(): ?int
{
if (!$this->organizationId) {
$channelId = $this->stepExecution->getJobExecution()->getExecutionContext()->get('channel');
if (!$channelId) {
return null;
}

/** @var Channel $channel */
$channel = $this->registry->getRepository(Channel::class)->find($channelId);
if (!$channel) {
return null;
}

$this->organizationId = $channel->getOrganization()->getId();
}

return $this->organizationId;
}
}
3 changes: 2 additions & 1 deletion ImportExport/Reader/ProductVariantReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ protected function initializeFromContext(ContextInterface $context)
{
parent::initializeFromContext($context);

$variants = $this->cacheProvider->fetch('akeneo')['variants'] ?? [];
$cache = $this->cacheProvider->fetch('product_variants') ;
$variants = $cache !== false ? $cache : [];

$this->stepExecution->setReadCount(count($variants));

Expand Down
Loading