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

Base::checkLocale()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 34
rs 8.9457
c 0
b 0
f 0
cc 6
nc 9
nop 2
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
 * Base class for the basket frontend controller
17
 *
18
 * @package Controller
19
 * @subpackage Frontend
20
 */
21
abstract class Base extends \Aimeos\Controller\Frontend\Base implements Iface
22
{
23
	private $listTypeItems = [];
24
25
26
	/**
27
	 * Calculates and returns the current price for the given order product and product prices.
28
	 *
29
	 * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Ordered product item
30
	 * @param \Aimeos\MShop\Price\Item\Iface[] $prices List of price items
31
	 * @param integer $quantity New product quantity
32
	 * @return \Aimeos\MShop\Price\Item\Iface Price item with calculated price
33
	 */
34
	protected function calcPrice( \Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $prices, $quantity )
35
	{
36
		$context = $this->getContext();
37
38
		if( empty( $prices ) )
39
		{
40
			$manager = \Aimeos\MShop::create( $context, 'product' );
41
			$prices = $manager->getItem( $product->getProductId(), array( 'price' ) )->getRefItems( 'price', '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

41
			$prices = $manager->getItem( $product->getProductId(), array( 'price' ) )->/** @scrutinizer ignore-call */ getRefItems( 'price', 'default' );
Loading history...
42
		}
43
44
45
		$priceManager = \Aimeos\MShop::create( $context, 'price' );
46
		$price = $priceManager->getLowestPrice( $prices, $quantity );
1 ignored issue
show
Bug introduced by
The method getLowestPrice() 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\Price\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\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\Order\Manager\Base\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

46
		/** @scrutinizer ignore-call */ 
47
  $price = $priceManager->getLowestPrice( $prices, $quantity );
Loading history...
47
48
		// customers can pay what they would like to pay
49
		if( ( $attr = $product->getAttributeItem( 'price', 'custom' ) ) !== null )
50
		{
51
			$amount = $attr->getValue();
52
53
			if( preg_match( '/^[0-9]*(\.[0-9]+)?$/', $amount ) !== 1 || ((double) $amount) < 0.01 )
0 ignored issues
show
Bug introduced by
It seems like $amount can also be of type array; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

53
			if( preg_match( '/^[0-9]*(\.[0-9]+)?$/', /** @scrutinizer ignore-type */ $amount ) !== 1 || ((double) $amount) < 0.01 )
Loading history...
54
			{
55
				$msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid price value "%1$s"' );
56
				throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $amount ) );
0 ignored issues
show
Bug introduced by
It seems like $amount can also be of type array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

56
				throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, /** @scrutinizer ignore-type */ $amount ) );
Loading history...
57
			}
58
59
			$price->setValue( $amount );
60
		}
61
62
		$orderAttributes = $product->getAttributeItems();
63
		$attrItems = $this->getAttributeItems( $orderAttributes );
64
65
		// add prices of (optional) attributes
66
		foreach( $orderAttributes as $orderAttrItem )
67
		{
68
			$attrId = $orderAttrItem->getAttributeId();
69
70
			if( isset( $attrItems[$attrId] )
71
				&& ( $prices = $attrItems[$attrId]->getRefItems( 'price', 'default' ) ) !== []
72
			) {
73
				$attrPrice = $priceManager->getLowestPrice( $prices, $orderAttrItem->getQuantity() );
74
				$price->addItem( $attrPrice, $orderAttrItem->getQuantity() );
75
			}
76
		}
77
78
		// remove product rebate of original price in favor to rebates granted for the order
79
		$price->setRebate( '0.00' );
80
81
		return $price;
82
	}
83
84
85
	/**
86
	 * Checks if the reference IDs are really associated to the product
87
	 *
88
	 * @param string|array $prodId Unique ID of the product or list of product IDs
89
	 * @param string $domain Domain the references must be of
90
	 * @param array $refMap Associative list of list type codes as keys and lists of reference IDs as values
91
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated
92
	 */
93
	protected function checkListRef( $prodId, $domain, array $refMap )
