Passed
Branch master (901174)
by Aimeos
03:14
created

Standard::deleteCoupon()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 19
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 * @package Controller
8
 * @subpackage Frontend
9
 */
10
11
12
namespace Aimeos\Controller\Frontend\Basket;
13
14
15
/**
16
 * Default implementation of the basket frontend controller.
17
 *
18
 * @package Controller
19
 * @subpackage Frontend
20
 */
21
class Standard
22
	extends Base
23
	implements Iface, \Aimeos\Controller\Frontend\Common\Iface
24
{
25
	private $baskets = [];
26
	private $domainManager;
27
	private $type = 'default';
28
29
30
	/**
31
	 * Initializes the frontend controller.
32
	 *
33
	 * @param \Aimeos\MShop\Context\Item\Iface $context Object storing the required instances for manaing databases
34
	 *  connections, logger, session, etc.
35
	 */
36
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
37
	{
38
		parent::__construct( $context );
39
40
		$this->domainManager = \Aimeos\MShop::create( $context, 'order/base' );
41
	}
42
43
44
	/**
45
	 * Empties the basket and removing all products, addresses, services, etc.
46
	 *
47
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object
48
	 */
49
	public function clear()
50
	{
51
		$this->baskets[$this->type] = $this->domainManager->createItem();
52
		$this->domainManager->setSession( $this->baskets[$this->type], $this->type );
1 ignored issue
show
Bug introduced by
The method setSession() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
		$this->domainManager->/** @scrutinizer ignore-call */ 
53
                        setSession( $this->baskets[$this->type], $this->type );
Loading history...
53
54
		return $this;
55
	}
56
57
58
	/**
59
	 * Returns the basket object.
60
	 *
61
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options
62
	 */
63
	public function get()
64
	{
65
		if( !isset( $this->baskets[$this->type] ) )
66
		{
67
			$this->baskets[$this->type] = $this->domainManager->getSession( $this->type );
1 ignored issue
show
Bug introduced by
The method getSession() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
			/** @scrutinizer ignore-call */ 
68
   $this->baskets[$this->type] = $this->domainManager->getSession( $this->type );
Loading history...
68
			$this->checkLocale( $this->baskets[$this->type]->getLocale(), $this->type );
69
		}
70
71
		return $this->baskets[$this->type];
72
	}
73
74
75
	/**
76
	 * Explicitely persists the basket content
77
	 *
78
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object
79
	 */
80
	public function save()
81
	{
82
		if( isset( $this->baskets[$this->type] ) && $this->baskets[$this->type]->isModified() ) {
83
			$this->domainManager->setSession( $this->baskets[$this->type], $this->type );
84
		}
85
86
		return $this;
87
	}
88
89
90
	/**
91
	 * Sets the new basket type
92
	 *
93
	 * @param string $type Basket type
94
	 * @return \Aimeos\Controller\Frontend\Basket\Iface Basket frontend object
95
	 */
96
	public function setType( $type )
97
	{
98
		$this->type = $type;
99
		return $this;
100
	}
101
102
103
	/**
104
	 * Creates a new order base object from the current basket
105
	 *
106
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including products, addresses and services
107
	 */
108
	public function store()
109
	{
110
		$total = 0;
111
		$context = $this->getContext();
112
		$config = $context->getConfig();
113
114
		/** controller/frontend/basket/limit-count
115
		 * Maximum number of orders within the time frame
116
		 *
117
		 * Creating new orders is limited to avoid abuse and mitigate denial of
118
		 * service attacks. The number of orders created within the time frame
119
		 * configured by "controller/frontend/basket/limit-seconds" are counted
120
		 * before a new order of the same user (either logged in or identified
121
		 * by the IP address) is created. If the number of orders is higher than
122
		 * the configured value, an error message will be shown to the user
123
		 * instead of creating a new order.
124
		 *
125
		 * @param integer Number of orders allowed within the time frame
126
		 * @since 2017.05
127
		 * @category Developer
128
		 * @see controller/frontend/basket/limit-seconds
129
		 */
130
		$count = $config->get( 'controller/frontend/basket/limit-count', 5 );
131
132
		/** controller/frontend/basket/limit-seconds
133
		 * Order limitation time frame in seconds
134
		 *
135
		 * Creating new orders is limited to avoid abuse and mitigate denial of
136
		 * service attacks. Within the configured time frame, only a limited
137
		 * number of orders can be created. All orders of the current user
138
		 * (either logged in or identified by the IP address) within the last X
139
		 * seconds are counted. If the total value is higher then the number
140
		 * configured in "controller/frontend/basket/limit-count", an error
141
		 * message will be shown to the user instead of creating a new order.
142
		 *
143
		 * @param integer Number of seconds to check orders within
144
		 * @since 2017.05
145
		 * @category Developer
146
		 * @see controller/frontend/basket/limit-count
147
		 */
148
		$seconds = $config->get( 'controller/frontend/basket/limit-seconds', 300 );
149
150
		$search = $this->domainManager->createSearch();
151
		$expr = [
152
			$search->compare( '==', 'order.base.editor', $context->getEditor() ),
153
			$search->compare( '>=', 'order.base.ctime', date( 'Y-m-d H:i:s', time() - $seconds ) ),
154
		];
155
		$search->setConditions( $search->combine( '&&', $expr ) );
156
		$search->setSlice( 0, 0 );
157
158
		$this->domainManager->searchItems( $search, [], $total );
159
160
		if( $total > $count )
161
		{
162
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Temporary order limit reached' );
163
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
164
		}
165
166
167
		$basket = $this->get()->finish();
168
		$basket->setCustomerId( (string) $context->getUserId() );
169
170
		$this->domainManager->begin();
171
		$this->domainManager->store( $basket );
1 ignored issue
show
Bug introduced by
The method store() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
		$this->domainManager->/** @scrutinizer ignore-call */ 
172
                        store( $basket );
Loading history...
172
		$this->domainManager->commit();
173
174
		$this->save(); // for reusing unpaid orders, might have side effects (!)
175
		$this->createSubscriptions( $basket );
176
177
		return $basket;
178
	}
179
180
181
	/**
182
	 * Returns the order base object for the given ID
183
	 *
184
	 * @param string $id Unique ID of the order base object
185
	 * @param integer $parts Constants which parts of the order base object should be loaded
186
	 * @param boolean $default True to add default criteria (user logged in), false if not
187
	 * @return \Aimeos\MShop\Order\Item\Base\Iface Order base object including the given parts
188
	 */
189
	public function load( $id, $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL, $default = true )
190
	{
191
		return $this->domainManager->load( $id, $parts, false, $default );
1 ignored issue
show
Bug introduced by
The method load() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MShop\Locale\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

191
		return $this->domainManager->/** @scrutinizer ignore-call */ load( $id, $parts, false, $default );
Loading history...
192
	}
193
194
195
	/**
196
	 * Adds a categorized product to the basket of the user stored in the session.
197
	 *
198
	 * @param string $prodid ID of the base product to add
199
	 * @param integer $quantity Amount of products that should by added
200
	 * @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product
201
	 * 	in a selection products
202
	 * @param array $configAttributeIds  List of attribute IDs that doesn't identify a specific product in a
203
	 * 	selection of products but are stored together with the product (e.g. for configurable products)
204
	 * @param array $hiddenAttributeIds Deprecated
205
	 * @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored
206
	 * 	along with the product in the order
207
	 * @param string $stocktype Unique code of the stock type to deliver the products from
208
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available
209
	 */
210
	public function addProduct( $prodid, $quantity = 1, $stocktype = 'default', array $variantAttributeIds = [],
211
		array $configAttributeIds = [], array $hiddenAttributeIds = [], array $customAttributeValues = [] )
212
	{
213
		$attributeMap = [
214
			'custom' => array_keys( $customAttributeValues ),
215
			'config' => array_keys( $configAttributeIds ),
216
		];
217
		$this->checkListRef( $prodid, 'attribute', $attributeMap );
218
219
220
		$context = $this->getContext();
221
		$productManager = \Aimeos\MShop::create( $context, 'product' );
222
223
		$productItem = $productManager->getItem( $prodid, ['attribute', 'media', 'supplier', 'price', 'product', 'text'], true );
224
		$prices = $productItem->getRefItems( 'price', 'default', 'default' );
1 ignored issue
show
Bug introduced by
The method getRefItems() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\ListRef\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

224
		/** @scrutinizer ignore-call */ 
225
  $prices = $productItem->getRefItems( 'price', 'default', 'default' );
Loading history...
225
		$hidden = $productItem->getRefItems( 'attribute', null, 'hidden' );
226
227
		$orderBaseProductItem = \Aimeos\MShop::create( $context, 'order/base/product' )->createItem();
228
		$orderBaseProductItem->copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype );
0 ignored issues
show
Bug introduced by
The method copyFrom() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

228
		$orderBaseProductItem->/** @scrutinizer ignore-call */ 
229
                         copyFrom( $productItem )->setQuantity( $quantity )->setStockType( $stocktype );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
229
230
		$custAttr = $this->getOrderProductAttributes( 'custom', array_keys( $customAttributeValues ), $customAttributeValues );
231
		$confAttr = $this->getOrderProductAttributes( 'config', array_keys( $configAttributeIds ), [], $configAttributeIds );
232
		$attr = array_merge( $custAttr, $confAttr, $this->getOrderProductAttributes( 'hidden', array_keys( $hidden ) ) );
233
234
		$orderBaseProductItem->setAttributeItems( $attr );
0 ignored issues
show
Bug introduced by
The method setAttributeItems() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

234
		$orderBaseProductItem->/** @scrutinizer ignore-call */ 
235
                         setAttributeItems( $attr );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
235
		$orderBaseProductItem->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) );
