Completed
Pull Request — master (#1)
by
unknown
14:19
created

ProductImage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 3
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _construct() 0 4 1
A imageExists() 0 9 1
A getProcessedEans() 0 9 1
1
<?php
2
3
namespace Stockbase\Integration\Model\ResourceModel;
4
5
/**
6
 * Class StockItem
7
 * @package Stockbase\Integration\Model\ResourceModel
8
 */
9
class ProductImage extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
10
{
11
12
    /**
13
     * @var \Magento\Framework\EntityManager\EntityManager
14
     */
15
    protected $entityManager;
16
17
    /**
18
     * Constructor.
19
     */
20
    protected function _construct()
21
    {
22
        $this->_init('stockbase_product_images', 'id');
23
    }
24
25
    /**
26
     * @param $imageName
27
     * @param $productId
28
     * @param $ean
29
     * @return mixed
30
     */
31
    public function imageExists($imageName, $productId, $ean)
32
    {
33
        $connection = $this->getConnection();
34
        $query = $connection->select()
35
            ->from(['s' => $this->getMainTable()], ['s.ean'])
36
            ->where('s.image = \''.$imageName.'\' AND s.product_id = '.$productId.' AND s.ean=\''.$ean.'\'');
37
        $eans = $connection->fetchAll($query);
38
        return $eans;
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function getProcessedEans()
45
    {
46
        $connection = $this->getConnection();
47
        $query = $connection->select()
48
            ->from(['s' => $this->getMainTable()], ['s.ean'])
49
            ->group('s.ean');
50
        $eans = $connection->fetchAll($query);
51
        return $eans;
52
    }
53
54
}
55