29
29
*/
30
30
class StoreWebsiteValidatorCallback extends ArrayValidatorCallback
31
31
{
32
-
33
32
/**
34
33
* The flag to query whether or not the value can be empty.
35
34
*
@@ -61,11 +60,11 @@ class StoreWebsiteValidatorCallback extends ArrayValidatorCallback
61
60
/**
62
61
* Initializes the callback with the loader instance.
63
62
*
64
- * @param \TechDivision\Import\Loaders\ LoaderInterface $storeLoader The loader instance to load the validations with
65
- * @param ImportProcessorInterface $importProcessor The loader instance to load the validations with
66
- * @param boolean $nullable The flag to decide whether or not the value can be empty
67
- * @param boolean $mainRowOnly The flag to decide whether or not the value has to be validated on the main row only
68
- * @param boolean $ignoreStrictMode The flag to query whether or not the value has to be ignored global strict mode configuration.
63
+ * @param LoaderInterface $storeLoader The loader instance to load the validations with
64
+ * @param ImportProcessorInterface $importProcessor The import processor instance
65
+ * @param boolean $nullable The flag to decide whether or not the value can be empty
66
+ * @param boolean $mainRowOnly The flag to decide whether or not the value has to be validated on the main row only
67
+ * @param boolean $ignoreStrictMode The flag to query whether or not the value has to be ignored global strict mode configuration.
69
68
*/
70
69
public function __construct (LoaderInterface $ storeLoader , ImportProcessorInterface $ importProcessor , $ nullable = false , $ mainRowOnly = false , $ ignoreStrictMode = true )
71
70
{
@@ -78,53 +77,44 @@ public function __construct(LoaderInterface $storeLoader, ImportProcessorInterfa
78
77
$ this ->mainRowOnly = $ mainRowOnly ;
79
78
$ this ->ignoreStrictMode = $ ignoreStrictMode ;
80
79
81
- // load the store websites
82
- $ storeWebsites = $ importProcessor ->getStoreWebsites ();
83
-
84
80
// initialize the array with the store websites
85
- foreach ($ storeWebsites as $ storeWebsite ) {
81
+ foreach ($ importProcessor -> getStoreWebsites () as $ storeWebsite ) {
86
82
$ this ->storeWebsites [$ storeWebsite [MemberNames::CODE ]] = $ storeWebsite [MemberNames::WEBSITE_ID ];
87
83
}
88
84
}
89
85
90
86
/**
91
87
* Will be invoked by a observer it has been registered for.
92
88
*
93
- * @param string|null $attributeCode The code of the attribute that has to be validated
89
+ * @param string|null $attributeCode The code of the attribute that has to be validated
94
90
* @param string|null $attributeValue The attribute value to be validated
95
91
*
96
92
* @return mixed The modified value
97
93
*/
98
94
public function handle ($ attributeCode = null , $ attributeValue = null )
99
95
{
100
-
101
- // the validations for the attribute with the given code
102
- $ validations = $ this ->getValidations ($ attributeCode );
103
-
104
96
// query whether or not the passed value IS empty and empty
105
97
// values are allowed
106
98
if ($ this ->isNullable ($ attributeValue )) {
107
99
return ;
108
100
}
109
101
102
+ // the validations for the attribute with the given code
103
+ $ validations = $ this ->getValidations ($ attributeCode );
104
+
110
105
$ website = $ this ->load ();
111
106
$ productWebsite = $ this ->getSubject ()->getValue ('product_websites ' );
112
- $ message = sprintf (
113
- 'The store "%s" does not belong to the website "%s" . Please check your data. ' ,
114
- $ attributeValue ,
115
- $ productWebsite
116
- );
117
107
118
- if ($ validations [$ attributeValue ][MemberNames::WEBSITE_ID ] === $ website [$ productWebsite ]) {
119
- return ;
120
- } else {
121
- if ($ this ->hasHandleStrictMode ($ attributeCode , $ message )) {
122
- return ;
108
+ if ($ validations [$ attributeValue ][MemberNames::WEBSITE_ID ] !== $ website [$ productWebsite ]) {
109
+ $ message = sprintf (
110
+ 'The store "%s" does not belong to the website "%s" . Please check your data. ' ,
111
+ $ attributeValue ,
112
+ $ productWebsite
113
+ );
114
+ if (!$ this ->hasHandleStrictMode ($ attributeCode , $ message )) {
115
+ throw new \InvalidArgumentException ($ message );
123
116
}
124
117
}
125
-
126
- // throw an exception if the store not in Website
127
- throw new \InvalidArgumentException ($ message );
128
118
}
129
119
130
120
/**
0 commit comments