Skip to content

Commit

Permalink
Merge branch 'feature/magento2-integr' into testmerge-magentoint
Browse files Browse the repository at this point in the history
  • Loading branch information
24198 committed Jun 19, 2020
2 parents b9016f8 + e45d024 commit a8352a6
Show file tree
Hide file tree
Showing 24 changed files with 437 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setAclHelper(AclHelper $aclHelper)
*
* @param ProductInterface $product
* @param SalesChannelGroup $group
* @return BalancedInventoryLevel
* @return null|BalancedInventoryLevel
*/
public function findExistingBalancedInventory(ProductInterface $product, SalesChannelGroup $group)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* )
* @ORM\Table(name="marello_assembled_ch_pr_list")
*/
class AssembledChannelPriceList extends ExtendAssembledChannelPriceList
class AssembledChannelPriceList extends ExtendAssembledChannelPriceList implements PriceListInterface
{
use EntityCreatedUpdatedAtTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* )
* @ORM\Table(name="marello_assembled_price_list")
*/
class AssembledPriceList extends ExtendAssembledPriceList
class AssembledPriceList extends ExtendAssembledPriceList implements PriceListInterface
{
use EntityCreatedUpdatedAtTrait;

Expand Down
28 changes: 28 additions & 0 deletions src/Marello/Bundle/PricingBundle/Entity/PriceListInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Marello\Bundle\PricingBundle\Entity;

use Marello\Bundle\ProductBundle\Entity\Product;

interface PriceListInterface
{
/**
* @return BasePrice
*/
public function getDefaultPrice();

/**
* @return BasePrice
*/
public function getSpecialPrice();

/**
* @return Product
*/
public function getProduct();

/**
* @return string
*/
public function getCurrency();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Marello\Bundle\PricingBundle\Entity\ProductChannelPrice;
use Marello\Bundle\SalesBundle\Form\Type\SalesChannelSelectType;
use Oro\Bundle\CurrencyBundle\Form\DataTransformer\MoneyValueTransformer;
use Oro\Bundle\FormBundle\Form\Type\OroMoneyType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
Expand Down Expand Up @@ -32,6 +33,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'constraints' => $options['allowed_empty_value'] === false ? new NotNull() : null,
'label' => 'marello.pricing.productprice.value.label',
]);

$builder->get('value')->addModelTransformer(new MoneyValueTransformer());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Marello\Bundle\PricingBundle\Form\Type;

use Marello\Bundle\PricingBundle\Entity\ProductPrice;
use Oro\Bundle\CurrencyBundle\Form\DataTransformer\MoneyValueTransformer;
use Oro\Bundle\FormBundle\Form\Type\OroMoneyType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
Expand Down Expand Up @@ -37,6 +38,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'marello.pricing.productprice.value.label',
]);
}

$builder->get('value')->addModelTransformer(new MoneyValueTransformer());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Marello/Bundle/ProductBundle/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Marello\Bundle\InventoryBundle\Model\InventoryItemAwareInterface;
use Marello\Bundle\PricingBundle\Entity\AssembledChannelPriceList;
use Marello\Bundle\PricingBundle\Entity\AssembledPriceList;
use Marello\Bundle\PricingBundle\Entity\ProductChannelPrice;
use Marello\Bundle\PricingBundle\Entity\PriceListInterface;
use Marello\Bundle\PricingBundle\Model\PricingAwareInterface;
use Marello\Bundle\ProductBundle\Model\ExtendProduct;
use Marello\Bundle\SalesBundle\Entity\SalesChannel;
Expand Down Expand Up @@ -1245,14 +1245,14 @@ public function getSalesChannelTaxCode(SalesChannel $salesChannel)

/**
* @param SalesChannel $salesChannel
* @return AssembledChannelPriceList|null
* @return PriceListInterface|null
*/
public function getSalesChannelPrice(SalesChannel $salesChannel)
{
/** @var ProductChannelPrice $productChannelPrice */
/** @var AssembledChannelPriceList $productChannelPrice */
$productChannelPrice = $this->getChannelPrices()
->filter(function ($productChannelPrice) use ($salesChannel) {
/** @var ProductChannelPrice $productChannelPrice */
/** @var AssembledChannelPriceList $productChannelPrice */
return $productChannelPrice->getChannel() === $salesChannel;
})
->first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,56 @@ public function findByChannel(SalesChannel $salesChannel)
return $this->aclHelper->apply($qb->getQuery())->getResult();
}