0 ignored issues
show
Bug introduced by
$orderBaseProductItem of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Order\Item\Base\Product\Iface expected by parameter $product of Aimeos\Controller\Fronte...asket\Base::calcPrice(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

235
		$orderBaseProductItem->setPrice( $this->calcPrice( /** @scrutinizer ignore-type */ $orderBaseProductItem, $prices, $quantity ) );
Loading history...
Bug introduced by
The method setPrice() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

235
		$orderBaseProductItem->/** @scrutinizer ignore-call */ 
236
                         setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
236
237
		$this->get()->addProduct( $orderBaseProductItem );
238
		$this->save();
239
	}
240
241
242
	/**
243
	 * Deletes a product item from the basket.
244
	 *
245
	 * @param integer $position Position number (key) of the order product item
246
	 */
247
	public function deleteProduct( $position )
248
	{
249
		$product = $this->get()->getProduct( $position );
250
251
		if( $product->getFlags() === \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
252
		{
253
			$msg = $this->getContext()->getI18n()->dt( 'controller/frontend', 'Basket item at position "%1$d" cannot be deleted manually' );
254
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $position ) );
255
		}
256
257
		$this->get()->deleteProduct( $position );
258
		$this->save();
259
	}
260
261
262
	/**
263
	 * Edits the quantity of a product item in the basket.
264
	 *
265
	 * @param integer $position Position number (key) of the order product item
266
	 * @param integer $quantity New quantiy of the product item
267
	 * @param string[] $configAttributeCodes Codes of the product config attributes that should be REMOVED
268
	 */
