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

Migrate attribute group edit #31502

Merged
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b93d40b
creating attribute type
JevgenijVisockij Jun 28, 2023
a5cf1c0
Reverting package-lock.json
JevgenijVisockij Feb 23, 2023
07f6d2e
Reverting package-lock.json
JevgenijVisockij Feb 23, 2023
6884659
Adding behat tests
JevgenijVisockij Apr 13, 2023
fff3f77
Removed unneeded AttributeType.php
JevgenijVisockij Feb 24, 2023
a4cff18
Fixed form type
JevgenijVisockij Feb 24, 2023
ddad352
PHP stan fixes
JevgenijVisockij Feb 24, 2023
d82bfa2
Fixed template
JevgenijVisockij Feb 24, 2023
52abd99
CS fixer fix
JevgenijVisockij Apr 13, 2023
7bf4547
Added attribute group type for validation
JevgenijVisockij Apr 13, 2023
eb4caec
Changed to use repository in handlers
JevgenijVisockij Apr 13, 2023
cd1ba1d
Moved layout title to controller, changed EditAttributeGroupCommand.p…
JevgenijVisockij Mar 10, 2023
5c2cfe2
Update src/Core/Domain/AttributeGroup/ValueObject/AttributeGroupId.php
JevgenijVisockij Mar 10, 2023
fc869ce
Snaller changes from code review
JevgenijVisockij Mar 10, 2023
f227cc8
Update src/PrestaShopBundle/Resources/config/services/core/form/form_…
JevgenijVisockij Mar 10, 2023
56fd36c
Removed InvalidAttributeGroupIdException.php replacing iwth constrain…
JevgenijVisockij Apr 13, 2023
ff04f69
Changed attribute group to not use GetEditableAttribute group CQRS an…
JevgenijVisockij Mar 10, 2023
95764b4
Apply suggestions from code review
JevgenijVisockij Mar 10, 2023
210b72b
Update tests/Integration/Behaviour/Features/Context/Domain/AttributeG…
JevgenijVisockij Mar 10, 2023
5c81b80
Refactored behat tests to use multilantg
JevgenijVisockij Mar 10, 2023
f50a59f
Refactored attribute group js to use 2 separate files
JevgenijVisockij Apr 13, 2023
c874ba6
Apply suggestions from code review
JevgenijVisockij Apr 13, 2023
6638569
Removed unneeded exception and smaller fixes
JevgenijVisockij Apr 13, 2023
f5ae785
Apply suggestions from code review
JevgenijVisockij Apr 13, 2023
b7573f1
Cleaned up attribute group exceptions
JevgenijVisockij Apr 13, 2023
d664958
Cleaned up attribute group exceptions
JevgenijVisockij Apr 13, 2023
bff2679
CS fixer fix
JevgenijVisockij Apr 17, 2023
c1af84c
Updated phpdoc for AttributeGroupFeatureContext.php
JevgenijVisockij Apr 18, 2023
594c6cc
Update tests/Integration/Behaviour/Features/Context/Domain/AttributeG…
JevgenijVisockij Apr 19, 2023
b85cdbb
PHP stan fix
JevgenijVisockij Apr 19, 2023
840a17b
Apply suggestions from code review
JevgenijVisockij Apr 26, 2023
7fa4f83
Code review fixes
JevgenijVisockij May 2, 2023
46f6e78
Apply suggestions from code review
JevgenijVisockij May 2, 2023
d38a779
Code review fixes
JevgenijVisockij May 2, 2023
c174a81
Fixed not working update and add commands
JevgenijVisockij May 2, 2023
efb4588
CS fixer fix
JevgenijVisockij May 2, 2023
a36be2e
CS Fixer fixes
JevgenijVisockij May 2, 2023
8cdf3b6
Fixed multistore not working properly
JevgenijVisockij May 2, 2023
2fc82fb
Cs fixer fix
JevgenijVisockij May 3, 2023
bd3f85c
Fixed some typos
JevgenijVisockij May 10, 2023
d6be6ab
Fix last issues + implement export
Aug 21, 2023
7aa5916
Update src/PrestaShopBundle/Resources/config/services/bundle/form/for…
matthieu-rolland Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions admin-dev/themes/new-theme/.webpack/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = {
attachment: './js/pages/attachment',
attribute: './js/pages/attribute',
attribute_group: './js/pages/attribute-group',
attribute_group_form: './js/pages/attribute-group/form',
authorization_server: './js/pages/authorization-server',
backup: './js/pages/backup',
carrier: './js/pages/carrier',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

/**
* Defines all selectors that are used in customers address add/edit form.
*/
export default {
attributeGroupShopAssociationInput: '#attribute_group_shop_association',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

import AttributeGroupFormMap from '@pages/attribute-group/form/attribute-group-form-map';

const {$} = window;

$(() => {
window.prestashop.component.initComponents(
[
'TranslatableInput',
'TranslatableField',
],
);

new window.prestashop.component.ChoiceTree(AttributeGroupFormMap.attributeGroupShopAssociationInput).enableAutoCheckChildren();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\AttributeGroup\CommandHandler;

use AttributeGroup;
use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Adapter\Domain\AbstractObjectModelHandler;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\AddAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\CommandHandler\AddAttributeGroupHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupId;

/**
* Handles adding of attribute groups using legacy logic.
*/
#[AsCommandHandler]
final class AddAttributeGroupHandler extends AbstractObjectModelHandler implements AddAttributeGroupHandlerInterface
{
/**
* @var AttributeGroupRepository
*/
private $attributeGroupRepository;

public function __construct(AttributeGroupRepository $attributeGroupRepository)
{
$this->attributeGroupRepository = $attributeGroupRepository;
}
Comment on lines +48 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are in develop branch and we drop some PHP versions oldies, you can use constructor property promotion here (and in other handler classes) to simplify some lines.
Anyway, I'm not blocking your PR for this, but it can be a must have now in develop branch PRs! ;)


/**
* {@inheritdoc}
*/
public function handle(AddAttributeGroupCommand $command): AttributeGroupId
{
$attributeGroup = new AttributeGroup();

$attributeGroup->name = $command->getLocalizedNames();
$attributeGroup->public_name = $command->getLocalizedPublicNames();
$attributeGroup->group_type = $command->getType()->getValue();

$id = $this->attributeGroupRepository->add($attributeGroup);

$this->associateWithShops($attributeGroup, $command->getShopAssociation());
jolelievre marked this conversation as resolved.
Show resolved Hide resolved

return $id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\AttributeGroup\CommandHandler;

use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Adapter\Domain\AbstractObjectModelHandler;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\CommandHandler\EditAttributeGroupHandlerInterface;

/**
* Handles editing of attribute groups using legacy logic.
*/
#[AsCommandHandler]
final class EditAttributeGroupHandler extends AbstractObjectModelHandler implements EditAttributeGroupHandlerInterface
{
/**
* @var AttributeGroupRepository
*/
private $attributeGroupRepository;

public function __construct(AttributeGroupRepository $attributeGroupRepository)
{
$this->attributeGroupRepository = $attributeGroupRepository;
}

/**
* {@inheritdoc}
*/
public function handle(EditAttributeGroupCommand $command): void
{
$attributeGroup = $this->attributeGroupRepository->get($command->getAttributeGroupId());

$attributeGroup->name = $command->getLocalizedNames();
$attributeGroup->public_name = $command->getLocalizedPublicNames();
$attributeGroup->group_type = $command->getType()->getValue();

$this->attributeGroupRepository->update($attributeGroup);

$this->associateWithShops($attributeGroup, $command->getShopAssociation());
jolelievre marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\PrestaShop\Adapter\AttributeGroup\QueryHandler;

use PrestaShop\PrestaShop\Adapter\AttributeGroup\Repository\AttributeGroupRepository;
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsQueryHandler;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Query\GetAttributeGroupForEditing;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryHandler\GetAttributeGroupForEditingHandlerInterface;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryResult\EditableAttributeGroup;

/**
* Handles query which gets attribute group for editing
*/
#[AsQueryHandler]
final class GetAttributeGroupForEditingHandler implements GetAttributeGroupForEditingHandlerInterface
{
/**
* @var AttributeGroupRepository
*/
private $attributeGroupRepository;

public function __construct(AttributeGroupRepository $attributeGroupRepository)
{
$this->attributeGroupRepository = $attributeGroupRepository;
}

/**
* {@inheritdoc}
*/
public function handle(GetAttributeGroupForEditing $query): EditableAttributeGroup
{
$attributeGroup = $this->attributeGroupRepository->get($query->getAttributeGroupId());

return new EditableAttributeGroup(
$query->getAttributeGroupId()->getValue(),
$attributeGroup->name,
$attributeGroup->public_name,
$attributeGroup->group_type,
$attributeGroup->getAssociatedShops()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@

use AttributeGroup;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Adapter\AttributeGroup\Validate\AttributeGroupValidator;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\CannotAddAttributeGroupException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupId;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\InvalidShopConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopId;
use PrestaShop\PrestaShop\Core\Exception\CoreException;
use PrestaShop\PrestaShop\Core\Repository\AbstractMultiShopObjectModelRepository;

class AttributeGroupRepository extends AbstractMultiShopObjectModelRepository
Expand All @@ -48,12 +52,68 @@ class AttributeGroupRepository extends AbstractMultiShopObjectModelRepository
*/
private $dbPrefix;

/**
* @var AttributeGroupValidator
*/
private $validator;

public function __construct(
Connection $connection,
string $dbPrefix
string $dbPrefix,
AttributeGroupValidator $validator
) {
$this->connection = $connection;
$this->dbPrefix = $dbPrefix;
$this->validator = $validator;
}

/**
* @param AttributeGroupId $attributeGroupId
*
* @return AttributeGroup
*
* @throws AttributeGroupNotFoundException
* @throws CoreException
*/
public function get(AttributeGroupId $attributeGroupId): AttributeGroup
{
/** @var AttributeGroup $attributeGroup */
$attributeGroup = $this->getObjectModel(
$attributeGroupId->getValue(),
AttributeGroup::class,
AttributeGroupNotFoundException::class
);

return $attributeGroup;
}

/**
* @param AttributeGroup $attributeGroup
*
* @return AttributeGroupId
*
* @throws CoreException
*/
public function add(AttributeGroup $attributeGroup): AttributeGroupId
{
$this->validator->validate($attributeGroup);
$id = $this->addObjectModel($attributeGroup, CannotAddAttributeGroupException::class);

return new AttributeGroupId($id);
}

/**
* @param AttributeGroup $attributeGroup
* @param int $errorCode
*
* @return void
*
* @throws CoreException
*/
public function update(AttributeGroup $attributeGroup, int $errorCode = 0): void
{
$this->validator->validate($attributeGroup);
$this->updateObjectModel($attributeGroup, CannotAddAttributeGroupException::class, $errorCode);
}

/**
Expand Down