1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository |
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-attribute |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Repositories; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Utils\MemberNames; |
24
|
|
|
use TechDivision\Import\Attribute\Utils\SqlStatementKeys; |
25
|
|
|
use TechDivision\Import\Repositories\AbstractRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Repository implementation to load EAV attribute option swatch 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-attribute |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class AttributeOptionSwatchRepository extends AbstractRepository implements AttributeOptionSwatchRepositoryInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The prepared statement to load an existing EAV attribute option swatch by its option ID and store ID |
41
|
|
|
* |
42
|
|
|
* @var \PDOStatement |
43
|
|
|
*/ |
44
|
|
|
protected $attributeOptionSwatchByOptionIdAndStoreIdStmt; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The prepared statement to load an existing EAV attribute option swatch by its attribute code, store ID. value and type. |
48
|
|
|
* |
49
|
|
|
* @var \PDOStatement |
50
|
|
|
*/ |
51
|
|
|
protected $attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt; |
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->attributeOptionSwatchByOptionIdAndStoreIdStmt = |
63
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_OPTION_ID_AND_STORE_ID)); |
64
|
|
|
|
65
|
|
|
// initialize the prepared statements |
66
|
|
|
$this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt = |
67
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Load's and return's the EAV attribute option swatch with the passed option ID and store ID |
72
|
|
|
* |
73
|
|
|
* @param string $optionId The option ID of the attribute option swatch to load |
74
|
|
|
* @param integer $storeId The store ID of the attribute option swatch to load |
75
|
|
|
* |
76
|
|
|
* @return array The EAV attribute option swatch |
77
|
|
|
*/ |
78
|
|
|
public function findOneByOptionIdAndStoreId($optionId, $storeId) |
79
|
|
|
{ |
80
|
|
|
|
81
|
|
|
// the parameters of the EAV attribute option to load |
82
|
|
|
$params = array( |
83
|
|
|
MemberNames::OPTION_ID => $optionId, |
84
|
|
|
MemberNames::STORE_ID => $storeId, |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
// load and return the EAV attribute option swatch with the passed parameters |
88
|
|
|
$this->attributeOptionSwatchByOptionIdAndStoreIdStmt->execute($params); |
89
|
|
|
return $this->attributeOptionSwatchByOptionIdAndStoreIdStmt->fetch(\PDO::FETCH_ASSOC); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Load's and return's the EAV attribute option swatch with the passed entity type ID, code, store ID, value and type. |
94
|
|
|
* |
95
|
|
|
* @param string $entityTypeId The entity type ID of the EAV attribute to load the option swatch for |
96
|
|
|
* @param string $attributeCode The code of the EAV attribute option swatch to load |
97
|
|
|
* @param integer $storeId The store ID of the attribute option swatch to load |
98
|
|
|
* @param string $value The value of the attribute option swatch to load |
99
|
|
|
* @param string $type The type of the attribute option swatch to load |
100
|
|
|
* |
101
|
|
|
* @return array The EAV attribute option swatch |
102
|
|
|
*/ |
103
|
|
View Code Duplication |
public function findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId, $attributeCode, $storeId, $value, $type) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
|
106
|
|
|
// the parameters of the EAV attribute option to load |
107
|
|
|
$params = array( |
108
|
|
|
MemberNames::ENTITY_TYPE_ID => $entityTypeId, |
109
|
|
|
MemberNames::ATTRIBUTE_CODE => $attributeCode, |
110
|
|
|
MemberNames::STORE_ID => $storeId, |
111
|
|
|
MemberNames::VALUE => $value, |
112
|
|
|
MemberNames::TYPE => $type |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
// load and return the EAV attribute option swatch with the passed parameters |
116
|
|
|
$this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt->execute($params); |
117
|
|
|
return $this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt->fetch(\PDO::FETCH_ASSOC); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.