269
	public function editProduct( $position, $quantity, array $configAttributeCodes = [] )
270
	{
271
		$product = $this->get()->getProduct( $position );
272
273
		if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE )
274
		{
275
			$msg = $this->getContext()->getI18n()->dt( 'controller/frontend', 'Basket item at position "%1$d" cannot be changed' );
276
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $position ) );
277
		}
278
279
		$product->setQuantity( $quantity );
280
281
		$attributes = $product->getAttributeItems();
282
		foreach( $attributes as $key => $attribute )
283
		{
284
			if( in_array( $attribute->getCode(), $configAttributeCodes ) ) {
285
				unset( $attributes[$key] );
286
			}
287
		}
288
		$product->setAttributeItems( $attributes );
289
290
		$manager = \Aimeos\MShop::create( $this->getContext(), 'product' );
291
		$productItem = $manager->findItem( $product->getProductCode(), array( 'price', 'text' ), true );
1 ignored issue
show
Bug introduced by
The method findItem() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

291
		/** @scrutinizer ignore-call */ 
292
  $productItem = $manager->findItem( $product->getProductCode(), array( 'price', 'text' ), true );
Loading history...
292
		$product->setPrice( $this->calcPrice( $product, $productItem->getRefItems( 'price', 'default' ), $quantity ) );
293
294
		$this->get()->addProduct( $product, $position );
295
296
		$this->save();
297
	}
298
299
300
	/**
301
	 * Adds the given coupon code and updates the basket.
302
	 *
303
	 * @param string $code Coupon code entered by the user
304
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed
305
	 */
306
	public function addCoupon( $code )
