first commit
This commit is contained in:
64
modules/blockwishlist/src/Access/CustomerAccess.php
Normal file
64
modules/blockwishlist/src/Access/CustomerAccess.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Access;
|
||||
|
||||
use Customer;
|
||||
use Tools;
|
||||
use Validate;
|
||||
use WishList;
|
||||
|
||||
class CustomerAccess
|
||||
{
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
private $customer;
|
||||
|
||||
public function __construct(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasReadAccessToWishlist(WishList $wishlist)
|
||||
{
|
||||
// Wishlist is shared
|
||||
if (!empty($wishlist->token) && Tools::getIsset('token')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasWriteAccessToWishlist($wishlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasWriteAccessToWishlist(WishList $wishlist)
|
||||
{
|
||||
if (false === Validate::isLoadedObject($this->customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((int) $wishlist->id_customer) === $this->customer->id;
|
||||
}
|
||||
}
|
||||
264
modules/blockwishlist/src/Calculator/StatisticsCalculator.php
Normal file
264
modules/blockwishlist/src/Calculator/StatisticsCalculator.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Calculator;
|
||||
|
||||
use Customer;
|
||||
use DateTime;
|
||||
use Db;
|
||||
use DbQuery;
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Adapter\LegacyContext;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
|
||||
use PrestaShop\PrestaShop\Core\Localization\Locale;
|
||||
use PrestaShop\PrestaShop\Core\Product\ProductPresenter;
|
||||
use ProductAssembler;
|
||||
use ProductPresenterFactory;
|
||||
|
||||
class StatisticsCalculator
|
||||
{
|
||||
const ARRAY_KEYS_STATS = [
|
||||
'allTime',
|
||||
'currentYear',
|
||||
'currentMonth',
|
||||
'currentDay',
|
||||
];
|
||||
|
||||
private $context;
|
||||
private $productAssembler;
|
||||
|
||||
/**
|
||||
* @var Locale
|
||||
*/
|
||||
private $locale;
|
||||
|
||||
public function __construct(LegacyContext $context, Locale $locale)
|
||||
{
|
||||
$this->context = $context->getContext();
|
||||
$this->context->customer = new Customer();
|
||||
$this->productAssembler = new ProductAssembler($this->context);
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* computeStatsFor
|
||||
*
|
||||
* @param string|null $statsRange
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function computeStatsFor($statsRange = null)
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('id_product');
|
||||
$query->select('id_product_attribute');
|
||||
$query->select('date_add');
|
||||
$query->select('id_statistics');
|
||||
$query->from('blockwishlist_statistics');
|
||||
$query->where('id_shop = "' . (int) $this->context->shop->id . '"');
|
||||
|
||||
switch ($statsRange) {
|
||||
case 'currentYear':
|
||||
$dateStart = (new DateTime('now'))->modify('-1 year')->format('Y-m-d H:i:s');
|
||||
break;
|
||||
case 'currentMonth':
|
||||
$dateStart = (new DateTime('now'))->modify('-1 month')->format('Y-m-d H:i:s');
|
||||
break;
|
||||
case 'currentDay':
|
||||
$dateStart = (new DateTime('now'))->modify('-1 day')->format('Y-m-d H:i:s');
|
||||
break;
|
||||
case 'allTime':
|
||||
$dateStart = null;
|
||||
break;
|
||||
default:
|
||||
$dateStart = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (null !== $dateStart) {
|
||||
$query->where('date_add >= "' . $dateStart . '"');
|
||||
}
|
||||
|
||||
$results = Db::getInstance()->executeS($query);
|
||||
$stats = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$productAttributeKey = $result['id_product'] . '.' . $result['id_product_attribute'];
|
||||
|
||||
if (isset($stats[$productAttributeKey])) {
|
||||
$stats[$productAttributeKey] = $stats[$productAttributeKey] + 1;
|
||||
} else {
|
||||
$stats[$productAttributeKey] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
arsort($stats);
|
||||
$stats = array_slice($stats, 0, 10);
|
||||
$this->computeConversionRate($stats, $dateStart);
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* computeconversionRate
|
||||
*
|
||||
* @param array $stats
|
||||
* @param string|null $dateStart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function computeConversionRate(&$stats, $dateStart = null)
|
||||
{
|
||||
$position = 0;
|
||||
|
||||
foreach ($stats as $idProductAndAttribute => $count) {
|
||||
// first ID is product, second one is product_attribute
|
||||
$combination = '';
|
||||
$ids = explode('.', $idProductAndAttribute);
|
||||
$id_product = $ids[0];
|
||||
$id_product_attribute = $ids[1];
|
||||
$productDetails = $this->productAssembler->assembleProduct([
|
||||
'id_product' => $id_product,
|
||||
'id_product_attribute' => $id_product_attribute,
|
||||
]);
|
||||
|
||||
if (!empty($productDetails['attributes'])) {
|
||||
$combinationArr = [];
|
||||
foreach ($productDetails['attributes'] as $attribute) {
|
||||
$combinationArr[] = $attribute['group'] . ' : ' . $attribute['name'];
|
||||
}
|
||||
$combination = implode(',', $combinationArr);
|
||||
}
|
||||
|
||||
$imgDetails = $this->getProductImage($productDetails);
|
||||
$stats[$idProductAndAttribute] = [
|
||||
'position' => $position,
|
||||
'count' => $count,
|
||||
'id_product' => $id_product,
|
||||
'id_product_attribute' => $id_product_attribute,
|
||||
'name' => $productDetails['name'],
|
||||
'combination' => $combination,
|
||||
'category_name' => $productDetails['category_name'],
|
||||
'image_small_url' => $imgDetails['small']['url'],
|
||||
'link' => $productDetails['link'],
|
||||
'reference' => $productDetails['reference'],
|
||||
'price' => $this->locale->formatPrice($productDetails['price'], $this->context->currency->iso_code),
|
||||
'quantity' => $productDetails['quantity'],
|
||||
'conversionRate' => $this->computeConversionByProduct($id_product, $id_product_attribute, $dateStart) . '%',
|
||||
];
|
||||
|
||||
++$position;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getProductImage
|
||||
*
|
||||
* @param array $productDetails
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProductImage($productDetails)
|
||||
{
|
||||
$imgDetails = [];
|
||||
|
||||
$presenterFactory = new ProductPresenterFactory($this->context);
|
||||
$presentationSettings = $presenterFactory->getPresentationSettings();
|
||||
$imageRetriever = new ImageRetriever($this->context->link);
|
||||
$presenter = new ProductPresenter(
|
||||
$imageRetriever,
|
||||
$this->context->link,
|
||||
new PriceFormatter(),
|
||||
new ProductColorsRetriever(),
|
||||
$this->context->getTranslator()
|
||||
);
|
||||
|
||||
$presentedProduct = $presenter->present(
|
||||
$presentationSettings,
|
||||
$productDetails,
|
||||
$this->context->language
|
||||
);
|
||||
|
||||
foreach ($presentedProduct as $key => $value) {
|
||||
if ($key == 'embedded_attributes') {
|
||||
$imgDetails = $value['cover'];
|
||||
}
|
||||
}
|
||||
if (!$imgDetails) {
|
||||
$imgDetails = $imageRetriever->getNoPictureImage($this->context->language);
|
||||
}
|
||||
|
||||
return $imgDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* computeConversionByProduct
|
||||
*
|
||||
* @param string $id_product
|
||||
* @param string $id_product_attribute
|
||||
* @param string $dateStart (Y-m-d H:i:s)
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function computeConversionByProduct($id_product, $id_product_attribute, $dateStart = null)
|
||||
{
|
||||
$nbOrderPaidAndShipped = [];
|
||||
$queryOrders = '
|
||||
SELECT count(distinct(o.id_order)) as nb
|
||||
FROM ' . _DB_PREFIX_ . 'orders o
|
||||
INNER JOIN ' . _DB_PREFIX_ . 'blockwishlist_statistics bws ON (o.id_cart = bws.id_cart )
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'order_history oh ON (o.`id_order` = oh.`id_order`)
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'order_state os ON (os.`id_order_state` = oh.`id_order_state` AND os.`paid` = 1 AND os.`shipped` = 1)
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON (od.`id_order` = o.`id_order` AND od.`product_id` = bws.`id_product` AND od.`product_attribute_id` = bws.`id_product_attribute`)
|
||||
WHERE bws.`id_cart` <> 0 AND bws.`id_product` = ' . (int) $id_product . ' AND bws.`id_product_attribute` = ' . (int) $id_product_attribute . '
|
||||
AND bws.`id_shop` = ' . (int) $this->context->shop->id . '
|
||||
';
|
||||
|
||||
if (null != $dateStart) {
|
||||
$queryOrders .= 'AND bws.date_add >= "' . $dateStart . '"';
|
||||
}
|
||||
|
||||
$nbOrderPaidAndShipped = Db::getInstance()->getRow($queryOrders);
|
||||
|
||||
if (empty($nbOrderPaidAndShipped['nb'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$queryCountAll = new DbQuery();
|
||||
$queryCountAll->select('COUNT(id_statistics)');
|
||||
$queryCountAll->from('blockwishlist_statistics');
|
||||
$queryCountAll->where('id_product = ' . $id_product);
|
||||
$queryCountAll->where('id_product_attribute = ' . $id_product_attribute);
|
||||
$queryCountAll->where('id_shop = ' . (int) $this->context->shop->id);
|
||||
|
||||
if (null != $dateStart) {
|
||||
$queryCountAll->where('date_add >= "' . $dateStart . '"');
|
||||
}
|
||||
|
||||
$countAddedToWishlist = Db::getInstance()->getValue($queryCountAll);
|
||||
|
||||
if (0 != $countAddedToWishlist) {
|
||||
return round(($nbOrderPaidAndShipped['nb'] / $countAddedToWishlist) * 100, 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Controller;
|
||||
|
||||
use Configuration;
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use Language;
|
||||
use PrestaShop\Module\BlockWishList\Grid\Data\BaseGridDataFactory;
|
||||
use PrestaShop\Module\BlockWishList\Type\ConfigurationType;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteria;
|
||||
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class WishlistConfigurationAdminController extends FrameworkBundleAdminController
|
||||
{
|
||||
/**
|
||||
* @var CacheProvider
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $shopId;
|
||||
|
||||
public function __construct(CacheProvider $cache, $shopId)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->shopId = $shopId;
|
||||
}
|
||||
|
||||
public function configurationAction(Request $request)
|
||||
{
|
||||
$datas = $this->getWishlistConfigurationDatas();
|
||||
$configurationForm = $this->createForm(ConfigurationType::class, $datas);
|
||||
$configurationForm->handleRequest($request);
|
||||
$resultHandleForm = null;
|
||||
|
||||
if ($configurationForm->isSubmitted() && $configurationForm->isValid()) {
|
||||
$resultHandleForm = $this->handleForm($configurationForm->getData());
|
||||
if ($resultHandleForm) {
|
||||
return $this->redirectToRoute('blockwishlist_configuration');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@Modules/blockwishlist/views/templates/admin/home.html.twig', [
|
||||
'configurationForm' => $configurationForm->createView(),
|
||||
'resultHandleForm' => $resultHandleForm,
|
||||
'enableSidebar' => true,
|
||||
'help_link' => $this->generateSidebarLink('WishlistConfigurationAdminController'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function statisticsAction()
|
||||
{
|
||||
$searchCriteria = new SearchCriteria();
|
||||
$allTimeStatsGridFactory = $this->get('prestashop.module.blockwishlist.grid.all_time_stastistics_grid_factory');
|
||||
$currentYearGridFactory = $this->get('prestashop.module.blockwishlist.grid.current_year_stastistics_grid_factory');
|
||||
$currentMonthGridFactory = $this->get('prestashop.module.blockwishlist.grid.current_month_stastistics_grid_factory');
|
||||
$currentDayGridFactory = $this->get('prestashop.module.blockwishlist.grid.current_day_stastistics_grid_factory');
|
||||
$allTimeStatisticsGrid = $allTimeStatsGridFactory->getGrid($searchCriteria);
|
||||
$currentYearGrid = $currentYearGridFactory->getGrid($searchCriteria);
|
||||
$currentMonthGrid = $currentMonthGridFactory->getGrid($searchCriteria);
|
||||
$currentDayGrid = $currentDayGridFactory->getGrid($searchCriteria);
|
||||
|
||||
return $this->render('@Modules/blockwishlist/views/templates/admin/statistics.html.twig', [
|
||||
'allTimeStatisticsGrid' => $this->presentGrid($allTimeStatisticsGrid),
|
||||
'currentYearStatisticsGrid' => $this->presentGrid($currentYearGrid),
|
||||
'currentMonthStatisticsGrid' => $this->presentGrid($currentMonthGrid),
|
||||
'currentDayStatisticsGrid' => $this->presentGrid($currentDayGrid),
|
||||
'shopId' => $this->shopId,
|
||||
'enableSidebar' => true,
|
||||
'help_link' => $this->generateSidebarLink('WishlistConfigurationAdminController'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetStatisticsCacheAction()
|
||||
{
|
||||
$result = $this->cache->delete(BaseGridDataFactory::CACHE_KEY_STATS_ALL_TIME . $this->shopId)
|
||||
&& $this->cache->delete(BaseGridDataFactory::CACHE_KEY_STATS_CURRENT_DAY . $this->shopId)
|
||||
&& $this->cache->delete(BaseGridDataFactory::CACHE_KEY_STATS_CURRENT_MONTH . $this->shopId)
|
||||
&& $this->cache->delete(BaseGridDataFactory::CACHE_KEY_STATS_CURRENT_YEAR . $this->shopId);
|
||||
|
||||
return new JsonResponse(['success' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* handleForm
|
||||
*
|
||||
* @param array $datas
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function handleForm($datas)
|
||||
{
|
||||
$result = true;
|
||||
$defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
if (isset($datas['WishlistPageName'])) {
|
||||
foreach ($datas['WishlistPageName'] as $langID => $value) {
|
||||
if (empty($value) && $langID != $defaultLanguageId) {
|
||||
$value = $datas['WishlistPageName'][$defaultLanguageId];
|
||||
}
|
||||
$result = $result && Configuration::updateValue('blockwishlist_WishlistPageName', [$langID => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($datas['WishlistDefaultTitle'])) {
|
||||
foreach ($datas['WishlistDefaultTitle'] as $langID => $value) {
|
||||
if (empty($value) && $langID != $defaultLanguageId) {
|
||||
$value = $datas['WishlistDefaultTitle'][$defaultLanguageId];
|
||||
}
|
||||
$result = $result && Configuration::updateValue('blockwishlist_WishlistDefaultTitle', [$langID => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($datas['CreateButtonLabel'])) {
|
||||
foreach ($datas['CreateButtonLabel'] as $langID => $value) {
|
||||
if (empty($value) && $langID != $defaultLanguageId) {
|
||||
$value = $datas['CreateButtonLabel'][$defaultLanguageId];
|
||||
}
|
||||
$result = $result && Configuration::updateValue('blockwishlist_CreateButtonLabel', [$langID => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result === true) {
|
||||
$this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success'));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* getWishlistConfigurationDatas
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getWishlistConfigurationDatas()
|
||||
{
|
||||
$languages = Language::getLanguages(true);
|
||||
$wishlistNames = $wishlistDefaultTitles = $wishlistCreateNewButtonsLabel = [];
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
$wishlistNames[$lang['id_lang']] = Configuration::get('blockwishlist_WishlistPageName', $lang['id_lang']);
|
||||
$wishlistDefaultTitles[$lang['id_lang']] = Configuration::get('blockwishlist_WishlistDefaultTitle', $lang['id_lang']);
|
||||
$wishlistCreateNewButtonsLabel[$lang['id_lang']] = Configuration::get('blockwishlist_CreateButtonLabel', $lang['id_lang']);
|
||||
}
|
||||
|
||||
$datas = [
|
||||
'WishlistPageName' => $wishlistNames,
|
||||
'WishlistDefaultTitle' => $wishlistDefaultTitles,
|
||||
'CreateButtonLabel' => $wishlistCreateNewButtonsLabel,
|
||||
];
|
||||
|
||||
return $datas;
|
||||
}
|
||||
}
|
||||
140
modules/blockwishlist/src/Database/Install.php
Normal file
140
modules/blockwishlist/src/Database/Install.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Database;
|
||||
|
||||
use BlockWishList;
|
||||
use Configuration;
|
||||
use Db;
|
||||
use Language;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Tab;
|
||||
|
||||
class Install
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->installTables()
|
||||
&& $this->installConfiguration()
|
||||
&& $this->installTabs();
|
||||
}
|
||||
|
||||
public function installTables()
|
||||
{
|
||||
$sql = [];
|
||||
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'wishlist` (
|
||||
`id_wishlist` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_customer` int(10) unsigned NOT NULL,
|
||||
`id_shop` int(10) unsigned default 1,
|
||||
`id_shop_group` int(10) unsigned default 1,
|
||||
`token` varchar(64) NOT NULL,
|
||||
`name` varchar(64) NOT NULL,
|
||||
`counter` int(10) unsigned NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
`default` int(10) unsigned default 0,
|
||||
PRIMARY KEY (`id_wishlist`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
|
||||
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'wishlist_product` (
|
||||
`id_wishlist_product` int(10) NOT NULL auto_increment,
|
||||
`id_wishlist` int(10) unsigned NOT NULL,
|
||||
`id_product` int(10) unsigned NOT NULL,
|
||||
`id_product_attribute` int(10) unsigned NOT NULL,
|
||||
`quantity` int(10) unsigned NOT NULL,
|
||||
`priority` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_wishlist_product`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
|
||||
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'wishlist_product_cart` (
|
||||
`id_wishlist_product` int(10) unsigned NOT NULL,
|
||||
`id_cart` int(10) unsigned NOT NULL,
|
||||
`quantity` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
|
||||
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'blockwishlist_statistics` (
|
||||
`id_statistics` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_cart` int(10) unsigned default NULL,
|
||||
`id_product` int(10) unsigned NOT NULL,
|
||||
`id_product_attribute` int(10) unsigned NOT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`id_shop` int(10) unsigned default 1,
|
||||
PRIMARY KEY (`id_statistics`)
|
||||
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach ($sql as $query) {
|
||||
$result = $result && Db::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function installConfiguration()
|
||||
{
|
||||
$pageName = $defaultName = $createButtonLabel = [];
|
||||
|
||||
foreach (Language::getLanguages() as $lang) {
|
||||
$pageName[$lang['id_lang']] = $this->translator->trans('My wishlists', [], 'Modules.Blockwishlist.Admin', $lang['locale']);
|
||||
$defaultName[$lang['id_lang']] = $this->translator->trans('My wishlist', [], 'Modules.Blockwishlist.Admin', $lang['locale']);
|
||||
$createButtonLabel[$lang['id_lang']] = $this->translator->trans('Create new list', [], 'Modules.Blockwishlist.Admin', $lang['locale']);
|
||||
}
|
||||
|
||||
return Configuration::updateValue('blockwishlist_WishlistPageName', $pageName)
|
||||
&& Configuration::updateValue('blockwishlist_WishlistDefaultTitle', $defaultName)
|
||||
&& Configuration::updateValue('blockwishlist_CreateButtonLabel', $createButtonLabel);
|
||||
}
|
||||
|
||||
public function installTabs()
|
||||
{
|
||||
$installTabCompleted = true;
|
||||
|
||||
foreach (BlockWishList::MODULE_ADMIN_CONTROLLERS as $controller) {
|
||||
if (Tab::getIdFromClassName($controller['class_name'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tab = new Tab();
|
||||
$tab->class_name = $controller['class_name'];
|
||||
$tab->active = $controller['visible'];
|
||||
foreach (Language::getLanguages() as $lang) {
|
||||
$tab->name[$lang['id_lang']] = $this->translator->trans($controller['name'], [], 'Modules.BlockWishList.Admin', $lang['locale']);
|
||||
}
|
||||
$tab->id_parent = Tab::getIdFromClassName($controller['parent_class_name']);
|
||||
$tab->module = 'blockwishlist';
|
||||
$installTabCompleted = $installTabCompleted && $tab->add();
|
||||
}
|
||||
|
||||
return $installTabCompleted;
|
||||
}
|
||||
}
|
||||
64
modules/blockwishlist/src/Database/Uninstall.php
Normal file
64
modules/blockwishlist/src/Database/Uninstall.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Database;
|
||||
|
||||
use BlockWishList;
|
||||
use Db;
|
||||
use Tab;
|
||||
use Validate;
|
||||
|
||||
class Uninstall
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return $this->dropTables() && $this->uninstallTabs();
|
||||
}
|
||||
|
||||
private function dropTables()
|
||||
{
|
||||
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'wishlist`';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'wishlist_product`';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'wishlist_product_cart`';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'blockwishlist_statistics`';
|
||||
|
||||
$result = true;
|
||||
foreach ($sql as $query) {
|
||||
$result = $result && Db::getInstance()->execute($query);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function uninstallTabs()
|
||||
{
|
||||
$uninstallTabCompleted = true;
|
||||
|
||||
foreach (BlockWishList::MODULE_ADMIN_CONTROLLERS as $controller) {
|
||||
$id_tab = (int) Tab::getIdFromClassName($controller['class_name']);
|
||||
$tab = new Tab($id_tab);
|
||||
if (Validate::isLoadedObject($tab)) {
|
||||
$uninstallTabCompleted = $uninstallTabCompleted && $tab->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return $uninstallTabCompleted;
|
||||
}
|
||||
}
|
||||
28
modules/blockwishlist/src/Database/index.php
Normal file
28
modules/blockwishlist/src/Database/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Data;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
class AllTimeStatisticsGridDataFactory extends BaseGridDataFactory implements GridDataFactoryInterface
|
||||
{
|
||||
// 1 month
|
||||
const CACHE_LIFETIME_SECONDS = 2629746;
|
||||
|
||||
public function getData(SearchCriteriaInterface $searchCriteria)
|
||||
{
|
||||
if ($this->cache->contains(self::CACHE_KEY_STATS_ALL_TIME . $this->shopId)) {
|
||||
$results = $this->cache->fetch(self::CACHE_KEY_STATS_ALL_TIME . $this->shopId);
|
||||
} else {
|
||||
$results = $this->calculator->computeStatsFor('allTime');
|
||||
$this->cache->save(self::CACHE_KEY_STATS_ALL_TIME . $this->shopId, $results, self::CACHE_LIFETIME_SECONDS);
|
||||
}
|
||||
|
||||
return new GridData(new RecordCollection($results), count($results));
|
||||
}
|
||||
}
|
||||
32
modules/blockwishlist/src/Grid/Data/BaseGridDataFactory.php
Normal file
32
modules/blockwishlist/src/Grid/Data/BaseGridDataFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Data;
|
||||
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use PrestaShop\Module\BlockWishList\Calculator\StatisticsCalculator;
|
||||
|
||||
class BaseGridDataFactory
|
||||
{
|
||||
const CACHE_KEY_STATS_CURRENT_DAY = 'blockwishlist.stats.currentDay';
|
||||
const CACHE_KEY_STATS_CURRENT_MONTH = 'blockwishlist.stats.currentMonth';
|
||||
const CACHE_KEY_STATS_CURRENT_YEAR = 'blockwishlist.stats.currentYear';
|
||||
const CACHE_KEY_STATS_ALL_TIME = 'blockwishlist.stats.allTime';
|
||||
|
||||
/* @var CacheProvider $cache */
|
||||
protected $cache;
|
||||
|
||||
/* @var StatisticsCalculator $calculator */
|
||||
protected $calculator;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
protected $shopId;
|
||||
|
||||
public function __construct(CacheProvider $cache, StatisticsCalculator $calculator, $shopId)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->calculator = $calculator;
|
||||
$this->shopId = $shopId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Data;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
class CurrentDayStatisticsGridDataFactory extends BaseGridDataFactory implements GridDataFactoryInterface
|
||||
{
|
||||
// 1 day
|
||||
const CACHE_LIFETIME_SECONDS = 86400;
|
||||
|
||||
public function getData(SearchCriteriaInterface $searchCriteria)
|
||||
{
|
||||
if ($this->cache->contains(self::CACHE_KEY_STATS_CURRENT_DAY . $this->shopId)) {
|
||||
$results = $this->cache->fetch(self::CACHE_KEY_STATS_CURRENT_DAY . $this->shopId);
|
||||
} else {
|
||||
$results = $this->calculator->computeStatsFor('currentDay');
|
||||
$this->cache->save(self::CACHE_KEY_STATS_CURRENT_DAY . $this->shopId, $results, self::CACHE_LIFETIME_SECONDS);
|
||||
}
|
||||
|
||||
return new GridData(new RecordCollection($results), count($results));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Data;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
class CurrentMonthStatisticsGridDataFactory extends BaseGridDataFactory implements GridDataFactoryInterface
|
||||
{
|
||||
// 1 week
|
||||
const CACHE_LIFETIME_SECONDS = 604800;
|
||||
|
||||
public function getData(SearchCriteriaInterface $searchCriteria)
|
||||
{
|
||||
if ($this->cache->contains(self::CACHE_KEY_STATS_CURRENT_MONTH . $this->shopId)) {
|
||||
$results = $this->cache->fetch(self::CACHE_KEY_STATS_CURRENT_MONTH . $this->shopId);
|
||||
} else {
|
||||
$results = $this->calculator->computeStatsFor('currentMonth');
|
||||
$this->cache->save(self::CACHE_KEY_STATS_CURRENT_MONTH . $this->shopId, $results, self::CACHE_LIFETIME_SECONDS);
|
||||
}
|
||||
|
||||
return new GridData(new RecordCollection($results), count($results));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Data;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
class CurrentYearStatisticsGridDataFactory extends BaseGridDataFactory implements GridDataFactoryInterface
|
||||
{
|
||||
// 1 month
|
||||
const CACHE_LIFETIME_SECONDS = 2629746;
|
||||
|
||||
public function getData(SearchCriteriaInterface $searchCriteria)
|
||||
{
|
||||
if ($this->cache->contains(self::CACHE_KEY_STATS_CURRENT_YEAR . $this->shopId)) {
|
||||
$results = $this->cache->fetch(self::CACHE_KEY_STATS_CURRENT_YEAR . $this->shopId);
|
||||
} else {
|
||||
$results = $this->calculator->computeStatsFor('currentYear');
|
||||
$this->cache->save(self::CACHE_KEY_STATS_CURRENT_YEAR . $this->shopId, $results, self::CACHE_LIFETIME_SECONDS);
|
||||
}
|
||||
|
||||
return new GridData(new RecordCollection($results), count($results));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Definition;
|
||||
|
||||
class AllTimeStatisticsGridDefinitionFactory extends BaseStatisticsGridDefinitionFactory
|
||||
{
|
||||
protected function getId()
|
||||
{
|
||||
return 'statistics_all_time';
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('All Time Statistics', [], 'Modules.Blockwishlist.Admin');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Definition;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ImageColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\LinkColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
|
||||
|
||||
class BaseStatisticsGridDefinitionFactory extends AbstractGridDefinitionFactory
|
||||
{
|
||||
protected function getId()
|
||||
{
|
||||
return 'statistics';
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('Statistics', [], 'Admin.Advparameters.Feature');
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return (new ColumnCollection())
|
||||
->add((new PositionColumn('position'))
|
||||
->setName($this->trans('Product', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'id_field' => 'position',
|
||||
'position_field' => 'position',
|
||||
'update_route' => '',
|
||||
])
|
||||
)
|
||||
->add((new ImageColumn('image'))
|
||||
->setOptions([
|
||||
'src_field' => 'image_small_url',
|
||||
])
|
||||
)
|
||||
->add((new LinkColumn('name'))
|
||||
->setOptions([
|
||||
'field' => 'name',
|
||||
'route' => 'admin_product_form',
|
||||
'route_param_name' => 'id',
|
||||
'route_param_field' => 'id_product',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('reference'))
|
||||
->setName($this->trans('Reference', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'reference',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('combination'))
|
||||
->setName($this->trans('Combination', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'combination',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('category_name'))
|
||||
->setName($this->trans('Category', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'category_name',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('price'))
|
||||
->setName($this->trans('Price (tax excl.)', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'price',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('quantity'))
|
||||
->setName($this->trans('Available Qty', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'quantity',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('conversionRate'))
|
||||
->setName($this->trans('Conversion rate', [], 'Modules.Blockwishlist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'conversionRate',
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Definition;
|
||||
|
||||
class CurrentDayStatisticsGridDefinitionFactory extends BaseStatisticsGridDefinitionFactory
|
||||
{
|
||||
protected function getId()
|
||||
{
|
||||
return 'statistics_current_day';
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('Current Day Statistics', [], 'Modules.Blockwishlist.Admin');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Definition;
|
||||
|
||||
class CurrentMonthStatisticsGridDefinitionFactory extends BaseStatisticsGridDefinitionFactory
|
||||
{
|
||||
protected function getId()
|
||||
{
|
||||
return 'statistics_current_month';
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('Current Month Statistics', [], 'Modules.Blockwishlist.Admin');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Grid\Definition;
|
||||
|
||||
class CurrentYearStatisticsGridDefinitionFactory extends BaseStatisticsGridDefinitionFactory
|
||||
{
|
||||
protected function getId()
|
||||
{
|
||||
return 'statistics_current_year';
|
||||
}
|
||||
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('Current Year Statistics', [], 'Modules.Blockwishlist.Admin');
|
||||
}
|
||||
}
|
||||
27
modules/blockwishlist/src/Repository/WishlistRepository.php
Normal file
27
modules/blockwishlist/src/Repository/WishlistRepository.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
class WishlistRepository
|
||||
{
|
||||
public function getAllWishlistsProductID()
|
||||
{
|
||||
return (int) Db::getInstance()
|
||||
->getRow('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'wishlist_product`');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Search;
|
||||
|
||||
use Combination;
|
||||
use Configuration;
|
||||
use Db;
|
||||
use DbQuery;
|
||||
use FrontController;
|
||||
use Group;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchProviderInterface;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
|
||||
use Product;
|
||||
use Shop;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Validate;
|
||||
use WishList;
|
||||
|
||||
/**
|
||||
* Responsible of getting products for specific wishlist.
|
||||
*/
|
||||
class WishListProductSearchProvider implements ProductSearchProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @var WishList
|
||||
*/
|
||||
private $wishList;
|
||||
|
||||
/**
|
||||
* @var SortOrderFactory
|
||||
*/
|
||||
private $sortOrderFactory;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface the translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
* @param WishList $wishList
|
||||
*/
|
||||
public function __construct(
|
||||
Db $db,
|
||||
WishList $wishList,
|
||||
SortOrderFactory $sortOrderFactory,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->db = $db;
|
||||
$this->wishList = $wishList;
|
||||
$this->sortOrderFactory = $sortOrderFactory;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProductSearchContext $context
|
||||
* @param ProductSearchQuery $query
|
||||
*
|
||||
* @return ProductSearchResult
|
||||
*/
|
||||
public function runQuery(
|
||||
ProductSearchContext $context,
|
||||
ProductSearchQuery $query
|
||||
) {
|
||||
$result = new ProductSearchResult();
|
||||
$result->setProducts($this->getProductsOrCount($context, $query, 'products'));
|
||||
$result->setTotalProductsCount($this->getProductsOrCount($context, $query, 'count'));
|
||||
$sortOrders = $this->sortOrderFactory->getDefaultSortOrders();
|
||||
$sortOrders[] = (new SortOrder('wishlist_product', 'id_wishlist_product', 'DESC'))->setLabel($this->translator->trans('Last added', [], 'Modules.Blockwishlist.Shop'));
|
||||
$result->setAvailableSortOrders($sortOrders);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProductSearchContext $context
|
||||
* @param ProductSearchQuery $query
|
||||
* @param string $type
|
||||
*
|
||||
* @return array|int
|
||||
*/
|
||||
private function getProductsOrCount(
|
||||
ProductSearchContext $context,
|
||||
ProductSearchQuery $query,
|
||||
$type = 'products'
|
||||
) {
|
||||
$querySearch = new DbQuery();
|
||||
|
||||
if ('products' === $type) {
|
||||
$querySearch->select('p.*');
|
||||
$querySearch->select('wp.quantity AS wishlist_quantity');
|
||||
$querySearch->select('product_shop.*');
|
||||
$querySearch->select('stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity');
|
||||
$querySearch->select('pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
|
||||
pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`');
|
||||
$querySearch->select('image_shop.`id_image` AS id_image');
|
||||
$querySearch->select('il.`legend`');
|
||||
$querySearch->select('
|
||||
DATEDIFF(
|
||||
product_shop.`date_add`,
|
||||
DATE_SUB(
|
||||
"' . date('Y-m-d') . ' 00:00:00",
|
||||
INTERVAL ' . (0 <= (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY
|
||||
)
|
||||
) > 0 AS new'
|
||||
);
|
||||
|
||||
if (Combination::isFeatureActive()) {
|
||||
$querySearch->select('product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, IFNULL(product_attribute_shop.`id_product_attribute`,0) AS id_product_attribute');
|
||||
}
|
||||
} else {
|
||||
$querySearch->select('COUNT(wp.id_product)');
|
||||
}
|
||||
|
||||
$querySearch->from('product', 'p');
|
||||
$querySearch->join(Shop::addSqlAssociation('product', 'p'));
|
||||
$querySearch->innerJoin('wishlist_product', 'wp', 'wp.`id_product` = p.`id_product`');
|
||||
$querySearch->leftJoin('category_product', 'cp', 'p.id_product = cp.id_product AND cp.id_category = product_shop.id_category_default');
|
||||
|
||||
if (Combination::isFeatureActive()) {
|
||||
$querySearch->leftJoin('product_attribute_shop', 'product_attribute_shop', 'p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`id_product_attribute` = wp.id_product_attribute AND product_attribute_shop.id_shop=' . (int) $context->getIdShop());
|
||||
}
|
||||
|
||||
if ('products' === $type) {
|
||||
$querySearch->leftJoin('stock_available', 'stock', 'stock.id_product = `p`.id_product AND stock.id_product_attribute = wp.id_product_attribute' . \StockAvailable::addSqlShopRestriction(null, (int) $context->getIdShop(), 'stock'));
|
||||
$querySearch->leftJoin('product_lang', 'pl', 'p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $context->getIdLang() . \Shop::addSqlRestrictionOnLang('pl'));
|
||||
$querySearch->leftJoin('image_shop', 'image_shop', 'image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop = ' . (int) $context->getIdShop());
|
||||
$querySearch->leftJoin('image_lang', 'il', 'image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $context->getIdLang());
|
||||
$querySearch->leftJoin('category', 'ca', 'cp.`id_category` = ca.`id_category` AND ca.`active` = 1');
|
||||
}
|
||||
|
||||
if (Group::isFeatureActive()) {
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sqlGroups = false === empty($groups) ? 'IN (' . implode(',', $groups) . ')' : '=' . (int) Group::getCurrent()->id;
|
||||
$querySearch->leftJoin('category_group', 'cg', 'cp.`id_category` = cg.`id_category` AND cg.`id_group`' . $sqlGroups);
|
||||
}
|
||||
|
||||
$querySearch->where('wp.id_wishlist = ' . (int) $this->wishList->id);
|
||||
$querySearch->where('product_shop.active = 1');
|
||||
$querySearch->where('product_shop.visibility IN ("both", "catalog")');
|
||||
|
||||
if ('products' === $type) {
|
||||
$sortOrder = $query->getSortOrder()->toLegacyOrderBy(true);
|
||||
$sortWay = $query->getSortOrder()->toLegacyOrderWay();
|
||||
if (Validate::isOrderBy($sortOrder) && Validate::isOrderWay($sortWay)) {
|
||||
$querySearch->orderBy($sortOrder . ' ' . $sortWay);
|
||||
}
|
||||
$querySearch->limit((int) $query->getResultsPerPage(), ((int) $query->getPage() - 1) * (int) $query->getResultsPerPage());
|
||||
$products = $this->db->executeS($querySearch);
|
||||
|
||||
if (empty($products)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Product::getProductsProperties((int) $context->getIdLang(), $products);
|
||||
}
|
||||
|
||||
return (int) $this->db->getValue($querySearch);
|
||||
}
|
||||
}
|
||||
56
modules/blockwishlist/src/Type/ConfigurationType.php
Normal file
56
modules/blockwishlist/src/Type/ConfigurationType.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\BlockWishList\Type;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
|
||||
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class ConfigurationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('WishlistDefaultTitle', TranslatableType::class, [
|
||||
// we'll have text area that is translatable
|
||||
'type' => TextType::class,
|
||||
'constraints' => [
|
||||
new DefaultLanguage(),
|
||||
],
|
||||
])
|
||||
->add('CreateButtonLabel', TranslatableType::class, [
|
||||
// we'll have text area that is translatable
|
||||
'type' => TextType::class,
|
||||
'constraints' => [
|
||||
new DefaultLanguage(),
|
||||
],
|
||||
])
|
||||
->add('WishlistPageName', TranslatableType::class, [
|
||||
// we'll have text area that is translatable
|
||||
'type' => TextType::class,
|
||||
'constraints' => [
|
||||
new DefaultLanguage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
modules/blockwishlist/src/index.php
Normal file
28
modules/blockwishlist/src/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user