Completed
Push — master ( 52d06b...ee11f0 )
by Aimeos
04:53
created

Index::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 13
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 22
rs 9.8333
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2020
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Common\Decorator;
12
13
14
/**
15
 * Index rebuild decorator for JQAdm clients
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Index extends Base
21
{
22
	/**
23
	 * Rebuilds the index after saving the item
24
	 *
25
	 * @return string|null admin output to display or null for redirecting to the list
26
	 */
27
	public function save() : ?string
28
	{
29
		$result = $this->getClient()->save();
30
		$prodIds = array_unique( array_merge(
31
			$this->getView()->param( 'product/catalog.lists.refid', [] ),
32
			$this->getView()->param( 'product/supplier.lists.refid', [] )
33
		) );
34
35
		if( !empty( $prodIds ) )
36
		{
37
			$context = $this->getContext();
38
			$manager = \Aimeos\MShop::create( $context, 'product' );
39
			$domains = $context->getConfig()->get( 'admin/jqadm/product/domains', [] );
40
41
			$search = $manager->createSearch( true )->setSlice( count( $prodIds ) );
42
			$search->setConditions( $search->compare( '==', 'product.id', $prodIds ) );
43
44
			$items = $manager->searchItems( $search, $domains );
45
			\Aimeos\MShop::create( $context, 'index' )->rebuild( $items->toArray() );
46
		}
47
48
		return $result;
49
	}
50
}
51