Completed
Push — feature/filter-visibility ( 937ddc...e06bbd )
by Steven
02:33
created

Products::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Richdynamix\PersonalisedProducts\Model;
4
5
use \Magento\Catalog\Model\ProductFactory as ProductFactory;
6
use \Magento\Catalog\Model\Product\Visibility as Visibility;
7
8
/**
9
 * Loads product collections from predicted product ids
10
 *
11
 * @category  Richdynamix
12
 * @package   PersonalisedProducts
13
 * @author    Steven Richardson ([email protected]) @mage_gizmo
14
 */
15
class Products
16
{
17
    /**
18
     * @var ProductFactory
19
     */
20
    private $_productFactory;
21
22
    /**
23
     * Products constructor.
24
     * @param ProductFactory $productFactory
25
     * @param Visibility $productVisibility
26
     */
27
    public function __construct(ProductFactory $productFactory, Visibility $productVisibility)
0 ignored issues
show
Unused Code introduced by
The parameter $productVisibility is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        $this->_productFactory = $productFactory;
30
    }
31
32
    /**
33
     * We only want to show visible and enabled products.
34
     *
35
     * @param $personalisedIds
36
     * @return $this
37
     */
38
    public function getPersonalisedProductCollection($personalisedIds)
39
    {
40
        $collection = $this->_productFactory->create()->getCollection()
41
            ->addAttributeToFilter('entity_id', ['in', $personalisedIds])
42
            ->addAttributeToFilter('visibility', Visibility::VISIBILITY_BOTH)
43
            ->addAttributeToFilter('status', array('eq' => 1));
44
        return $collection;
45
    }
46
}