Skip to content

Commit

Permalink
Merge pull request PrestaShop#11153 from tomas862/migration-brands-an…
Browse files Browse the repository at this point in the history
…d-suppliers-list

Migration of "Catalog > Brand & Suppliers > Suppliers" listing
  • Loading branch information
matks authored Jan 11, 2019
2 parents ce44a89 + 0a5ca8b commit fc5da24
Show file tree
Hide file tree
Showing 47 changed files with 3,108 additions and 3 deletions.
50 changes: 50 additions & 0 deletions admin-dev/themes/new-theme/js/pages/supplier/index.js
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());
});
3 changes: 3 additions & 0 deletions admin-dev/themes/new-theme/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const config = {
currency: [
'./js/pages/currency',
],
supplier: [
'./js/pages/supplier',
],
},
output: {
path: path.resolve(__dirname, 'public'),
Expand Down
5 changes: 4 additions & 1 deletion classes/helper/HelperList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
class HelperListCore extends Helper
{
/** @var int size which is used for lists image thumbnail generation. */
const LIST_THUMBNAIL_SIZE = 45;

/** @var array Cache for query results */
protected $_list = array();

Expand Down Expand Up @@ -316,7 +319,7 @@ public function displayListContent()
} else {
$path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . Image::getImgFolderStatic($tr['id_image']) . (int) $tr['id_image'] . '.' . $this->imageType;
}
$this->_list[$index][$key] = ImageManager::thumbnail($path_to_image, $this->table . '_mini_' . $item_id . '_' . $this->context->shop->id . '.' . $this->imageType, 45, $this->imageType);
$this->_list[$index][$key] = ImageManager::thumbnail($path_to_image, $this->table . '_mini_' . $item_id . '_' . $this->context->shop->id . '.' . $this->imageType, self::LIST_THUMBNAIL_SIZE, $this->imageType);
} elseif (isset($params['icon'], $tr[$key]) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) {
if (!$this->bootstrap) {
if (isset($params['icon'][$tr[$key]]) && is_array($params['icon'][$tr[$key]])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Language/LanguageFlagThumbnailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace PrestaShop\PrestaShop\Adapter\Language;

use HelperList;
use ImageManager;
use PrestaShop\PrestaShop\Core\Image\ImageProviderInterface;
use PrestaShop\PrestaShop\Core\Image\Parser\ImageTagSourceParserInterface;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function getPath($languageId)
$imageTag = ImageManager::thumbnail(
$pathToImage,
'lang_mini_' . $languageId . '_' . $this->contextShopId . '.jpg',
45,
HelperList::LIST_THUMBNAIL_SIZE,
'jpg'
);

Expand Down
197 changes: 197 additions & 0 deletions src/Adapter/Supplier/CommandHandler/AbstractDeleteSupplierHandler.php
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 src/Adapter/Supplier/CommandHandler/BulkDeleteSupplierHandler.php
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);
}
}
}
Loading

0 comments on commit fc5da24

Please sign in to comment.