Skip to content

Commit

Permalink
Merge branch 'feature/magento2-integr' into task/ZON20001-0-update-m2…
Browse files Browse the repository at this point in the history
…-bundle
  • Loading branch information
24198 committed Jul 2, 2020
2 parents 584f866 + 9ac3f06 commit 0442000
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
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
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 0442000

Please sign in to comment.