94
	{
95
		if( empty( $refMap ) ) {
96
			return;
97
		}
98
99
		$context = $this->getContext();
100
		$productManager = \Aimeos\MShop::create( $context, 'product' );
101
		$search = $productManager->createSearch( true );
102
103
		$expr = array(
104
			$search->compare( '==', 'product.id', $prodId ),
105
			$search->getConditions(),
106
		);
107
108
		foreach( $refMap as $listType => $refIds )
109
		{
110
			foreach( $refIds as $key => $refId )
111
			{
112
				$cmpfunc = $search->createFunction( 'product:has', [$domain, $listType, (string) $refId] );
113
				$expr[] = $search->compare( '!=', $cmpfunc, null );
114
			}
115
		}
116
117
		$search->setConditions( $search->combine( '&&', $expr ) );
118
119
		if( count( $productManager->searchItems( $search, [] ) ) === 0 )
120
		{
121
			$msg = $context->getI18n()->dt( 'controller/frontend', 'Invalid "%1$s" references for product with ID %2$s' );
122
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $domain, json_encode( $prodId ) ) );
123
		}
124
	}
125
126
127
	/**
128
	 * Checks for a locale mismatch and migrates the products to the new basket if necessary.
129
	 *
130
	 * @param \Aimeos\MShop\Locale\Item\Iface $locale Locale object from current basket
131
	 * @param string $type Basket type
132
	 */
133
	protected function checkLocale( \Aimeos\MShop\Locale\Item\Iface $locale, $type )
