This repository was archived by the owner on Jun 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprices.php
More file actions
89 lines (75 loc) · 2.93 KB
/
Copy pathprices.php
File metadata and controls
89 lines (75 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Plugin Name: Apisearch
* License: MIT
* Copyright (c) 2020 - 2025 Apisearch SL
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use
* of this software, even if advised of the possibility of such damages.
*
* Permission is hereby granted, free of charge, to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is provided to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice must be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT,
* OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
use Apisearch\Model\Product\ProductPrices;
use Apisearch\Context;
set_time_limit(1800);
/**
* We suppress all possible incoming output data to avoid malformed feed
*/
ob_start();
require_once(dirname(__FILE__) . '../../../config/config.inc.php');
require_once(dirname(__FILE__) . '../../../init.php');
require_once __DIR__.'/vendor/autoload.php';
function pricesFromProductsId(
Context $context,
array $productsId
)
{
$prices = [];
foreach ($productsId as $productId) {
$priceGroup = ProductPrices::getProductPrices($context, $productId, null, true);
$price = $priceGroup[0];
$priceWithCurrency = $priceGroup[1];
$priceNoRound = $priceGroup[2];
$oldPriceGroup = ProductPrices::getProductPrices($context, $productId, null, false);
$oldPrice = $oldPriceGroup[0];
$oldPriceWithCurrency = $oldPriceGroup[1];
$oldPriceNoRound = $oldPriceGroup[2];
$discountPercentage = ProductPrices::getDiscount($priceNoRound, $oldPriceNoRound);
$withDiscount = $discountPercentage !== null;
$prices[$productId] = [
'p' => $price,
'p_c' => $priceWithCurrency,
'op' => $oldPrice,
'op_c' => $oldPriceWithCurrency,
'wd' => $withDiscount,
'dp' => $discountPercentage
];
}
return $prices;
}
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET");
header("Content-Type: application/json; charset=UTF-8");
$ids = \Tools::getValue('ids', '');
$ids = explode(',', $ids);
$ids = array_filter($ids);
if (empty($ids)) {
echo "[]";
die();
}
$context = Context::fromCurrentPrestashopContext();
$prices = pricesFromProductsId($context, $ids);
echo json_encode($prices);