/**
* @param int $productId
* @return array
*/
public function getSalesChannelIdsByProductId(int $productId): array
{
$qb = $this->createQueryBuilder('product');
$qb
->select('sc.id')
->innerJoin('product.channels', 'sc')
->where($qb->expr()->eq('product.id', ':productId'))
->setParameter('productId', $productId);

$result = $qb->getQuery()->getArrayResult();

return array_column($result, 'id');
}

/**
* @param array $salesChannelIds
* @return int[]
*/
public function getProductIdsBySalesChannelIds(array $salesChannelIds): array
{
if (empty($salesChannelIds)) {
return [];
}

$subQb = $this->createQueryBuilder('innerProduct');
$subQb
->select('1')
->innerJoin('innerProduct.channels', 'sc')
->where(
$subQb->expr()->andX(
$subQb->expr()->in('sc.id', ':salesChannelIds'),
$subQb->expr()->eq('innerProduct.id', 'product.id')
)
);

$qb = $this->createQueryBuilder('product');
$qb
->select('product.id')
->where($qb->expr()->exists($subQb))
->setParameter('salesChannelIds', $salesChannelIds);

$result = $this->aclHelper->apply($qb->getQuery())->getResult();

return \array_column($result, 'id');
}

/**
* Return products for specified price list and product IDs
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Marello\Bundle\SalesBundle\Acl\Voter;

use Marello\Bundle\SalesBundle\Entity\Repository\SalesChannelGroupRepository;
use Marello\Bundle\SalesBundle\Entity\SalesChannelGroup;
use Oro\Bundle\SecurityBundle\Acl\BasicPermission;
use Oro\Bundle\SecurityBundle\Acl\Voter\AbstractEntityVoter;

/**
* Disables deleting the sales channel group in case when it has attached integration
*/
class SalesChannelGroupVoter extends AbstractEntityVoter
{
/** @var array */
protected $supportedAttributes = [BasicPermission::DELETE];

/**
* {@inheritdoc}
*/
protected function getPermissionForAttribute($class, $identifier, $attribute)
{
/** @var SalesChannelGroupRepository $scgRepository */
$scgRepository = $this->doctrineHelper->getEntityRepository(SalesChannelGroup::class);

if ($scgRepository->hasAttachedIntegration($identifier)) {
return self::ACCESS_DENIED;
}

return self::ACCESS_ABSTAIN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Marello\Bundle\SalesBundle\Autocomplete;

use Doctrine\ORM\QueryBuilder;
use Oro\Bundle\FormBundle\Autocomplete\SearchHandler;

/**
* @todo Cover with functional test
*/
class GroupSalesChannelHandler extends SearchHandler
{
/**
* {@inheritdoc}
*/
protected function checkAllDependenciesInjected()
{
if (!$this->entityRepository || !$this->idFieldName) {
throw new \RuntimeException('Search handler is not fully configured');
}
}

/**
* @param string $searchTerm
* @param int $firstResult
* @param int $maxResults
* @return QueryBuilder
*/
protected function prepareQueryBuilder($searchTerm, $firstResult, $maxResults)
{
$queryBuilder = $this->entityRepository->createQueryBuilder('scg');
$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}
*/
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)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\EntityRepository;
use Marello\Bundle\SalesBundle\Entity\SalesChannelGroup;
use Oro\Bundle\IntegrationBundle\Entity\Channel as IntegrationChannel;
use Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper;

class SalesChannelGroupRepository extends EntityRepository
Expand Down Expand Up @@ -33,4 +34,30 @@ public function findSystemChannelGroup()

return reset($result);
}

/**
* @param IntegrationChannel $integrationChannel
* @return SalesChannelGroup|null
*/
public function findSalesChannelGroupAttachedToIntegration(
IntegrationChannel $integrationChannel
): ?SalesChannelGroup {
return $this->findOneBy(['integrationChannel' => $integrationChannel]);
}

/**
* @param int $salesChannelGroupId
* @return bool
*/
public function hasAttachedIntegration(int $salesChannelGroupId): bool
{
$qb = $this->createQueryBuilder('scg');
$qb
->select('1')
->where($qb->expr()->eq('scg.id', ':salesChannelGroupId'))
->andWhere($qb->expr()->isNotNull('scg.integrationChannel'))
->setParameter('salesChannelGroupId', $salesChannelGroupId);

return (bool) $qb->getQuery()->getResult();
}
}
3 changes: 3 additions & 0 deletions src/Marello/Bundle/SalesBundle/Entity/SalesChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class SalesChannel extends ExtendSalesChannel implements
* defaultValues={
* "dataaudit"={
* "auditable"=true
* },
* "importexport"={
* "identity"=true
* }
* }
* )
Expand Down
Loading

0 comments on commit a8352a6

Please sign in to comment.