134
	{
135
		$errors = [];
136
		$context = $this->getContext();
137
		$session = $context->getSession();
138
139
		$localeStr = $session->get( 'aimeos/basket/locale' );
140
		$localeKey = $locale->getSite()->getCode() . '|' . $locale->getLanguageId() . '|' . $locale->getCurrencyId();
141
142
		if( $localeStr !== null && $localeStr !== $localeKey )
143
		{
144
			$locParts = explode( '|', $localeStr );
145
			$locSite = ( isset( $locParts[0] ) ? $locParts[0] : '' );
146
			$locLanguage = ( isset( $locParts[1] ) ? $locParts[1] : '' );
147
			$locCurrency = ( isset( $locParts[2] ) ? $locParts[2] : '' );
148
149
			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
150
			$locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false );
1 ignored issue
show
Bug introduced by
The method bootstrap() 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\Locale\Manager\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\Order\Manager\Base\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\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

150
			/** @scrutinizer ignore-call */ 
151
   $locale = $localeManager->bootstrap( $locSite, $locLanguage, $locCurrency, false );
Loading history...
151
152
			$context = clone $context;
153
			$context->setLocale( $locale );
154
155
			$manager = \Aimeos\MShop::create( $context, 'order/base' );
156
			$basket = $manager->getSession( $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

156
			/** @scrutinizer ignore-call */ 
157
   $basket = $manager->getSession( $type );
Loading history...
157
158
			$this->copyAddresses( $basket, $errors, $localeKey );
159
			$this->copyServices( $basket, $errors );
160
			$this->copyProducts( $basket, $errors, $localeKey );
161
			$this->copyCoupons( $basket, $errors, $localeKey );
162
163
			$manager->setSession( $basket, $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

163
			$manager->/** @scrutinizer ignore-call */ 
164
             setSession( $basket, $type );
Loading history...
164
		}
165
166
		$session->set( 'aimeos/basket/locale', $localeKey );
167
	}
168
169
170
	/**
171
	 * Migrates the addresses from the old basket to the current one.
172
	 *
173
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
174
	 * @param array $errors Associative list of previous errors
175
	 * @param string $localeKey Unique identifier of the site, language and currency
176
	 * @return array Associative list of errors occured
177
	 */
178
	protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
179
	{
180
		foreach( $basket->getAddresses() as $type => $item )
181
		{
182
			try
183
			{
184
				$this->setAddress( $type, $item->toArray() );
185
				$basket->deleteAddress( $type );
186
			}
187
			catch( \Exception $e )
188
			{
189
				$logger = $this->getContext()->getLogger();
190
				$errors['address'][$type] = $e->getMessage();
191
192
				$str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s';
193
				$logger->log( sprintf( $str, $type, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
194
			}
195
		}
196
197
		return $errors;
198
	}
199
200
201
	/**
202
	 * Migrates the coupons from the old basket to the current one.
203
	 *
204
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
205
	 * @param array $errors Associative list of previous errors
206
	 * @param string $localeKey Unique identifier of the site, language and currency
207
	 * @return array Associative list of errors occured
208
	 */
209
	protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
210
	{
211
		foreach( $basket->getCoupons() as $code => $list )
212
		{
213
			try
214
			{
215
				$this->addCoupon( $code );
216
				$basket->deleteCoupon( $code, true );
217
			}
218
			catch( \Exception $e )
219
			{
220
				$logger = $this->getContext()->getLogger();
221
				$errors['coupon'][$code] = $e->getMessage();
222
223
				$str = 'Error migrating coupon with code "%1$s" in basket to locale "%2$s": %3$s';
224
				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
225
			}
226
		}
227
228
		return $errors;
229
	}
230
231
232
	/**
233
	 * Migrates the products from the old basket to the current one.
234
	 *
235
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
236
	 * @param array $errors Associative list of previous errors
237
	 * @param string $localeKey Unique identifier of the site, language and currency
238
	 * @return array Associative list of errors occured
239
	 */
240
	protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey )
241
	{
242
		foreach( $basket->getProducts() as $pos => $product )
243
		{
244
			if( $product->getFlags() & \Aimeos\MShop\Order\Item\Base\Product\Base::FLAG_IMMUTABLE ) {
245
				continue;
246
			}
247
248
			try
249
			{
250
				$variantIds = $configIds = $customIds = [];
251
252
				foreach( $product->getAttributeItems() as $attrItem )
253
				{
254
					switch( $attrItem->getType() )
255
					{
256
						case 'variant': $variantIds[] = $attrItem->getAttributeId(); break;
257
						case 'config': $configIds[$attrItem->getAttributeId()] = $attrItem->getQuantity(); break;
258
						case 'custom': $customIds[$attrItem->getAttributeId()] = $attrItem->getValue(); break;
259
					}
260
				}
261
262
				$this->addProduct(
263
					$product->getProductId(), $product->getQuantity(), $product->getStockType(),
264
					$variantIds, $configIds, [], $customIds
265
				);
266
267
				$basket->deleteProduct( $pos );
268
			}
269
			catch( \Exception $e )
270
			{
271
				$code = $product->getProductCode();
272
				$logger = $this->getContext()->getLogger();
273
				$errors['product'][$pos] = $e->getMessage();
274
275
				$str = 'Error migrating product with code "%1$s" in basket to locale "%2$s": %3$s';
276
				$logger->log( sprintf( $str, $code, $localeKey, $e->getMessage() ), \Aimeos\MW\Logger\Base::INFO );
277
			}
278
		}
279
280
		return $errors;
281
	}
282
283
284
	/**
285
	 * Migrates the services from the old basket to the current one.
286
	 *
287
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
288
	 * @param array $errors Associative list of previous errors
289
	 * @return array Associative list of errors occured
290
	 */
291
	protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors )
292
	{
293
		foreach( $basket->getServices() as $type => $list )
294
		{
295
			foreach( $list as $item )
296
			{
297
				try
298
				{
299
					$attributes = [];
300
301
					foreach( $item->getAttributeItems() as $attrItem ) {
302
						$attributes[$attrItem->getCode()] = $attrItem->getValue();
303
					}
304
305
					$this->addService( $type, $item->getServiceId(), $attributes );
306
					$basket->deleteService( $type );
307
				}
308
				catch( \Exception $e ) { ; } // Don't notify the user as appropriate services can be added automatically
309
			}
310
		}
311
312
		return $errors;
313
	}
314
315
316
	/**
317
	 * Creates the subscription entries for the ordered products with interval attributes
318
	 *
319
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
320
	 */
321
	protected function createSubscriptions( \Aimeos\MShop\Order\Item\Base\Iface $basket )
322
	{
323
		$manager = \Aimeos\MShop::create( $this->getContext(), 'subscription' );
324
325
		foreach( $basket->getProducts() as $orderProduct )
326
		{
327
			if( ( $interval = $orderProduct->getAttribute( 'interval', 'config' ) ) !== null )
328
			{
329
				$item = $manager->createItem();
330
				$item->setOrderBaseId( $basket->getId() );
0 ignored issues
show
Bug introduced by
The method setOrderBaseId() 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

330
				$item->/** @scrutinizer ignore-call */ 
331
           setOrderBaseId( $basket->getId() );

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...
331
				$item->setOrderProductId( $orderProduct->getId() );
0 ignored issues
show
Bug introduced by
The method setOrderProductId() 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

331
				$item->/** @scrutinizer ignore-call */ 
332
           setOrderProductId( $orderProduct->getId() );

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...
332
				$item->setInterval( $interval );
0 ignored issues
show
Bug introduced by
The method setInterval() 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

332
				$item->/** @scrutinizer ignore-call */ 
333
           setInterval( $interval );

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...
333
				$item->setStatus( 1 );
334
335
				if( ( $end = $orderProduct->getAttribute( 'intervalend', 'custom' ) ) !== null
336
					|| ( $end = $orderProduct->getAttribute( 'intervalend', 'config' ) ) !== null
337
					|| ( $end = $orderProduct->getAttribute( 'intervalend', 'hidden' ) ) !== null
338
				) {
339
					$item->setDateEnd( $end );
0 ignored issues
show
Bug introduced by
The method setDateEnd() 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

339
					$item->/** @scrutinizer ignore-call */ 
340
            setDateEnd( $end );

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...
340
				}
341
342
				$manager->saveItem( $item, false );
343
			}
344
		}
345
	}
346
347
348
	/**
349
	 * Returns the attribute items for the given attribute IDs.
350
	 *
351
	 * @param array $attributeIds List of attribute IDs
352
	 * @param string[] $domains Names of the domain items that should be fetched too
353
	 * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface
354
	 * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one
355
	 */
356
	protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) )
