1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Repositories\ProductWebsiteRepository |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-product |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Repositories; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Utils\MemberNames; |
24
|
|
|
use TechDivision\Import\Product\Utils\SqlStatementKeys; |
25
|
|
|
use TechDivision\Import\Repositories\AbstractRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Repository implementation to load product website data. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import-product |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class ProductWebsiteRepository extends AbstractRepository implements ProductWebsiteRepositoryInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The prepared statement to load the existing product website relations. |
41
|
|
|
* |
42
|
|
|
* @var \PDOStatement |
43
|
|
|
*/ |
44
|
|
|
protected $productWebsiteStmt; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The prepared statement to load the existing product website relations for the given SKU. |
48
|
|
|
* |
49
|
|
|
* @var \PDOStatement |
50
|
|
|
*/ |
51
|
|
|
protected $productWebsitesBySkuStmt; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Initializes the repository's prepared statements. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function init() |
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
// initialize the prepared statements |
62
|
|
|
$this->productWebsiteStmt = |
63
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::PRODUCT_WEBSITE)); |
64
|
|
|
$this->productWebsitesBySkuStmt = |
65
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::PRODUCT_WEBSITES_BY_SKU)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Load's and return's the product website relations for the product with the passed SKU. |
70
|
|
|
* |
71
|
|
|
* @param string $sku The SKU to of the product to load the product website relations for |
72
|
|
|
* |
73
|
|
|
* @return array The product website relations |
74
|
|
|
*/ |
75
|
|
|
public function findAllBySku($sku) |
76
|
|
|
{ |
77
|
|
|
|
78
|
|
|
// prepare the params |
79
|
|
|
$params = array(MemberNames::SKU => $sku); |
80
|
|
|
|
81
|
|
|
// load and return the product with the passed product/website ID |
82
|
|
|
$this->productWebsitesBySkuStmt->execute($params); |
83
|
|
|
return $this->productWebsitesBySkuStmt->fetchAll(\PDO::FETCH_ASSOC); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Load's and return's the product website relation with the passed product and website ID. |
88
|
|
|
* |
89
|
|
|
* @param string $productId The product ID of the relation |
90
|
|
|
* @param string $websiteId The website ID of the relation |
91
|
|
|
* |
92
|
|
|
* @return array The product website |
93
|
|
|
*/ |
94
|
|
|
public function findOneByProductIdAndWebsite($productId, $websiteId) |
95
|
|
|
{ |
96
|
|
|
|
97
|
|
|
// prepare the params |
98
|
|
|
$params = array( |
99
|
|
|
MemberNames::PRODUCT_ID => $productId, |
100
|
|
|
MemberNames::WEBSITE_ID => $websiteId |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
// load and return the product with the passed product/website ID |
104
|
|
|
$this->productWebsiteStmt->execute($params); |
105
|
|
|
return $this->productWebsiteStmt->fetch(\PDO::FETCH_ASSOC); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|