|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Ee\Observers\EeProductAttributeObserverTrait |
|
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-ee |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Ee\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Ee\Utils\MemberNames; |
|
24
|
|
|
use TechDivision\Import\Observers\AttributeObserverTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Trait that provides basic EAV attribute functionality for Magento EE. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Tim Wagner <[email protected]> |
|
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
32
|
|
|
* @link https://github.com/techdivision/import-ee |
|
33
|
|
|
* @link http://www.techdivision.com |
|
34
|
|
|
*/ |
|
35
|
|
|
trait EeAttributeObserverTrait |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The attribute observer trait implementation. |
|
40
|
|
|
* |
|
41
|
|
|
* @var \TechDivision\Import\Observers\AttributeObserverTrait |
|
42
|
|
|
*/ |
|
43
|
|
|
use AttributeObserverTrait; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Return's the PK column name to create the product => attribute relation. |
|
47
|
|
|
* |
|
48
|
|
|
* @return string The PK column name |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getPrimaryKeyMemberName() |
|
51
|
|
|
{ |
|
52
|
|
|
return MemberNames::ROW_ID; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return's the PK to create the product => attribute relation. |
|
57
|
|
|
* |
|
58
|
|
|
* @return integer The PK to create the relation with |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function getPrimaryKey() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getLastRowId(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Return's the row ID of the product that has been created recently. |
|
67
|
|
|
* |
|
68
|
|
|
* @return string The row Id |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function getLastRowId() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getSubject()->getLastRowId(); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.