forked from shopware5/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalLineItemService.php
115 lines (103 loc) · 3.59 KB
/
ConditionalLineItemService.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our licensing model, this program can be used
* under the terms of the GNU Affero General Public License, version 3.
*
* The texts of the GNU Affero General Public License with an additional
* permission can be found at and in the LICENSE file you have received
* along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore, any rights, title and interest in
* our trademarks remain entirely with the shopware AG.
*/
namespace Shopware\Components\Cart;
use Doctrine\DBAL\Connection;
use Enlight_Components_Session_Namespace as Session;
use Shopware\Components\Cart\Struct\DiscountContext;
use Shopware_Components_Config as Config;
use sSystem as System;
class ConditionalLineItemService implements ConditionalLineItemServiceInterface
{
/**
* @var System
*/
private $system;
/**
* @var Session
*/
private $session;
/**
* @var Config
*/
private $config;
/**
* @var BasketHelperInterface
*/
private $basketHelper;
/**
* @var Connection
*/
private $connection;
public function __construct(
System $sSystem, Session $session, Config $config, BasketHelperInterface $basketHelper, Connection $connection
) {
$this->system = $sSystem;
$this->session = $session;
$this->config = $config;
$this->basketHelper = $basketHelper;
$this->connection = $connection;
}
public function addConditionalLineItem(string $name, string $orderNumber, float $price, float $tax, int $mode): void
{
$currencyFactor = empty($this->system->sCurrency['factor']) ? 1 : (float) $this->system->sCurrency['factor'];
$taxFree = empty($this->system->sUSERGROUPDATA['tax']) && !empty($this->system->sUSERGROUPDATA['id']);
$sessionId = $this->session->get('sessionId');
if ($taxFree) {
$netPrice = $price;
} else {
$netPrice = round($price / (100 + $tax) * 100, 2);
}
if (!$taxFree && $this->config->get('proportionalTaxCalculation')) {
$this->basketHelper->addProportionalDiscount(
new DiscountContext(
$sessionId,
BasketHelperInterface::DISCOUNT_ABSOLUTE,
$price,
$name,
$orderNumber,
$mode,
$currencyFactor,
$taxFree
)
);
} else {
$this->connection->insert(
's_order_basket',
[
'sessionID' => $sessionId,
'articlename' => $name,
'articleID' => 0,
'ordernumber' => $orderNumber,
'quantity' => 1,
'price' => $price,
'netprice' => $netPrice,
'tax_rate' => $tax,
'datum' => date('Y-m-d H:i:s'),
'modus' => $mode,
'currencyFactor' => $currencyFactor,
]
);
$this->connection->insert('s_order_basket_attributes', ['basketID' => $this->connection->lastInsertId()]);
}
}
}