|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
6
|
|
|
* @package Client |
|
7
|
|
|
* @subpackage Html |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Basket\Related; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default implementation of related basket HTML client. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Client |
|
18
|
|
|
* @subpackage Html |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Client\Html\Basket\Base |
|
22
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Sets the necessary parameter values in the view. |
|
26
|
|
|
* |
|
27
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
|
28
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
29
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
30
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
|
31
|
|
|
*/ |
|
32
|
|
|
public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
|
33
|
|
|
{ |
|
34
|
|
|
$context = $this->context(); |
|
35
|
|
|
$config = $context->config(); |
|
36
|
|
|
|
|
37
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' ); |
|
38
|
|
|
$basket = \Aimeos\Controller\Frontend::create( $context, 'basket' )->get(); |
|
39
|
|
|
|
|
40
|
|
|
/** client/html/basket/related/bought/limit |
|
41
|
|
|
* Number of items in the list of bought together products |
|
42
|
|
|
* |
|
43
|
|
|
* This option limits the number of suggested products in the |
|
44
|
|
|
* list of bought together products. The suggested items are |
|
45
|
|
|
* calculated using the products that are in the current basket |
|
46
|
|
|
* of the customer. |
|
47
|
|
|
* |
|
48
|
|
|
* Note: You need to start the job controller for calculating |
|
49
|
|
|
* the bought together products regularly to get up to date |
|
50
|
|
|
* product suggestions. |
|
51
|
|
|
* |
|
52
|
|
|
* @param integer Number of products |
|
53
|
|
|
* @since 2014.09 |
|
54
|
|
|
*/ |
|
55
|
|
|
$size = $config->get( 'client/html/basket/related/bought/limit', 6 ); |
|
56
|
|
|
|
|
57
|
|
|
/** client/html/basket/related/bought/domains |
|
58
|
|
|
* The list of domain names whose items should be available in the template for the products |
|
59
|
|
|
* |
|
60
|
|
|
* The templates rendering product details usually add the images, |
|
61
|
|
|
* prices and texts, etc. associated to the product |
|
62
|
|
|
* item. If you want to display additional or less content, you can |
|
63
|
|
|
* configure your own list of domains (attribute, media, price, product, |
|
64
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
|
65
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
|
66
|
|
|
* the more time is required for fetching the content! |
|
67
|
|
|
* |
|
68
|
|
|
* @param array List of domain names |
|
69
|
|
|
* @since 2014.09 |
|
70
|
|
|
* @category Developer |
|
71
|
|
|
*/ |
|
72
|
|
|
$domains = $config->get( 'client/html/basket/related/bought/domains', ['text', 'price', 'media'] ); |
|
73
|
|
|
$domains['product'] = ['bought-together']; |
|
74
|
|
|
|
|
75
|
|
|
/** client/html/basket/related/basket-add |
|
76
|
|
|
* Display the "add to basket" button for each product item |
|
77
|
|
|
* |
|
78
|
|
|
* Enables the button for adding products to the basket for the related products |
|
79
|
|
|
* in the basket. This works for all type of products, even for selection products |
|
80
|
|
|
* with product variants and product bundles. By default, also optional attributes |
|
81
|
|
|
* are displayed if they have been associated to a product. |
|
82
|
|
|
* |
|
83
|
|
|
* @param boolean True to display the button, false to hide it |
|
84
|
|
|
* @since 2020.10 |
|
85
|
|
|
* @see client/html/catalog/home/basket-add |
|
86
|
|
|
* @see client/html/catalog/lists/basket-add |
|
87
|
|
|
* @see client/html/catalog/detail/basket-add |
|
88
|
|
|
* @see client/html/catalog/product/basket-add |
|
89
|
|
|
*/ |
|
90
|
|
|
if( $view->config( 'client/html/basket/related/basket-add', false ) ) { |
|
91
|
|
|
$domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$prodIds = $basket->getProducts() |
|
95
|
|
|
->concat( $basket->getProducts()->getProducts() ) |
|
96
|
|
|
->col( 'order.base.product.parentproductid' ) |
|
97
|
|
|
->unique()->all(); |
|
98
|
|
|
|
|
99
|
|
|
$view->boughtItems = $cntl->uses( $domains )->product( $prodIds )->search() |
|
100
|
|
|
->getListItems( 'product', 'bought-together' ) |
|
101
|
|
|
->flat( 1 ) |
|
102
|
|
|
->usort( function( $a, $b ) { |
|
103
|
|
|
return $a->getPosition() <=> $b->getPosition(); |
|
104
|
|
|
} ) |
|
105
|
|
|
->getRefItem() |
|
106
|
|
|
->filter() |
|
107
|
|
|
->slice( 0, $size ) |
|
108
|
|
|
->col( null, 'product.id' ); |
|
109
|
|
|
|
|
110
|
|
|
return parent::data( $view, $tags, $expire ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** client/html/basket/related/template-body |
|
115
|
|
|
* Relative path to the HTML body template of the basket related client. |
|
116
|
|
|
* |
|
117
|
|
|
* The template file contains the HTML code and processing instructions |
|
118
|
|
|
* to generate the result shown in the body of the frontend. The |
|
119
|
|
|
* configuration string is the path to the template file relative |
|
120
|
|
|
* to the templates directory (usually in client/html/templates). |
|
121
|
|
|
* |
|
122
|
|
|
* You can overwrite the template file configuration in extensions and |
|
123
|
|
|
* provide alternative templates. These alternative templates should be |
|
124
|
|
|
* named like the default one but suffixed by |
|
125
|
|
|
* an unique name. You may use the name of your project for this. If |
|
126
|
|
|
* you've implemented an alternative client class as well, it |
|
127
|
|
|
* should be suffixed by the name of the new class. |
|
128
|
|
|
* |
|
129
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
|
130
|
|
|
* @since 2014.03 |
|
131
|
|
|
* @category Developer |
|
132
|
|
|
* @see client/html/basket/related/template-header |
|
133
|
|
|
*/ |
|
134
|
|
|
|
|
135
|
|
|
/** client/html/basket/related/template-header |
|
136
|
|
|
* Relative path to the HTML header template of the basket related client. |
|
137
|
|
|
* |
|
138
|
|
|
* The template file contains the HTML code and processing instructions |
|
139
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
|
140
|
|
|
* of the rendered page in the frontend. The configuration string is the |
|
141
|
|
|
* path to the template file relative to the templates directory (usually |
|
142
|
|
|
* in client/html/templates). |
|
143
|
|
|
* |
|
144
|
|
|
* You can overwrite the template file configuration in extensions and |
|
145
|
|
|
* provide alternative templates. These alternative templates should be |
|
146
|
|
|
* named like the default one but suffixed by |
|
147
|
|
|
* an unique name. You may use the name of your project for this. If |
|
148
|
|
|
* you've implemented an alternative client class as well, it |
|
149
|
|
|
* should be suffixed by the name of the new class. |
|
150
|
|
|
* |
|
151
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
|
152
|
|
|
* @since 2014.03 |
|
153
|
|
|
* @category Developer |
|
154
|
|
|
* @see client/html/basket/related/template-body |
|
155
|
|
|
*/ |
|
156
|
|
|
} |
|
157
|
|
|
|