Skip to content

Commit 48702f5

Browse files
committed
Fix tests
1 parent a1af1e2 commit 48702f5

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

classes/Hook/HookActionCartUpdateQuantityBefore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Ps_Googleanalytics $module, Context $context)
4848
*/
4949
public function run()
5050
{
51-
/*
51+
/*
5252
* The hook passes a legacy Product object to add, but no attribute information.
5353
* But thankfully, we can use id_product_attribute for this.
5454
*
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
8+
* that is bundled with this package in the file LICENSE.md.
9+
* It is also available through the world-wide-web at this URL:
10+
* https://opensource.org/licenses/AFL-3.0
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* @author PrestaShop SA <contact@prestashop.com>
16+
* @copyright Since 2007 PrestaShop SA and Contributors
17+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
18+
* International Registered Trademark & Property of PrestaShop SA
19+
*/
20+
21+
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
22+
23+
use Context;
24+
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
25+
use Product;
26+
use Ps_Googleanalytics;
27+
use Validate;
28+
29+
class HookActionObjectProductInCartDeleteBefore implements HookInterface
30+
{
31+
private $module;
32+
33+
/**
34+
* @var Context
35+
*/
36+
private $context;
37+
private $params;
38+
39+
public function __construct(Ps_Googleanalytics $module, Context $context)
40+
{
41+
$this->module = $module;
42+
$this->context = $context;
43+
}
44+
45+
/**
46+
* run
47+
*
48+
* @return void
49+
*/
50+
public function run()
51+
{
52+
// Format product and standardize ID
53+
$product = new Product((int) $this->params['id_product'], false, (int) $this->context->language->id);
54+
if (!Validate::isLoadedObject($product)) {
55+
return;
56+
}
57+
$product = (array) $product;
58+
$product['id_product'] = $product['id'];
59+
60+
// Get some basic information
61+
$product = Product::getProductProperties($this->context->language->id, $product);
62+
63+
// Add information about attribute
64+
if (!empty($this->params['id_product_attribute'])) {
65+
$product['id_product_attribute'] = (int) $this->params['id_product_attribute'];
66+
}
67+
68+
// Prepare it and format it for our purpose
69+
$productWrapper = new ProductWrapper($this->context);
70+
$item = $productWrapper->prepareItemFromProduct($product, false);
71+
72+
// Prepare and render event
73+
$eventData = [
74+
'currency' => $this->context->currency->iso_code,
75+
'value' => $item['price'] * $item['quantity'],
76+
'items' => [$item],
77+
];
78+
$jsCode = $this->module->getTools()->renderEvent(
79+
'remove_from_cart',
80+
$eventData
81+
);
82+
83+
// Store this event
84+
$this->module->getDataHandler()->persistData($jsCode);
85+
}
86+
87+
/**
88+
* @param array $params
89+
*/
90+
public function setParams($params)
91+
{
92+
$this->params = $params;
93+
}
94+
}

tests/phpstan/phpstan-1.7.6.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ includes:
44
parameters:
55
ignoreErrors:
66
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'
7-
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
87
- '#Property TabCore\:\:\$name \(string\) does not accept array.#'
98
- '#Parameter \#1 \$id of class Currency constructor expects null, int given.#'
109
- '#Access to an undefined property Cookie\:\:\$ga_admin_order.#'

0 commit comments

Comments
 (0)