1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2022 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Account\Review; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of account review HTML client. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
22
|
|
|
implements \Aimeos\Client\Html\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
|
|
|
$products = []; |
35
|
|
|
$context = $this->context(); |
36
|
|
|
$config = $context->config(); |
37
|
|
|
|
38
|
|
|
/** client/html/account/review/size |
39
|
|
|
* Maximum number of products shown for review |
40
|
|
|
* |
41
|
|
|
* After customers bought products, they can write a review for those items. |
42
|
|
|
* The products bought last will be displayed first for review and this |
43
|
|
|
* setting limits the number of products shown in the account page. |
44
|
|
|
* |
45
|
|
|
* @param int Number of products |
46
|
|
|
* @since 2020.10 |
47
|
|
|
* @see client/html/account/review/days-after |
48
|
|
|
*/ |
49
|
|
|
$size = $config->get( 'client/html/account/review/size', 10 ); |
50
|
|
|
|
51
|
|
|
/** client/html/account/review/days-after |
52
|
|
|
* Number of days after the product can be reviewed |
53
|
|
|
* |
54
|
|
|
* After customers bought products, they can write a review for those items. |
55
|
|
|
* To avoid fake or revenge reviews, the option for reviewing the products is |
56
|
|
|
* shown after the configured number of days to customers. |
57
|
|
|
* |
58
|
|
|
* @param int Number of days |
59
|
|
|
* @since 2020.10 |
60
|
|
|
* @see client/html/account/review/size |
61
|
|
|
*/ |
62
|
|
|
$days = $config->get( 'client/html/account/review/days-after', 0 ); |
63
|
|
|
|
64
|
|
|
$orders = \Aimeos\Controller\Frontend::create( $context, 'order' ) |
65
|
|
|
->compare( '>', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_PENDING ) |
66
|
|
|
->compare( '<', 'order.base.ctime', date( 'Y-m-d H:i:s', time() - $days * 86400 ) ) |
67
|
|
|
->uses( ['order/base', 'order/base/product'] ) |
68
|
|
|
->sort( '-order.base.ctime' ) |
69
|
|
|
->slice( 0, $size ) |
70
|
|
|
->search(); |
71
|
|
|
|
72
|
|
|
$prodMap = $orders->getBaseItem()->getProducts()->flat() |
73
|
|
|
->col( 'order.base.product.id', 'order.base.product.productid' ); |
74
|
|
|
|
75
|
|
|
$exclude = \Aimeos\Controller\Frontend::create( $context, 'review' ) |
76
|
|
|
->for( 'product', $prodMap->keys()->toArray() ) |
77
|
|
|
->slice( 0, $prodMap->count() ) |
78
|
|
|
->list()->getRefId(); |
79
|
|
|
|
80
|
|
|
if( ( $prodIds = $prodMap->keys()->diff( $exclude )->toArray() ) !== [] ) |
81
|
|
|
{ |
82
|
|
|
$productItems = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
83
|
|
|
->uses( ['text' => ['name'], 'media' => ['default']] ) |
84
|
|
|
->product( $prodIds ) |
85
|
|
|
->search(); |
86
|
|
|
|
87
|
|
|
foreach( $prodMap as $prodId => $ordProdId ) |
88
|
|
|
{ |
89
|
|
|
if( $item = $productItems->get( $prodId ) ) { |
90
|
|
|
$products[$prodId] = $item->set( 'orderProductId', $ordProdId ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$view->reviewProductItems = map( $products )->filter()->take( $size ); |
96
|
|
|
|
97
|
|
|
return parent::data( $view, $tags, $expire ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Processes the input, e.g. store given values. |
103
|
|
|
* |
104
|
|
|
* A view must be available and this method doesn't generate any output |
105
|
|
|
* besides setting view variables if necessary. |
106
|
|
|
*/ |
107
|
|
|
public function init() |
108
|
|
|
{ |
109
|
|
|
$view = $this->view(); |
110
|
|
|
|
111
|
|
|
if( ( $reviews = $view->param( 'review', [] ) ) !== [] ) |
112
|
|
|
{ |
113
|
|
|
$context = $this->context(); |
114
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $context, 'review' ); |
115
|
|
|
$addr = \Aimeos\Controller\Frontend::create( $context, 'customer' )->get()->getPaymentAddress(); |
116
|
|
|
|
117
|
|
|
foreach( $reviews as $values ) { |
118
|
|
|
$cntl->save( $cntl->create( $values )->setDomain( 'product' )->setName( $addr->getFirstName() ) ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$view->reviewInfoList = [$view->translate( 'client', 'Thank you for your review!' )]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
parent::init(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** client/html/account/review/template-body |
129
|
|
|
* Relative path to the HTML body template of the account review client. |
130
|
|
|
* |
131
|
|
|
* The template file contains the HTML code and processing instructions |
132
|
|
|
* to generate the result shown in the body of the frontend. The |
133
|
|
|
* configuration string is the path to the template file relative |
134
|
|
|
* to the templates directory (usually in client/html/templates). |
135
|
|
|
* |
136
|
|
|
* You can overwrite the template file configuration in extensions and |
137
|
|
|
* provide alternative templates. These alternative templates should be |
138
|
|
|
* named like the default one but suffixed by |
139
|
|
|
* an unique name. You may use the name of your project for this. If |
140
|
|
|
* you've implemented an alternative client class as well, it |
141
|
|
|
* should be suffixed by the name of the new class. |
142
|
|
|
* |
143
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
144
|
|
|
* @since 2020.10 |
145
|
|
|
* @category Developer |
146
|
|
|
* @see client/html/account/review/template-header |
147
|
|
|
*/ |
148
|
|
|
|
149
|
|
|
/** client/html/account/review/template-header |
150
|
|
|
* Relative path to the HTML header template of the account review client. |
151
|
|
|
* |
152
|
|
|
* The template file contains the HTML code and processing instructions |
153
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
154
|
|
|
* of the rendered page in the frontend. The configuration string is the |
155
|
|
|
* path to the template file relative to the templates directory (usually |
156
|
|
|
* in client/html/templates). |
157
|
|
|
* |
158
|
|
|
* You can overwrite the template file configuration in extensions and |
159
|
|
|
* provide alternative templates. These alternative templates should be |
160
|
|
|
* named like the default one but suffixed by |
161
|
|
|
* an unique name. You may use the name of your project for this. If |
162
|
|
|
* you've implemented an alternative client class as well, it |
163
|
|
|
* should be suffixed by the name of the new class. |
164
|
|
|
* |
165
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
166
|
|
|
* @since 2020.10 |
167
|
|
|
* @category Developer |
168
|
|
|
* @see client/html/account/review/template-body |
169
|
|
|
*/ |
170
|
|
|
} |
171
|
|
|
|