307
	{
308
		$context = $this->getContext();
309
310
		/** controller/frontend/basket/standard/coupon/allowed
311
		 * Number of coupon codes a customer is allowed to enter
312
		 *
313
		 * This configuration option enables shop owners to limit the number of coupon
314
		 * codes that can be added by a customer to his current basket. By default, only
315
		 * one coupon code is allowed per order.
316
		 *
317
		 * Coupon codes are valid until a payed order is placed by the customer. The
318
		 * "count" of the codes is decreased afterwards. If codes are not personalized
319
		 * the codes can be reused in the next order until their "count" reaches zero.
320
		 *
321
		 * @param integer Positive number of coupon codes including zero
322
		 * @since 2017.08
323
		 * @category User
324
		 * @category Developer
325
		 */
326
		$allowed = $context->getConfig()->get( 'controller/frontend/basket/standard/coupon/allowed', 1 );
327
328
		if( $allowed <= count( $this->get()->getCoupons() ) )
329
		{
330
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Number of coupon codes exceeds the limit' );
331
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
332
		}
333
334
335
		$manager = \Aimeos\MShop::create( $context, 'coupon' );
336
		$codeManager = \Aimeos\MShop::create( $context, 'coupon/code' );
337
338
		$search = $manager->createSearch( true )->setSlice( 0, 1 );
339
		$expr = [
340
			$search->compare( '==', 'coupon.code.code', $code ),
341
			$codeManager->createSearch( true )->getConditions(),
342
			$search->getConditions(),
343
		];
344
		$search->setConditions( $search->combine( '&&', $expr ) );
345
346
		$result = $manager->searchItems( $search );
347
348
		if( ( $item = reset( $result ) ) === false )
349
		{
350
			$msg = sprintf( $context->getI18n()->dt( 'controller/frontend', 'Coupon code "%1$s" is invalid or not available any more' ), $code );
351
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
352
		}
353
354
355
		$provider = $manager->getProvider( $item, $code );
1 ignored issue
show
Bug introduced by
The method getProvider() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MShop\Common\Manager\Type\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Customer\Manager\Group\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Index\Manager\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

355
		/** @scrutinizer ignore-call */ 
356
  $provider = $manager->getProvider( $item, $code );
Loading history...
356
357
		if( $provider->isAvailable( $this->get() ) !== true )
358
		{
359
			$msg = sprintf( $context->getI18n()->dt( 'controller/frontend', 'Requirements for coupon code "%1$s" aren\'t met' ), $code );
360
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
361
		}
362
363
		$provider->addCoupon( $this->get() );
364
		$this->save();
365
	}
366
367
368
	/**
369
	 * Removes the given coupon code and its effects from the basket.
370
	 *
371
	 * @param string $code Coupon code entered by the user
372
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid
373
	 */
374
	public function deleteCoupon( $code )
375
	{
376
		$context = $this->getContext();
377
		$manager = \Aimeos\MShop::create( $context, 'coupon' );
378
379
		$search = $manager->createSearch();
380
		$search->setConditions( $search->compare( '==', 'coupon.code.code', $code ) );
381
		$search->setSlice( 0, 1 );
382
383
		$result = $manager->searchItems( $search );
384
385
		if( ( $item = reset( $result ) ) === false )
386
		{
387
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Coupon code "%1$s" is invalid' );
388
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $code ) );
389
		}
390
391
		$manager->getProvider( $item, $code )->deleteCoupon( $this->get() );
392
		$this->save();
393
	}
394
395
396
	/**
397
	 * Sets the address of the customer in the basket.
398
	 *
399
	 * @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base
400
	 * @param \Aimeos\MShop\Common\Item\Address\Iface|array|null $value Address object or array with key/value pairs of address or null to remove address from basket
401
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of
402
	 * 	if one of the keys is invalid when using an array with key/value pairs
403
	 */
404
	public function setAddress( $type, $value )
405
	{
406
		$context = $this->getContext();
407
		$address = \Aimeos\MShop::create( $context, 'order/base/address' )->createItem();
408
		$address->setType( $type );
409
410
		if( $value instanceof \Aimeos\MShop\Common\Item\Address\Iface )
411
		{
412
			$this->get()->setAddress( $address->copyFrom( $value ), $type );
413
		}
414
		else if( is_array( $value ) )
415
		{
416
			$this->get()->setAddress( $this->setAddressFromArray( $address, $value ), $type );
0 ignored issues
show
Bug introduced by
$address of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Order\Item\Base\Address\Iface expected by parameter $address of Aimeos\Controller\Fronte...::setAddressFromArray(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

416
			$this->get()->setAddress( $this->setAddressFromArray( /** @scrutinizer ignore-type */ $address, $value ), $type );
Loading history...
417
		}
418
		else if( $value === null )
0 ignored issues
show
introduced by
The condition $value === null is always true.
Loading history...
419
		{
420
			$this->get()->deleteAddress( $type );
421
		}
422
		else
423
		{
424
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid value for address type "%1$s"' );
425
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $type ) );
426
		}
