Skip to content

Commit

Permalink
Merge pull request #203 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 6.0.3
  • Loading branch information
leemyongpakva committed Apr 4, 2024
2 parents 03955f7 + 3fe4fad commit d47e744
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 134 deletions.
8 changes: 8 additions & 0 deletions ProductComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ public static function deleteUsefulness($id_product_comment)
* Report comment
*
* @return bool
*
* @deprecated 4.0.0 - migrated to controllers/front/ReportComment and src/Entity/ProductCommentReport
*/
public static function reportComment($id_product_comment, $id_customer)
{
Expand All @@ -450,6 +452,8 @@ public static function reportComment($id_product_comment, $id_customer)
* Comment already report
*
* @return bool
*
* @deprecated 4.0.0 - migrated to controllers/front/ReportComment and src/Entity/ProductCommentReport
*/
public static function isAlreadyReport($id_product_comment, $id_customer)
{
Expand All @@ -464,6 +468,8 @@ public static function isAlreadyReport($id_product_comment, $id_customer)
* Set comment usefulness
*
* @return bool
*
* @deprecated 4.0.0 - migrated to controllers/front/UpdateCommentUsefulness and src/Entity/ProductCommentUsefulness
*/
public static function setCommentUsefulness($id_product_comment, $usefulness, $id_customer)
{
Expand All @@ -476,6 +482,8 @@ public static function setCommentUsefulness($id_product_comment, $usefulness, $i
* Usefulness already set
*
* @return bool
*
* @deprecated 4.0.0 - migrated to controllers/front/UpdateCommentUsefulness and src/Entity/ProductCommentUsefulness
*/
public static function isAlreadyUsefulness($id_product_comment, $id_customer)
{
Expand Down
18 changes: 9 additions & 9 deletions ProductCommentCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ProductCommentCriterion extends ObjectModel
],
];

/**
* @deprecated 6.0.0 - migrated to src/Repository/ProductCommentCriterionRepository
*/
public function delete()
{
if (!parent::delete()) {
Expand Down Expand Up @@ -96,6 +99,8 @@ public function update($nullValues = false)
* Link a Comment Criterion to a product
*
* @return bool succeed
*
* @deprecated 6.0.0 - migrated to src/Repository/ProductCommentCriterionRepository
*/
public function addProduct($id_product)
{
Expand All @@ -113,6 +118,8 @@ public function addProduct($id_product)
* Link a Comment Criterion to a category
*
* @return bool succeed
*
* @deprecated 6.0.0 - migrated to src/Repository/ProductCommentCriterionRepository
*/
public function addCategory($id_category)
{
Expand Down Expand Up @@ -165,13 +172,6 @@ public static function getByProduct($id_product, $id_lang)
!Validate::isUnsignedId($id_lang)) {
exit(Tools::displayError());
}
$alias = 'p';
$table = '';
// check if version > 1.5 to add shop association
if (version_compare(_PS_VERSION_, '1.5', '>')) {
$table = '_shop';
$alias = 'ps';
}

$cache_id = 'ProductCommentCriterion::getByProduct_' . $id_product . '-' . $id_lang;
if (!Cache::isStored($cache_id)) {
Expand All @@ -184,8 +184,8 @@ public static function getByProduct($id_product, $id_lang)
ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = ' . $id_product . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_comment_criterion_category` pccc
ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`)
LEFT JOIN `' . _DB_PREFIX_ . 'product' . $table . '` ' . $alias . '
ON (' . $alias . '.id_category_default = pccc.id_category AND ' . $alias . '.id_product = ' . $id_product . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` ps
ON (ps.id_category_default = pccc.id_category AND ps.id_product = ' . $id_product . ')
WHERE pccl.`id_lang` = ' . $id_lang . '
AND (
pccp.id_product IS NOT NULL
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>productcomments</name>
<displayName><![CDATA[Product Comments]]></displayName>
<version><![CDATA[6.0.2]]></version>
<version><![CDATA[6.0.3]]></version>
<description><![CDATA[Allows users to post reviews and rate products on specific criteria.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
16 changes: 16 additions & 0 deletions config/admin/services.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
imports:
- { resource: ../common.yml }

services:
product_comment_criterion_form_data_provider:
class: 'PrestaShop\Module\ProductComment\Form\ProductCommentCriterionFormDataProvider'
public: true
arguments:
- '@product_comment_criterion_repository'
- '@prestashop.core.admin.lang.repository'

product_comment_criterion_form_data_handler:
class: 'PrestaShop\Module\ProductComment\Form\ProductCommentCriterionFormDataHandler'
public: true
arguments:
- '@product_comment_criterion_repository'
- '@prestashop.core.admin.lang.repository'
- '@doctrine.orm.default_entity_manager'
16 changes: 8 additions & 8 deletions install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,56 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_comment` (
KEY `id_product` (`id_product`),
KEY `id_customer` (`id_customer`),
KEY `id_guest` (`id_guest`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion` (
`id_product_comment_criterion` int(10) unsigned NOT NULL auto_increment,
`id_product_comment_criterion_type` tinyint(1) NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id_product_comment_criterion`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_product` (
`id_product` int(10) unsigned NOT NULL,
`id_product_comment_criterion` int(10) unsigned NOT NULL,
PRIMARY KEY(`id_product`, `id_product_comment_criterion`),
KEY `id_product_comment_criterion` (`id_product_comment_criterion`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_lang` (
`id_product_comment_criterion` INT(11) UNSIGNED NOT NULL ,
`id_lang` INT(11) UNSIGNED NOT NULL ,
`name` VARCHAR(64) NOT NULL ,
PRIMARY KEY ( `id_product_comment_criterion` , `id_lang` )
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_criterion_category` (
`id_product_comment_criterion` int(10) unsigned NOT NULL,
`id_category` int(10) unsigned NOT NULL,
PRIMARY KEY(`id_product_comment_criterion`, `id_category`),
KEY `id_category` (`id_category`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_grade` (
`id_product_comment` int(10) unsigned NOT NULL,
`id_product_comment_criterion` int(10) unsigned NOT NULL,
`grade` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_product_comment`, `id_product_comment_criterion`),
KEY `id_product_comment_criterion` (`id_product_comment_criterion`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_usefulness` (
`id_product_comment` int(10) unsigned NOT NULL,
`id_customer` int(10) unsigned NOT NULL,
`usefulness` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`id_product_comment`, `id_customer`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PREFIX_product_comment_report` (
`id_product_comment` int(10) unsigned NOT NULL,
`id_customer` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_product_comment`, `id_customer`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO `PREFIX_product_comment_criterion` VALUES ('1', '1', '1');

Expand Down
71 changes: 53 additions & 18 deletions productcomments.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct()
{
$this->name = 'productcomments';
$this->tab = 'front_office_features';
$this->version = '6.0.2';
$this->version = '6.0.3';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -169,8 +169,10 @@ public function getCacheId($id_product = null)
protected function _postProcess()
{
$id_product_comment = (int) Tools::getValue('id_product_comment');
$id_product_comment_criterion = (int) Tools::getValue('id_product_comment_criterion');
$commentRepository = $this->get('product_comment_repository');
$criterionRepository = $this->get('product_comment_criterion_repository');
$criterionFormHandler = $this->get('product_comment_criterion_form_data_handler');

if (Tools::isSubmit('submitModerate')) {
$errors = [];
Expand Down Expand Up @@ -207,9 +209,20 @@ protected function _postProcess()
$commentRepository->deleteReports($id_product_comment);
} elseif (Tools::isSubmit('deleteproductcomments')) {
$comment = $commentRepository->find($id_product_comment);
$commentRepository->delete($comment);

if ($comment === null) {
$this->_html .= $this->displayError($this->trans('The comment cannot be deleted', [], 'Modules.Productcomments.Admin'));
} else {
$commentRepository->delete($comment);
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name]));
}
} elseif (Tools::isSubmit('submitEditCriterion')) {
$criterion = $criterionRepository->findRelation((int) Tools::getValue('id_product_comment_criterion'));
if ($id_product_comment_criterion > 0) {
$criterion = $criterionRepository->find($id_product_comment_criterion);
} else {
$criterion = new ProductCommentCriterion();
}

$criterion->setType((int) Tools::getValue('id_product_comment_criterion_type'));
$criterion->setActive(Tools::getValue('active'));

Expand All @@ -218,7 +231,12 @@ protected function _postProcess()
foreach ($languages as $key => $value) {
$name[$value['id_lang']] = Tools::getValue('name_' . $value['id_lang']);
}
$criterion->setNames($name);

if ($id_product_comment_criterion > 0) {
$criterionFormHandler->updateLangs($criterion, $name);
} else {
$criterionFormHandler->createLangs($criterion, $name);
}

if (!$criterion->isValid()) {
$this->_html .= $this->displayError($this->trans('The criterion cannot be saved', [], 'Modules.Productcomments.Admin'));
Expand All @@ -232,14 +250,18 @@ protected function _postProcess()
}
}
} elseif (Tools::isSubmit('deleteproductcommentscriterion')) {
$criterion = $criterionRepository->findRelation((int) Tools::getValue('id_product_comment_criterion'));
$criterion = $criterionRepository->find($id_product_comment_criterion);
if ($criterionRepository->delete($criterion)) {
$this->_html .= $this->displayConfirmation($this->trans('Criterion deleted', [], 'Modules.Productcomments.Admin'));
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name]));
} else {
$this->_html .= $this->displayError($this->trans('Criterion cannot be deleted', [], 'Modules.Productcomments.Admin'));
}
} elseif (Tools::isSubmit('statusproductcommentscriterion')) {
$criterion = $criterionRepository->findRelation((int) Tools::getValue('id_product_comment_criterion'));
$criterion = $criterionRepository->find($id_product_comment_criterion);
$criterion->setActive(!$criterion->isActive());
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name, 'tab_module' => $this->tab, 'conf' => 4, 'module_name' => $this->name]));
$criterionRepository->updateGeneral($criterion);

Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name]));
} elseif ($id_product_comment = (int) Tools::getValue('approveComment')) {
$comment = $commentRepository->find($id_product_comment);
$commentRepository->validate($comment, 1);
Expand Down Expand Up @@ -596,16 +618,22 @@ public function getConfigFieldsValues()
];
}

public function getCriterionFieldsValues($id = 0)
public function getCriterionFieldsValues(int $id = 0)
{
$criterionRepos = $this->get('product_comment_criterion_repository');
$criterion = $criterionRepos->findRelation($id);
$criterionFormProvider = $this->get('product_comment_criterion_form_data_provider');

if ($id > 0) {
$criterionData = $criterionFormProvider->getData($id);
} else {
$criterionData = $criterionFormProvider->getDefaultData();
}

return [
'name' => $criterion->getNames(),
'id_product_comment_criterion_type' => $criterion->getType(),
'active' => $criterion->isActive(),
'id_product_comment_criterion' => $criterion->getId(),
'name' => $criterionData['name'],
'id_product_comment_criterion_type' => $criterionData['type'],
'active' => $criterionData['active'],
'id_product_comment_criterion' => $id,
];
}

Expand Down Expand Up @@ -696,7 +724,7 @@ public function renderCriterionForm($id_criterion = 0)

$criterionRepository = $this->get('product_comment_criterion_repository');

$criterion = $criterionRepository->findRelation($id_criterion);
$criterion = $criterionRepository->find($id_criterion);
$selected_categories = $criterionRepository->getCategories($id_criterion);

$product_table_values = Product::getSimpleProducts($this->langId);
Expand Down Expand Up @@ -1044,9 +1072,16 @@ public function renderWidget($hookName = null, array $configuration = [])
$idProduct = $this->context->controller->getProduct()->id;
$variables = $this->getWidgetVariables($hookName, ['id_product' => $idProduct]);

$filePath = 'quickview' === Tools::getValue('action')
? $tplHookPath . 'product-additional-info-quickview.tpl'
: $tplHookPath . 'product-additional-info.tpl';
switch (Tools::getValue('action')) {
case 'quickview':
$filePath = $tplHookPath . 'product-additional-info-quickview.tpl';
break;
case '':
$filePath = $tplHookPath . 'product-additional-info.tpl';
break;
default: // 'refresh' and other unpredicted cases
$filePath = '';
}
}

if (empty($variables) || empty($filePath)) {
Expand Down
Loading

0 comments on commit d47e744

Please sign in to comment.