-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
customer page, favorite products list
- Loading branch information
Showing
19 changed files
with
316 additions
and
6 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
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Hook; | ||
|
||
use Oksydan\IsFavoriteProducts\Services\FavoriteProductService; | ||
use Twig\Environment; | ||
|
||
abstract class AbstractDisplayAdminHook extends AbstractHook | ||
{ | ||
/** | ||
* @var Environment | ||
*/ | ||
protected Environment $twig; | ||
|
||
public function __construct( | ||
\Is_favoriteproducts $module, | ||
\Context $context, | ||
FavoriteProductService $favoriteProductService, | ||
Environment $twig | ||
) { | ||
parent::__construct($module, $context, $favoriteProductService); | ||
$this->twig = $twig; | ||
} | ||
|
||
public function execute(array $params): string | ||
{ | ||
if (!$this->shouldBlockBeDisplayed($params)) { | ||
return ''; | ||
} | ||
|
||
return $this->twig->render($this->getTemplateFullPath(), $this->getTemplateVariables($params)); | ||
} | ||
|
||
protected function getTemplateVariables(array $params): array | ||
{ | ||
return []; | ||
} | ||
|
||
protected function shouldBlockBeDisplayed(array $params) | ||
{ | ||
return true; | ||
} | ||
|
||
public function getTemplateFullPath(): string | ||
{ | ||
return "@Modules/{$this->module->name}/views/templates/hook/admin/{$this->getTemplate()}"; | ||
} | ||
|
||
abstract protected function getTemplate(): string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Hook; | ||
|
||
use Oksydan\IsFavoriteProducts\Presenter\AdminFavoriteProductPresenter; | ||
use Oksydan\IsFavoriteProducts\Provider\CustomerFavoriteProductsProvider; | ||
use Oksydan\IsFavoriteProducts\Services\FavoriteProductService; | ||
use PrestaShop\PrestaShop\Adapter\Validate; | ||
use Twig\Environment; | ||
|
||
class DisplayAdminCustomers extends AbstractDisplayAdminHook | ||
{ | ||
protected CustomerFavoriteProductsProvider $customerFavoriteProductsProvider; | ||
|
||
protected AdminFavoriteProductPresenter $adminFavoriteProductPresenter; | ||
|
||
public function __construct( | ||
\Is_favoriteproducts $module, | ||
\Context $context, | ||
FavoriteProductService $favoriteProductService, | ||
Environment $twig, | ||
CustomerFavoriteProductsProvider $customerFavoriteProductsProvider, | ||
AdminFavoriteProductPresenter $adminFavoriteProductPresenter | ||
) { | ||
parent::__construct($module, $context, $favoriteProductService, $twig); | ||
$this->customerFavoriteProductsProvider = $customerFavoriteProductsProvider; | ||
$this->adminFavoriteProductPresenter = $adminFavoriteProductPresenter; | ||
} | ||
|
||
private const TEMPLATE_FILE = 'displayAdminCustomers.html.twig'; | ||
|
||
protected function getTemplate(): string | ||
{ | ||
return self::TEMPLATE_FILE; | ||
} | ||
|
||
protected function getTemplateVariables(array $params): array | ||
{ | ||
$idCustomer = (int) $params['id_customer']; | ||
$customer = new \Customer($idCustomer); | ||
|
||
if (!Validate::isLoadedObject($customer)) { | ||
return []; | ||
} | ||
|
||
$shop = new \Shop($customer->id_shop); | ||
|
||
if (!Validate::isLoadedObject($shop)) { | ||
return []; | ||
} | ||
|
||
$productsRaw = $this->customerFavoriteProductsProvider->getFavoriteProductsByCustomer($customer, $shop); | ||
$products = []; | ||
|
||
foreach ($productsRaw as $productRaw) { | ||
$products[] = $this->adminFavoriteProductPresenter->present($productRaw, $this->context->language); | ||
} | ||
|
||
return [ | ||
'products' => $products, | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Presenter; | ||
|
||
use Oksydan\IsFavoriteProducts\DTO\FavoriteProduct; | ||
use Oksydan\IsFavoriteProducts\Repository\ProductLegacyRepository; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class AdminFavoriteProductPresenter implements AdminFavoriteProductPresenterInterface | ||
{ | ||
/** | ||
* @var RouterInterface $router | ||
*/ | ||
protected RouterInterface $router; | ||
|
||
protected ProductLegacyRepository $productLegacyRepository; | ||
|
||
protected const DATE_FORMAT = 'Y-m-d H:i:s'; | ||
|
||
public function __construct( | ||
RouterInterface $router, | ||
ProductLegacyRepository $productLegacyRepository | ||
) | ||
{ | ||
$this->router = $router; | ||
$this->productLegacyRepository = $productLegacyRepository; | ||
} | ||
|
||
public function present(FavoriteProduct $favoriteProduct, \Language $language): array | ||
{ | ||
$productObject = new \Product($favoriteProduct->getIdProduct(), false, $language->id); | ||
$idAttribute = $favoriteProduct->getIdProductAttribute(); | ||
$productName = $productObject->name; | ||
|
||
if ($idAttribute > 0) { | ||
$combination = $this->productLegacyRepository->getProductCombinationForIdProductAttribute($favoriteProduct->getIdProduct(), $idAttribute, $language->id); | ||
|
||
$combinationName = array_reduce($combination, function ($combinationReduced, $combination) { | ||
$combinationReduced[] = $combination['group_name'] . ': ' . $combination['attribute_name']; | ||
|
||
return $combinationReduced; | ||
}, []); | ||
|
||
$productName = $productName . ' - ' . implode(', ', $combinationName); | ||
} | ||
|
||
$admin_url = $this->router->generate('admin_product_form', [ | ||
'id' => $favoriteProduct->getIdProduct(), | ||
]); | ||
|
||
return [ | ||
'id' => $favoriteProduct->getIdProduct(), | ||
'name' => $productName, | ||
'admin_url' => $admin_url, | ||
'date_add' => $favoriteProduct->getDateAdd()->format(self::DATE_FORMAT), | ||
]; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Presenter; | ||
|
||
use Oksydan\IsFavoriteProducts\DTO\FavoriteProduct; | ||
|
||
interface AdminFavoriteProductPresenterInterface | ||
{ | ||
public function present(FavoriteProduct $favoriteProduct, \Language $language): array; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Provider; | ||
|
||
use Oksydan\IsFavoriteProducts\Entity\FavoriteProduct; | ||
use Oksydan\IsFavoriteProducts\Mapper\FavoriteProductMapper; | ||
use Oksydan\IsFavoriteProducts\Repository\FavoriteProductRepository; | ||
|
||
class CustomerFavoriteProductsProvider implements CustomerFavoriteProductsProviderInterface | ||
{ | ||
|
||
/* | ||
* @var FavoriteProductRepository $favoriteProductsRepository | ||
*/ | ||
private FavoriteProductRepository $favoriteProductsRepository; | ||
|
||
/** | ||
* @var FavoriteProductMapper $favoriteProductMapper | ||
*/ | ||
private FavoriteProductMapper $favoriteProductMapper; | ||
|
||
public function __construct( | ||
FavoriteProductRepository $favoriteProductsRepository, | ||
FavoriteProductMapper $favoriteProductMapper | ||
) | ||
{ | ||
$this->favoriteProductsRepository = $favoriteProductsRepository; | ||
$this->favoriteProductMapper = $favoriteProductMapper; | ||
} | ||
|
||
public function getFavoriteProductsByCustomer(\Customer $customer, \Shop $shop): array | ||
{ | ||
$favoriteProducts = $this->favoriteProductsRepository->getFavoriteProductsByCustomer( | ||
(int) $customer->id, | ||
(int) $shop->id | ||
); | ||
|
||
$products = array_map(function (FavoriteProduct $favoriteProduct) { | ||
return $this->favoriteProductMapper->mapFavoriteProductEntityToFavoriteProductDTO($favoriteProduct); | ||
}, $favoriteProducts); | ||
|
||
return $products; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Provider/CustomerFavoriteProductsProviderInterface.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsFavoriteProducts\Provider; | ||
|
||
|
||
interface CustomerFavoriteProductsProviderInterface | ||
{ | ||
public function getFavoriteProductsByCustomer(\Customer $customer, \Shop $shop): array; | ||
} |
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
37 changes: 37 additions & 0 deletions
37
views/templates/hook/admin/displayAdminCustomers.html.twig
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,37 @@ | ||
{% if products is not empty %} | ||
<div class="col-md-6 col"> | ||
|
||
<div class="card customer-favorite-products-card"> | ||
<h3 class="card-header"> | ||
<i class="material-icons">favorite</i> | ||
{{ 'Favorite products'|trans({}, 'Modules.Isfavoriteproducts.Admin') }} | ||
<span class="badge badge-primary rounded">{{ products|length }}</span> | ||
</h3> | ||
<div class="card-body"> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>{{ 'ID'|trans({}, 'Admin.Global') }}</th> | ||
<th>{{ 'Name'|trans({}, 'Admin.Global') }}</th> | ||
<th>{{ 'Data add'|trans({}, 'Admin.Global') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for product in products %} | ||
<tr> | ||
<td>{{ product.id }}</td> | ||
<td> | ||
<a href="{{ product.admin_url }}"> | ||
{{ product.name }} | ||
</a> | ||
</td> | ||
<td>{{ product.date_add }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
{% endif %} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.