-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-29: Add functionality to map relation between website and sales_ch…
…annel on the integration form (#54)
- Loading branch information
1 parent
9c76576
commit c9a5ad9
Showing
42 changed files
with
1,938 additions
and
183 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Marello/Bundle/Magento2Bundle/Autocomplete/SalesChannelInGroupHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Marello\Bundle\Magento2Bundle\Autocomplete; | ||
|
||
use Marello\Bundle\SalesBundle\Entity\Repository\SalesChannelRepository; | ||
use Oro\Bundle\FormBundle\Autocomplete\SearchHandler; | ||
|
||
/** | ||
* @todo Cover with functional test | ||
*/ | ||
class SalesChannelInGroupHandler extends SearchHandler | ||
{ | ||
private const DELIMITER = ';'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function checkAllDependenciesInjected() | ||
{ | ||
if (!$this->entityRepository || !$this->idFieldName) { | ||
throw new \RuntimeException('Search handler is not fully configured'); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function searchEntities($search, $firstResult, $maxResults) | ||
{ | ||
$parts = explode(self::DELIMITER, $search); | ||
if (3 !== count($parts)) { | ||
return []; | ||
} | ||
|
||
$searchTerm = $parts[0]; | ||
$salesChannelGroupId = (int) $parts[1]; | ||
$skippedSalesChannelIds = '' !== $parts[2] ? explode(',', $parts[2]) : []; | ||
|
||
$resultEntities = []; | ||
if (0 !== $salesChannelGroupId) { | ||
/** @var SalesChannelRepository $repository */ | ||
$repository = $this->entityRepository; | ||
$queryBuilder = $repository->getActiveSalesChannelBySearchTermLimitedWithGroupIdQB( | ||
$searchTerm, | ||
$salesChannelGroupId, | ||
$skippedSalesChannelIds | ||
); | ||
|
||
$queryBuilder | ||
->setFirstResult($firstResult) | ||
->setMaxResults($maxResults); | ||
|
||
$resultEntities = $this->aclHelper->apply($queryBuilder->getQuery())->getResult(); | ||
} | ||
|
||
return $resultEntities; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/Marello/Bundle/Magento2Bundle/DTO/WebsiteToSalesChannelMappingItemDTO.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace Marello\Bundle\Magento2Bundle\DTO; | ||
|
||
class WebsiteToSalesChannelMappingItemDTO implements \JsonSerializable | ||
{ | ||
/** @var string[] */ | ||
public const REQUIRED_KEYS = [ | ||
'originWebsiteId', | ||
'websiteName', | ||
'salesChannelId', | ||
'salesChannelName' | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $originData = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $data = []; | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$notExistedKeys = \array_diff_key(\array_flip(self::REQUIRED_KEYS), $data); | ||
if (!empty($notExistedKeys)) { | ||
throw new \LogicException( | ||
'The website to sales channel mapping item must contains all required keys.', | ||
[ | ||
'missedKeys' => $notExistedKeys, | ||
'originalData' => $data | ||
] | ||
); | ||
} | ||
|
||
$this->originData = $data; | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getOriginWebsiteId(): int | ||
{ | ||
return $this->data['originWebsiteId']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getWebsiteName(): string | ||
{ | ||
return $this->data['websiteName']; | ||
} | ||
|
||
/** | ||
* @param string $websiteName | ||
*/ | ||
public function setWebsiteName(string $websiteName): void | ||
{ | ||
$this->data['websiteName'] = $websiteName; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSalesChannelId(): int | ||
{ | ||
return $this->data['salesChannelId']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSalesChannelName(): string | ||
{ | ||
return $this->data['salesChannelName']; | ||
} | ||
|
||
/** | ||
* @param string $salesChannelName | ||
*/ | ||
public function setSalesChannelName(string $salesChannelName): void | ||
{ | ||
$this->data['salesChannelName'] = $salesChannelName; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOriginData(): array | ||
{ | ||
return $this->originData; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Marello/Bundle/Magento2Bundle/Form/Type/SalesChannelInGroupSelectType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Marello\Bundle\Magento2Bundle\Form\Type; | ||
|
||
use Oro\Bundle\FormBundle\Form\Type\OroJquerySelect2HiddenType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class SalesChannelInGroupSelectType extends AbstractType | ||
{ | ||
private const BLOCK_PREFIX = 'marello_magento2_sales_channel_in_group_select'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults( | ||
[ | ||
'componentName' => 'salesChannelInGroupSelectComponent', | ||
'autocomplete_alias' => 'magento2_saleschannels_in_group', | ||
'configs' => [ | ||
'allowClear' => false, | ||
'component' => 'autocomplete-magento2-sales-channel-in-group', | ||
'placeholder' => 'marello.sales.saleschannel.form.select_saleschannel', | ||
'result_template_twig' => 'MarelloMagento2Bundle:SalesChannel:Autocomplete/result.html.twig', | ||
'selection_template_twig' => 'MarelloMagento2Bundle:SalesChannel:Autocomplete/selection.html.twig' | ||
], | ||
'attr' => [ | ||
'data-role' => 'sales-channel-in-group-select' | ||
] | ||
] | ||
); | ||
} | ||
|
||
public function buildView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
parent::buildView($view, $form, $options); | ||
|
||
$vars = [ | ||
'attr' => [ | ||
'data-page-component-name' => $options['componentName'] | ||
] | ||
]; | ||
|
||
$view->vars = array_replace_recursive($view->vars, $vars); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParent() | ||
{ | ||
return OroJquerySelect2HiddenType::class; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBlockPrefix() | ||
{ | ||
return self::BLOCK_PREFIX; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.