357
	{
358
		if( empty( $attributeIds ) ) {
359
			return [];
360
		}
361
362
		$attributeManager = \Aimeos\MShop::create( $this->getContext(), 'attribute' );
363
364
		$search = $attributeManager->createSearch( true );
365
		$expr = array(
366
			$search->compare( '==', 'attribute.id', $attributeIds ),
367
			$search->getConditions(),
368
		);
369
		$search->setConditions( $search->combine( '&&', $expr ) );
370
		$search->setSlice( 0, count( $attributeIds ) );
371
372
		$attrItems = $attributeManager->searchItems( $search, $domains );
373
374
		if( count( $attrItems ) !== count( $attributeIds ) )
375
		{
376
			$i18n = $this->getContext()->getI18n();
377
			$expected = implode( ',', $attributeIds );
378
			$actual = implode( ',', array_keys( $attrItems ) );
379
			$msg = $i18n->dt( 'controller/frontend', 'Available attribute IDs "%1$s" do not match the given attribute IDs "%2$s"' );
380
381
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $actual, $expected ) );
382
		}
383
384
		return $attrItems;
385
	}
386
387
388
	/**
389
	 * Returns the attribute items using the given order attribute items.
390
	 *
391
	 * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items
392
	 * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values
393
	 */
394
	protected function getAttributeItems( array $orderAttributes )
395
	{
396
		if( empty( $orderAttributes ) ) {
397
			return [];
398
		}
399
400
		$attributeManager = \Aimeos\MShop::create( $this->getContext(), 'attribute' );
401
		$search = $attributeManager->createSearch( true );
402
		$expr = [];
403
404
		foreach( $orderAttributes as $item )
405
		{
406
			$tmp = array(
407
				$search->compare( '==', 'attribute.domain', 'product' ),
408
				$search->compare( '==', 'attribute.code', $item->getValue() ),
409
				$search->compare( '==', 'attribute.type', $item->getCode() ),
410
				$search->compare( '>', 'attribute.status', 0 ),
411
				$search->getConditions(),
412
			);
413
			$expr[] = $search->combine( '&&', $tmp );
414
		}
415
416
		$search->setConditions( $search->combine( '||', $expr ) );
417
		return $attributeManager->searchItems( $search, array( 'price' ) );
418
	}
419
420
421
	/**
422
	 * Returns the order product attribute items for the given IDs and values
423
	 *
424
	 * @param string $type Attribute type code
425
	 * @param array $ids List of attributes IDs of the given type
426
	 * @param array $values Associative list of attribute IDs as keys and their codes as values
427
	 * @param array $quantities Associative list of attribute IDs as keys and their quantities as values
428
	 * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface
429
	 */
430
	protected function getOrderProductAttributes( $type, array $ids, array $values = [], array $quantities = [] )