427
428
		$this->save();
429
	}
430
431
432
	/**
433
	 * Adds the delivery/payment service item based on the service ID.
434
	 *
435
	 * @param string $type Service type code like 'payment' or 'delivery'
436
	 * @param string $id|null Unique ID of the service item or null to remove it
437
	 * @param array $attributes Associative list of key/value pairs containing the attributes selected or
438
	 * 	entered by the customer when choosing one of the delivery or payment options
439
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached
440
	 */
441
	public function addService( $type, $id, array $attributes = [] )
442
	{
443
		$context = $this->getContext();
444
445
		$serviceManager = \Aimeos\MShop::create( $context, 'service' );
446
		$serviceItem = $serviceManager->getItem( $id, array( 'media', 'price', 'text' ) );
447
448
		$provider = $serviceManager->getProvider( $serviceItem, $serviceItem->getType() );
1 ignored issue
show
Bug introduced by
The method getType() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Order\Item\Base\Service\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Common\Item\Property\Standard or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Tag\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Stock\Item\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Order\Item\Base\Service\Base or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Order\Item\Base\Address\Standard or Aimeos\MShop\Order\Item\Standard or Aimeos\MShop\Order\Item\Status\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Base\Address\Iface or Aimeos\MShop\Order\Item\Base\Address\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

448
		$provider = $serviceManager->getProvider( $serviceItem, $serviceItem->/** @scrutinizer ignore-call */ getType() );
Loading history...
449
		$result = $provider->checkConfigFE( $attributes );
450
		$unknown = array_diff_key( $attributes, $result );
451
452
		if( count( $unknown ) > 0 )
453
		{
454
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Unknown attributes "%1$s"' );
455
			$msg = sprintf( $msg, implode( '","', array_keys( $unknown ) ) );
456
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg );
457
		}
458
459
		foreach( $result as $key => $value )
460
		{
461
			if( $value !== null ) {
462
				throw new \Aimeos\Controller\Frontend\Basket\Exception( $value );
463
			}
464
		}
465
466
		$orderBaseServiceManager = \Aimeos\MShop::create( $context, 'order/base/service' );
467
		$orderServiceItem = $orderBaseServiceManager->createItem();
468
		$orderServiceItem->copyFrom( $serviceItem );
469
470
		// remove service rebate of original price
471
		$price = $provider->calcPrice( $this->get() )->setRebate( '0.00' );
472
		$orderServiceItem->setPrice( $price );
473
474
		$provider->setConfigFE( $orderServiceItem, $attributes );
475
476
		$this->get()->addService( $orderServiceItem, $type );
0 ignored issues
show
Bug introduced by
$orderServiceItem of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Order\Item\Base\Service\Iface expected by parameter $service of Aimeos\MShop\Order\Item\Base\Iface::addService(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

476
		$this->get()->addService( /** @scrutinizer ignore-type */ $orderServiceItem, $type );
Loading history...
477
		$this->save();
478
	}
479
480
481
	/**
482
	 * Removes the delivery or payment service items from the basket
483
	 *
484
	 * @param string $type Service type code like 'payment' or 'delivery'
485
	 */
486
	public function deleteService( $type )
487
	{
488
		$this->get()->deleteService( $type );
489
		$this->save();
490
	}
491
492
493
	/**
494
	 * Fills the order address object with the values from the array.
495
	 *
496
	 * @param \Aimeos\MShop\Order\Item\Base\Address\Iface $address Address item to store the values into
497
	 * @param array $map Associative array of key/value pairs. The keys must be the same as when calling toArray() from
498
	 * 	an address item.
499
	 * @return \Aimeos\MShop\Order\Item\Base\Address\Iface Updated address item
500
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception
501
	 */
502
	protected function setAddressFromArray( \Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map )
503
	{
504
		foreach( $map as $key => $value ) {
505
			$map[$key] = strip_tags( $value ); // prevent XSS
506
		}
507
508
		$address = $address->fromArray( $map );
509
510
		if( count( $map ) > 0 )
511
		{
512
			$msg = $this->getContext()->getI18n()->dt( 'controller/frontend', 'Invalid address properties, please check your input' );
513
			throw new \Aimeos\Controller\Frontend\Basket\Exception( $msg, 0, null, $map );
514
		}
515
516
		return $address;
517
	}
518
}
519