forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrestaShop#11153 from tomas862/migration-brands-an…
…d-suppliers-list Migration of "Catalog > Brand & Suppliers > Suppliers" listing
- Loading branch information
Showing
47 changed files
with
3,108 additions
and
3 deletions.
There are no files selected for viewing
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,50 @@ | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* 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.txt. | ||
* 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 [email protected] 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 http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
import Grid from "../../components/grid/grid"; | ||
import SortingExtension from "../../components/grid/extension/sorting-extension"; | ||
import FiltersResetExtension from "../../components/grid/extension/filters-reset-extension"; | ||
import SubmitGridActionExtension from "../../components/grid/extension/submit-grid-action-extension"; | ||
import ColumnTogglingExtension from "../../components/grid/extension/column-toggling-extension"; | ||
import SubmitRowActionExtension from "../../components/grid/extension/action/row/submit-row-action-extension"; | ||
import BulkActionCheckboxExtension from "../../components/grid/extension/bulk-action-checkbox-extension"; | ||
import SubmitBulkActionExtension from "../../components/grid/extension/submit-bulk-action-extension"; | ||
import ReloadListExtension from "../../components/grid/extension/reload-list-extension"; | ||
import ExportToSqlManagerExtension from "../../components/grid/extension/export-to-sql-manager-extension"; | ||
|
||
const $ = window.$; | ||
|
||
$(() => { | ||
const supplierGrid = new Grid('suppliers'); | ||
supplierGrid.addExtension(new SortingExtension()); | ||
supplierGrid.addExtension(new SubmitGridActionExtension()); | ||
supplierGrid.addExtension(new FiltersResetExtension()); | ||
supplierGrid.addExtension(new ColumnTogglingExtension()); | ||
supplierGrid.addExtension(new SubmitRowActionExtension()); | ||
supplierGrid.addExtension(new BulkActionCheckboxExtension()); | ||
supplierGrid.addExtension(new SubmitBulkActionExtension()); | ||
supplierGrid.addExtension(new ReloadListExtension()); | ||
supplierGrid.addExtension(new ExportToSqlManagerExtension()); | ||
}); |
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
197 changes: 197 additions & 0 deletions
197
src/Adapter/Supplier/CommandHandler/AbstractDeleteSupplierHandler.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,197 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop. | ||
* | ||
* 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.txt. | ||
* 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 [email protected] 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 http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Supplier\CommandHandler; | ||
|
||
use Address; | ||
use Db; | ||
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierAddressProvider; | ||
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierOrderValidator; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\CannotDeleteSupplierAddressException; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\CannotDeleteSupplierException; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\CannotDeleteSupplierProductRelationException; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierException; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierNotFoundException; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\ValueObject\SupplierId; | ||
use PrestaShopException; | ||
use Supplier; | ||
|
||
/** | ||
* Class AbstractDeleteSupplierHandler defines common actions required for | ||
* both BulkDeleteSupplierHandler and DeleteSupplierHandler. | ||
*/ | ||
abstract class AbstractDeleteSupplierHandler | ||
{ | ||
/** | ||
* @var SupplierOrderValidator | ||
*/ | ||
private $supplierOrderValidator; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $dbPrefix; | ||
|
||
/** | ||
* @var SupplierAddressProvider | ||
*/ | ||
private $supplierAddressProvider; | ||
|
||
/** | ||
* @param SupplierOrderValidator $supplierOrderValidator | ||
* @param SupplierAddressProvider $supplierAddressProvider | ||
* @param string $dbPrefix | ||
*/ | ||
public function __construct( | ||
SupplierOrderValidator $supplierOrderValidator, | ||
SupplierAddressProvider $supplierAddressProvider, | ||
$dbPrefix | ||
) { | ||
$this->supplierOrderValidator = $supplierOrderValidator; | ||
$this->dbPrefix = $dbPrefix; | ||
$this->supplierAddressProvider = $supplierAddressProvider; | ||
} | ||
|
||
/** | ||
* Removes supplier and all related content with it such as image, supplier and product relation | ||
* and supplier address. | ||
* | ||
* @param SupplierId $supplierId | ||
* | ||
* @throws SupplierException | ||
*/ | ||
protected function removeSupplier(SupplierId $supplierId) | ||
{ | ||
try { | ||
$entity = new Supplier($supplierId->getValue()); | ||
|
||
if (0 >= $entity->id) { | ||
throw new SupplierNotFoundException( | ||
sprintf( | ||
'Supplier object with id "%s" has not been found for deletion.', | ||
$supplierId->getValue() | ||
) | ||
); | ||
} | ||
|
||
if ($this->hasPendingOrders($supplierId)) { | ||
throw new CannotDeleteSupplierException( | ||
$supplierId->getValue(), | ||
sprintf( | ||
'Supplier with id %s cannot be deleted due to it has pending orders', | ||
$supplierId->getValue() | ||
), | ||
CannotDeleteSupplierException::HAS_PENDING_ORDERS | ||
); | ||
} | ||
|
||
if (false === $this->deleteProductSupplierRelation($supplierId)) { | ||
throw new CannotDeleteSupplierProductRelationException( | ||
sprintf( | ||
'Unable to delete suppliers with id "%s" product relation from product_supplier table', | ||
$supplierId->getValue() | ||
) | ||
); | ||
} | ||
|
||
if (false === $this->deleteSupplierAddress($supplierId)) { | ||
throw new CannotDeleteSupplierAddressException( | ||
sprintf( | ||
'Unable to set deleted flag for supplier with id "%s" address', | ||
$supplierId->getValue() | ||
) | ||
); | ||
} | ||
|
||
if (false === $entity->delete()) { | ||
throw new CannotDeleteSupplierException( | ||
$supplierId->getValue(), | ||
sprintf( | ||
'Unable to delete supplier object with id "%s"', | ||
$supplierId->getValue() | ||
) | ||
); | ||
} | ||
} catch (PrestaShopException $exception) { | ||
throw new SupplierException( | ||
sprintf( | ||
'An error occurred when deleting the supplier object with id "%s"', | ||
$supplierId->getValue() | ||
), | ||
0, | ||
$exception | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Deletes product supplier relation. | ||
* | ||
* @param SupplierId $supplierId | ||
* | ||
* @return bool | ||
*/ | ||
private function deleteProductSupplierRelation(SupplierId $supplierId) | ||
{ | ||
$sql = 'DELETE FROM `' . $this->dbPrefix . 'product_supplier` WHERE `id_supplier`=' . $supplierId->getValue(); | ||
|
||
return Db::getInstance()->execute($sql); | ||
} | ||
|
||
/** | ||
* Deletes supplier address. | ||
* | ||
* @param SupplierId $supplierId | ||
* | ||
* @return bool | ||
*/ | ||
private function deleteSupplierAddress(SupplierId $supplierId) | ||
{ | ||
$supplierAddressId = $this->supplierAddressProvider->getIdBySupplier($supplierId->getValue()); | ||
|
||
$address = new Address($supplierAddressId); | ||
|
||
if ($address->id) { | ||
$address->deleted = true; | ||
|
||
return $address->update(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Checks if the given supplier has pending orders. | ||
* | ||
* @param SupplierId $supplierId | ||
* | ||
* @return bool | ||
*/ | ||
private function hasPendingOrders(SupplierId $supplierId) | ||
{ | ||
return $this->supplierOrderValidator->hasPendingOrders($supplierId->getValue()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Adapter/Supplier/CommandHandler/BulkDeleteSupplierHandler.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,49 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop. | ||
* | ||
* 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.txt. | ||
* 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 [email protected] 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 http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Supplier\CommandHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\BulkDeleteSupplierCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\CommandHandler\BulkDeleteSupplierHandlerInterface; | ||
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierException; | ||
|
||
/** | ||
* Class BulkDeleteSupplierHandler is responsible for deleting multiple suppliers. | ||
*/ | ||
final class BulkDeleteSupplierHandler extends AbstractDeleteSupplierHandler implements BulkDeleteSupplierHandlerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws SupplierException | ||
*/ | ||
public function handle(BulkDeleteSupplierCommand $command) | ||
{ | ||
foreach ($command->getSupplierIds() as $supplierId) { | ||
$this->removeSupplier($supplierId); | ||
} | ||
} | ||
} |
Oops, something went wrong.