431
	{
432
		if( empty( $ids ) ) {
433
			return [];
434
		}
435
436
		$list = [];
437
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product/attribute' );
438
439
		foreach( $this->getAttributes( $ids ) as $id => $attrItem )
440
		{
441
			$item = $manager->createItem();
442
			$item->copyFrom( $attrItem );
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

442
			$item->/** @scrutinizer ignore-call */ 
443
          copyFrom( $attrItem );

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...
443
			$item->setType( $type );
444
			$item->setQuantity( isset( $quantities[$id] ) ? $quantities[$id] : 1 );
0 ignored issues
show
Bug introduced by
The method setQuantity() 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

444
			$item->/** @scrutinizer ignore-call */ 
445
          setQuantity( isset( $quantities[$id] ) ? $quantities[$id] : 1 );

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...
445
446
			if( isset( $values[$id] ) ) {
447
				$item->setValue( $values[$id] );
0 ignored issues
show
Bug introduced by
The method setValue() 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

447
				$item->/** @scrutinizer ignore-call */ 
448
           setValue( $values[$id] );

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...
448
			}
449
450
			$list[] = $item;
451
		}
452
453
		return $list;
454
	}
455
456
457
	/**
458
	 * Returns the list type item for the given domain and code.
459
	 *
460
	 * @param string $domain Domain name of the list type
461
	 * @param string $code Code of the list type
462
	 * @return \Aimeos\MShop\Common\Item\Type\Iface List type item
463
	 */
464
	protected function getProductListTypeItem( $domain, $code )
465
	{
466
		$context = $this->getContext();
467
468
		if( empty( $this->listTypeItems ) )
469
		{
470
			$manager = \Aimeos\MShop::create( $context, 'product/lists/type' );
471
472
			foreach( $manager->searchItems( $manager->createSearch( true ) ) as $item ) {
473
				$this->listTypeItems[ $item->getDomain() ][ $item->getCode() ] = $item;
2 ignored issues
show
Bug introduced by
The method getDomain() 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\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\Tag\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Tag\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Price\Item\Base 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\Common\Item\Type\Iface or Aimeos\MShop\Attribute\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\Media\Item\Iface or 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

473
				$this->listTypeItems[ $item->/** @scrutinizer ignore-call */ getDomain() ][ $item->getCode() ] = $item;
Loading history...
Bug introduced by
The method getCode() 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\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Base\Service\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Order\Item\Base\Coupon\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Group\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Order\Item\Base\Service\Base or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Order\Item\Base\Coupon\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Tree\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\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

473
				$this->listTypeItems[ $item->getDomain() ][ $item->/** @scrutinizer ignore-call */ getCode() ] = $item;
Loading history...
474
			}
475
		}
476
477
		if( !isset( $this->listTypeItems[$domain][$code] ) )
478
		{
479
			$msg = $context->getI18n()->dt( 'controller/frontend', 'List type for domain "%1$s" and code "%2$s" not found' );
480
			throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $domain, $code ) );
481
		}
482
483
		return $this->listTypeItems[$domain][$code];
484
	}
485
486
487
	/**
488
	 * Returns the product variants of a selection product that match the given attributes.
489
	 *
490
	 * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item including sub-products
491
	 * @param array $variantAttributeIds IDs for the variant-building attributes
492
	 * @param array $domains Names of the domain items that should be fetched too
493
	 * @return array List of products matching the given attributes
494
	 */
495
	protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds,
496
			array $domains = array( 'attribute', 'media', 'price', 'text' ) )
497
	{
498
		$subProductIds = [];
499
		foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) {
500
			$subProductIds[] = $item->getId();
501
		}
502
503
		if( count( $subProductIds ) === 0 ) {
504
			return [];
505
		}
506
507
		$productManager = \Aimeos\MShop::create( $this->getContext(), 'product' );
508
		$search = $productManager->createSearch( true );
509
510
		$expr = array(
511
			$search->compare( '==', 'product.id', $subProductIds ),
512
			$search->getConditions(),
513
		);
514
515
		foreach( $variantAttributeIds as $id )
516
		{
517
			$cmpfunc = $search->createFunction( 'product:has', ['attribute', 'variant', (string) $id] );
518
			$expr[] = $search->compare( '!=', $cmpfunc, null );
519
		}
520
521
		$search->setConditions( $search->combine( '&&', $expr ) );
522
523
		return $productManager->searchItems( $search, $domains );
524
	}
525
526
527
	/**
528
	 * Returns the value of an array or the default value if it's not available.
529
	 *
530
	 * @param array $values Associative list of key/value pairs
531
	 * @param string $name Name of the key to return the value for
532
	 * @param mixed $default Default value if no value is available for the given name
533
	 * @return mixed Value from the array or default value
534
	 */
535
	protected function getValue( array $values, $name, $default = null )
536
	{
537
		if( isset( $values[$name] ) ) {
538
			return $values[$name];
539
		}
540
541
		return $default;
542
	}
543
}
544