Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration #44

Merged
merged 7 commits into from Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -10,3 +10,7 @@ build-back:

build-back-prod:
docker-compose run --rm php sh -c "composer install --no-dev -o"

build-front:
docker-compose run --rm node sh -c "npm install"
docker-compose run --rm node sh -c "npm run build"
15 changes: 11 additions & 4 deletions blockwishlist.php
Expand Up @@ -19,6 +19,7 @@
*/

use PrestaShop\Module\BlockWishList\Database\Install;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -70,9 +71,7 @@ public function __construct()
*/
public function install()
{
$isDatabaseInstalled = new Install($this);

if (false === $isDatabaseInstalled->installTables()) {
if (false === (new Install())->installTables()) {
return false;
}

Expand All @@ -85,7 +84,15 @@ public function install()
*/
public function uninstall()
{
return parent::uninstall();
return (new Install())->dropTables()
&& parent::uninstall();
}

public function getContent()
{
Tools::redirectAdmin(
SymfonyContainer::getInstance()->get('router')->generate('blockwishlist_home')
);
}

/**
Expand Down
50 changes: 50 additions & 0 deletions classes/Statistics.php
@@ -0,0 +1,50 @@
<?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 Statistics extends ObjectModel
{
/** @var int ID */
public $id_statistics;

/** @var int id_product */
public $id_product;

/** @var int id_product_attribute */
public $id_product_attribute;

/** @var string date_add */
public $date_add;

/** @var int|null date_add */
public $id_cart;

/**
* @see ObjectModel::$definition
*/
public static $definition = [
'table' => 'blockwishlist_statistics',
'primary' => 'id_statistics',
'fields' => [
'id_cart' => ['type' => self::TYPE_INT, 'required' => false],
'id_product' => ['type' => self::TYPE_INT, 'required' => true],
'id_product_attribute' => ['type' => self::TYPE_INT, 'required' => true],
'date_add' => ['type' => self::TYPE_DATE, 'required' => true],
],
];
}
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -37,5 +37,6 @@
"set-license-header": [
"@php ./vendor/bin/header-stamp --license=\"assets/afl.txt\" --exclude=\".github,.webpack,node_modules,vendor\""
]
}
}
},
"author": "PrestaShop"
}
Empty file removed config/front/services.yml
Empty file.
11 changes: 11 additions & 0 deletions config/routes.yml
@@ -0,0 +1,11 @@
blockwishlist_home:
path: blockwishlist/home
methods: [GET, POST]
defaults:
_controller: PrestaShop\Module\BlockWishList\Controller\AdminAjaxPrestashopWishlistController::homeAction

blockwishlist_statistics:
path: blockwishlist/getStatisticsAction
methods: [GET]
defaults:
_controller: PrestaShop\Module\BlockWishList\Controller\AdminAjaxPrestashopWishlistController::getStatisticsAction
14 changes: 14 additions & 0 deletions config/services.yml
@@ -0,0 +1,14 @@
services:
_defaults:
public: true

PrestaShop\Module\BlockWishList\Controller\AdminAjaxPrestashopWishlistController:
class: PrestaShop\Module\BlockWishList\Controller\AdminAjaxPrestashopWishlistController
arguments:
- '@doctrine.cache.provider'
- '@prestashop.adapter.legacy.context'

prestashop.module.blockwishlist.grid.statistics_grid_definition_factory:
class: 'PrestaShop\Module\BlockWishList\Grid\StatisticsGridDefinitionFactory'
parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
public: true
18 changes: 18 additions & 0 deletions controllers/front/action.php
Expand Up @@ -88,6 +88,11 @@ private function addProductToWishListAction($params)
$quantity
);

$newStat = new Statistics();
$newStat->id_product = $id_product;
$newStat->id_product_attribute = $id_product_attribute;
$newStat->save();

if (false === $productIsAdded) {
return $this->ajaxRender(
json_encode([
Expand All @@ -97,6 +102,8 @@ private function addProductToWishListAction($params)
);
}

// TODO: add product to stats

return $this->ajaxRender(
json_encode([
'success' => true,
Expand Down Expand Up @@ -331,6 +338,7 @@ private function getProductsByWishListAction($params)
new ProductColorsRetriever(),
$this->context->getTranslator()
);

$products_for_template = [];

if (is_array($wishlistProducts)) {
Expand Down Expand Up @@ -366,6 +374,16 @@ private function addProductToCartAction($params)
(int) $this->context->cart->id,
$params['quantity']
);

// Transform an add to favorite
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'blockwishlist_statistics`
SET `id_cart` = ' . (int) $this->context->cart->id . '
WHERE `id_cart` = 0
AND `id_product` = ' . (int) $params['id_product'] . '
AND `id_product_attribute` = ' . (int) $params['id_product_attribute']
);

if (true === $productAdd) {
return $this->ajaxRender(
json_encode([
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -10,7 +10,7 @@ services:
environment:
_PS_ROOT_DIR_: /var/www/html
node:
image: node:13.1
image: node:10
volumes:
- ./:/var/www/html/modules/blockwishlist
working_dir: /var/www/html/modules/blockwishlist
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -80,4 +80,4 @@
"env"
]
}
}
}