Skip to content

Commit

Permalink
Merge branch 'bugfix/MAR10001-0-fix-inventory-item-grid' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
24198 committed Jul 13, 2020
2 parents 3015ccf + 3d51851 commit f7a39f6
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ datagrids:
- p.denormalizedDefaultName as productName
- p.sku as productSku
- i.enableBatchInventory as enableBatchInventory
- productUnit.name as productUnit
- pu.name as productUnit
- COALESCE(SUM(il.inventory), 0) AS inventoryQty
- COALESCE(SUM(il.allocatedInventory), 0) AS allocatedInventoryQty
- COALESCE(SUM(il.inventory - il.allocatedInventory), 0) AS virtualInventoryQty
Expand All @@ -18,7 +18,7 @@ datagrids:
left:
- { join: i.product, alias: p }
- { join: i.inventoryLevels, alias: il }
- { join: i.productUnit, alias: productUnit }
- { join: i.productUnit, alias: pu }
groupBy: i.id
columns:
productSku:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,26 @@ protected function checkAllDependenciesInjected()

/**
* @param string $searchTerm
* @param int $firstResult
* @param int $maxResults
* @param int $firstResult
* @param int $maxResults
* @return QueryBuilder
*/
protected function prepareQueryBuilder($searchTerm, $firstResult, $maxResults)
{
$queryBuilder = $this->entityRepository->createQueryBuilder('scg');
$queryBuilder = $this->entityRepository->getNonSystemSalesChannelBySearchTermQB($searchTerm);
$queryBuilder
->where($queryBuilder->expr()->like('LOWER(scg.name)', ':searchTerm'))
->andWhere(($queryBuilder->expr()->eq('scg.system', $queryBuilder->expr()->literal(false))))
->setParameter('searchTerm', '%' . mb_strtolower($searchTerm) . '%')
->orderBy('scg.name', 'ASC')
->setFirstResult($firstResult)
->setMaxResults($maxResults);

return $queryBuilder;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function searchEntities($search, $firstResult, $maxResults)
{
$queryBuilder = $this->prepareQueryBuilder($search, $firstResult, $maxResults);
$query = $this->aclHelper->apply($queryBuilder, 'VIEW');

return $query->getResult();
}

/**
* {@inheritdoc}
*/
protected function findById($query)
{
$parts = explode(';', $query);
$id = $parts[0];

$criteria = [$this->idFieldName => $id];

return [$this->entityRepository->findOneBy($criteria, null)];
return $this->aclHelper->apply($queryBuilder->getQuery())->getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Marello\Bundle\SalesBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Marello\Bundle\SalesBundle\Entity\SalesChannelGroup;
use Oro\Bundle\IntegrationBundle\Entity\Channel as IntegrationChannel;
use Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper;
Expand Down Expand Up @@ -60,4 +61,20 @@ public function hasAttachedIntegration(int $salesChannelGroupId): bool

return (bool) $qb->getQuery()->getResult();
}

/**
* @param string $searchTerm
* @return QueryBuilder
*/
public function getNonSystemSalesChannelBySearchTermQB(string $searchTerm): QueryBuilder
{
$qb = $this->createQueryBuilder('scg');
$qb
->where($qb->expr()->like('LOWER(scg.name)', ':searchTerm'))
->andWhere(($qb->expr()->eq('scg.system', $qb->expr()->literal(false))))
->setParameter('searchTerm', '%' . mb_strtolower($searchTerm) . '%')
->orderBy('scg.name', 'ASC');

return $qb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@ public function setAclHelper(AclHelper $aclHelper)
$this->aclHelper = $aclHelper;
}

/**
* @param string $searchTerm
* @param int $groupId
* @param array $skippedSalesChannelIds
* @return QueryBuilder
*/
public function getActiveSalesChannelBySearchTermLimitedWithGroupIdQB(
string $searchTerm,
int $groupId,
array $skippedSalesChannelIds = []
): QueryBuilder {
$qb = $this->getActiveChannelsQuery();
$qb
->andWhere($qb->expr()->like('LOWER(sc.name)', ':searchTerm'))
->andWhere($qb->expr()->eq('sc.group', ':salesChannelGroupId'))
->setParameter('searchTerm', '%' . mb_strtolower($searchTerm) . '%')
->setParameter('salesChannelGroupId', $groupId)
->orderBy('sc.name', 'ASC');

if (!empty($skippedSalesChannelIds)) {
$qb
->andWhere($qb->expr()->notIn('sc.id', ':skippedSalesChannelIds'))
->setParameter('skippedSalesChannelIds', $skippedSalesChannelIds);
}

return $qb;
}

/**
* Return product prices for specified channel and productId
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Marello\Bundle\PricingBundle\Form\EventListener\CurrencySubscriber;
use Marello\Bundle\SalesBundle\Entity\SalesChannel;
use Oro\Bundle\CurrencyBundle\Form\Type\CurrencyType;
use Oro\Bundle\FormBundle\Utils\FormUtils;
use Oro\Bundle\LocaleBundle\Form\Type\LocalizationSelectType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MarelloSalesBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v1_3';
return 'v1_3_1';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Marello\Bundle\SalesBundle\Migrations\Schema\v1_3_1;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
*/
class MarelloSalesBundle implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
/** Tables generation **/
$this->modifyMarelloSalesSalesChannelGroupTable($schema);
}

/**
* {@inheritDoc}
*/
protected function modifyMarelloSalesSalesChannelGroupTable(Schema $schema)
{
$table = $schema->getTable('marello_sales_channel_group');
if (!$table->hasColumn('integration_channel_id')) {
$table->addColumn('integration_channel_id', 'integer', ['notnull' => false]);
}

if (!$table->hasIndex('UNIQ_759DCFAB3D6A9E29')) {
$table->addUniqueIndex(['integration_channel_id'], 'UNIQ_759DCFAB3D6A9E29');
}

if ($table->hasForeignKey('FK_759DCFAB3D6A9E29')) {
$table->addForeignKeyConstraint(
$schema->getTable('oro_integration_channel'),
['integration_channel_id'],
['id'],
['onDelete' => 'SET NULL', 'onUpdate' => null]
);
}
}
}
2 changes: 1 addition & 1 deletion src/Marello/Bundle/SalesBundle/Resources/config/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
class: 'Marello\Bundle\SalesBundle\Form\Type\SalesChannelGroupType'
tags:
- { name: form.type }

marello_sales_form_type.saleschannel_multi_select:
class: 'Marello\Bundle\SalesBundle\Form\Type\SalesChannelMultiSelectType'
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ services:
- 'Marello\Bundle\SalesBundle\Entity\SalesChannelGroup'
- ['name']
tags:
- { name: oro_form.autocomplete.search_handler, alias: group_saleschannels }
- { name: oro_form.autocomplete.search_handler, alias: group_saleschannels, acl_resource: marello_product_view }

marello_sales.active_saleschannels.form.autocomplete.search_handler:
class: 'Marello\Bundle\SalesBundle\Autocomplete\ActiveSalesChannelHandler'
Expand Down

0 comments on commit f7a39f6

Please sign in to comment.