Version Notes
Please refer User and Installation guide
Download this release
Release Info
Developer | Magento Core Team |
Extension | Mavenstore_Customoptionproductimport |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- app/code/local/Maven/AdvanceImport/Model/Convert/Adapter/Abstract.php +407 -0
- app/code/local/Maven/AdvanceImport/Model/Convert/Adapter/Configurableimport.php +104 -0
- app/code/local/Maven/AdvanceImport/Model/Product.php +10 -0
- app/code/local/Maven/AdvanceImport/etc/config.xml +50 -0
- app/etc/modules/Maven_AdvanceImport.xml +9 -0
- package.xml +27 -0
app/code/local/Maven/AdvanceImport/Model/Convert/Adapter/Abstract.php
ADDED
@@ -0,0 +1,407 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Maven_AdvanceImport_Model_Convert_Adapter_Abstract
|
3 |
+
extends Mage_Catalog_Model_Convert_Adapter_Product
|
4 |
+
{
|
5 |
+
|
6 |
+
public function getProductModel()
|
7 |
+
{
|
8 |
+
|
9 |
+
if (is_null($this->_productModel)) {
|
10 |
+
$productModel = Mage::getModel('advanceimport/product');
|
11 |
+
$this->_productModel = Mage::objects()->save($productModel);
|
12 |
+
}
|
13 |
+
return Mage::objects()->load($this->_productModel);
|
14 |
+
}
|
15 |
+
|
16 |
+
public function saveRow(array $importData)
|
17 |
+
{
|
18 |
+
$product = $this->getProductModel()
|
19 |
+
->reset();
|
20 |
+
|
21 |
+
if (empty($importData['store'])) {
|
22 |
+
if (!is_null($this->getBatchParams('store'))) {
|
23 |
+
$store = $this->getStoreById($this->getBatchParams('store'));
|
24 |
+
} else {
|
25 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store');
|
26 |
+
Mage::throwException($message);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
else {
|
30 |
+
$store = $this->getStoreByCode($importData['store']);
|
31 |
+
}
|
32 |
+
|
33 |
+
if ($store === false) {
|
34 |
+
$message = Mage::helper('catalog')->__('Skip import row, store "%s" field not exists', $importData['store']);
|
35 |
+
Mage::throwException($message);
|
36 |
+
}
|
37 |
+
|
38 |
+
if (empty($importData['sku'])) {
|
39 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku');
|
40 |
+
Mage::throwException($message);
|
41 |
+
}
|
42 |
+
$product->setStoreId($store->getId());
|
43 |
+
$productId = $product->getIdBySku($importData['sku']);
|
44 |
+
|
45 |
+
if ($productId) {
|
46 |
+
$product->load($productId);
|
47 |
+
}
|
48 |
+
else {
|
49 |
+
$productTypes = $this->getProductTypes();
|
50 |
+
$productAttributeSets = $this->getProductAttributeSets();
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Check product define type
|
54 |
+
*/
|
55 |
+
if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
|
56 |
+
$value = isset($importData['type']) ? $importData['type'] : '';
|
57 |
+
$message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'type');
|
58 |
+
Mage::throwException($message);
|
59 |
+
}
|
60 |
+
$product->setTypeId($productTypes[strtolower($importData['type'])]);
|
61 |
+
/**
|
62 |
+
* Check product define attribute set
|
63 |
+
*/
|
64 |
+
if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
|
65 |
+
$value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
|
66 |
+
$message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'attribute_set');
|
67 |
+
Mage::throwException($message);
|
68 |
+
}
|
69 |
+
$product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]);
|
70 |
+
|
71 |
+
foreach ($this->_requiredFields as $field) {
|
72 |
+
$attribute = $this->getAttribute($field);
|
73 |
+
if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) {
|
74 |
+
$message = Mage::helper('catalog')->__('Skip import row, required field "%s" for new products not defined', $field);
|
75 |
+
Mage::throwException($message);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
$this->setProductTypeInstance($product);
|
81 |
+
|
82 |
+
/* Maven Configurable Product Import Function */
|
83 |
+
|
84 |
+
$configurableImport = $this->getImportType('configurable');
|
85 |
+
if(!is_object($configurableImport)){
|
86 |
+
//echo 'Class Not Found';
|
87 |
+
}else{
|
88 |
+
$configurableImport->import($importData,$product);
|
89 |
+
}
|
90 |
+
|
91 |
+
/* Maven Configurable Product Import Function */
|
92 |
+
|
93 |
+
/* Maven Related Products Import Function */
|
94 |
+
|
95 |
+
$relatedImport = $this->getImportType('related');
|
96 |
+
if(!is_object($relatedImport)){
|
97 |
+
//echo 'Related Class Not Found';
|
98 |
+
}else{
|
99 |
+
$relatedImport->import($importData,$product);
|
100 |
+
}
|
101 |
+
/* Maven Related Products Import Function */
|
102 |
+
/* Maven Upsell Products Import Function */
|
103 |
+
|
104 |
+
$upsellImport = $this->getImportType('upsell');
|
105 |
+
if(!is_object($upsellImport)){
|
106 |
+
//echo 'Upsell Class Not Found';
|
107 |
+
}else{
|
108 |
+
$upsellImport->import($importData,$product);
|
109 |
+
}
|
110 |
+
/* Maven Upsell Products Import Function */
|
111 |
+
/* Maven crosssell Products Import Function */
|
112 |
+
|
113 |
+
$crosssellImport = $this->getImportType('crosssell');
|
114 |
+
if(!is_object($crosssellImport)){
|
115 |
+
//echo 'Crosssell Class Not Found';
|
116 |
+
}else{
|
117 |
+
$crosssellImport->import($importData,$product);
|
118 |
+
}
|
119 |
+
/* Maven crosssell Products Import Function */
|
120 |
+
/* Maven grouped Products Import Function */
|
121 |
+
|
122 |
+
$groupedImport = $this->getImportType('grouped');
|
123 |
+
if(!is_object($groupedImport)){
|
124 |
+
//echo 'grouped Class Not Found';
|
125 |
+
}else{
|
126 |
+
$groupedImport->import($importData,$product);
|
127 |
+
}
|
128 |
+
/* Maven grouped Products Import Function */
|
129 |
+
/* Maven tierprice Products Import Function */
|
130 |
+
|
131 |
+
$tierpriceImport = $this->getImportType('tierprice');
|
132 |
+
|
133 |
+
if(!is_object($tierpriceImport)){
|
134 |
+
//echo 'tierprice Class Not Found';
|
135 |
+
}else{
|
136 |
+
$tierpriceImport->import($importData,$product);
|
137 |
+
}
|
138 |
+
|
139 |
+
/* Maven tierprice Products Import Function */
|
140 |
+
|
141 |
+
$gallaryImport = $this->getImportType('imagegallery');
|
142 |
+
|
143 |
+
if(!is_object($gallaryImport))
|
144 |
+
{
|
145 |
+
|
146 |
+
}
|
147 |
+
else
|
148 |
+
{
|
149 |
+
$gallaryImport->import($importData,$product);
|
150 |
+
}
|
151 |
+
|
152 |
+
if (isset($importData['category_ids'])) {
|
153 |
+
$product->setCategoryIds($importData['category_ids']);
|
154 |
+
}
|
155 |
+
|
156 |
+
foreach ($this->_ignoreFields as $field) {
|
157 |
+
if (isset($importData[$field])) {
|
158 |
+
unset($importData[$field]);
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
if ($store->getId() != 0) {
|
163 |
+
$websiteIds = $product->getWebsiteIds();
|
164 |
+
if (!is_array($websiteIds)) {
|
165 |
+
$websiteIds = array();
|
166 |
+
}
|
167 |
+
if (!in_array($store->getWebsiteId(), $websiteIds)) {
|
168 |
+
$websiteIds[] = $store->getWebsiteId();
|
169 |
+
}
|
170 |
+
$product->setWebsiteIds($websiteIds);
|
171 |
+
}
|
172 |
+
|
173 |
+
if (isset($importData['websites'])) {
|
174 |
+
$websiteIds = $product->getWebsiteIds();
|
175 |
+
if (!is_array($websiteIds)) {
|
176 |
+
$websiteIds = array();
|
177 |
+
}
|
178 |
+
$websiteCodes = explode(',', $importData['websites']);
|
179 |
+
foreach ($websiteCodes as $websiteCode) {
|
180 |
+
try {
|
181 |
+
$website = Mage::app()->getWebsite(trim($websiteCode));
|
182 |
+
if (!in_array($website->getId(), $websiteIds)) {
|
183 |
+
$websiteIds[] = $website->getId();
|
184 |
+
}
|
185 |
+
}
|
186 |
+
catch (Exception $e) {}
|
187 |
+
}
|
188 |
+
$product->setWebsiteIds($websiteIds);
|
189 |
+
unset($websiteIds);
|
190 |
+
}
|
191 |
+
$custom_options = array();
|
192 |
+
$bundle_options = array();
|
193 |
+
$bundle_selections = array();
|
194 |
+
//$iii=0;
|
195 |
+
$i=0;
|
196 |
+
$j=0;
|
197 |
+
foreach ($importData as $field => $value) {
|
198 |
+
if (in_array($field, $this->_inventoryFields)) {
|
199 |
+
continue;
|
200 |
+
}
|
201 |
+
if (in_array($field, $this->_imageFields)) {
|
202 |
+
continue;
|
203 |
+
}
|
204 |
+
$attribute = $this->getAttribute($field);
|
205 |
+
if (!$attribute) {
|
206 |
+
if(strpos($field,'$')!==FALSE && strlen($value))
|
207 |
+
{
|
208 |
+
$CO_BI = explode('$',$field );
|
209 |
+
if(strtolower($CO_BI[0])=='co')
|
210 |
+
{
|
211 |
+
/* Maven Product Custom Option Import Function */
|
212 |
+
$customoptionImport = $this->getImportType('customoption');
|
213 |
+
if(!is_object($customoptionImport)){
|
214 |
+
//echo 'CustomOption Class Not Found';
|
215 |
+
}else{
|
216 |
+
$custom_options[] = $customoptionImport->import($importData,$product,$field,$value);
|
217 |
+
}
|
218 |
+
/* Maven Product Custom Option Import Function */
|
219 |
+
}
|
220 |
+
|
221 |
+
if(strtolower($CO_BI[0])=='bi')
|
222 |
+
{
|
223 |
+
$bundleImport = $this->getImportType('bundle');
|
224 |
+
if(!is_object($bundleImport)){
|
225 |
+
//echo 'Bundle Class Not Found';
|
226 |
+
}else{
|
227 |
+
$returnArray[] = $bundleImport->import($importData,$product,$field,$value,$i);
|
228 |
+
$lastArray = end($returnArray);
|
229 |
+
//print_r($lastArray);
|
230 |
+
foreach($lastArray as $key1=>$value1)
|
231 |
+
{
|
232 |
+
if($key1 == 'bundle_options'){
|
233 |
+
foreach($value1 as $k1=>$v1)
|
234 |
+
{
|
235 |
+
$bundle_options_array[] = $v1;
|
236 |
+
}
|
237 |
+
|
238 |
+
}
|
239 |
+
if($key1 == 'bundle_selections'){
|
240 |
+
foreach($value1 as $k2=>$v2)
|
241 |
+
{
|
242 |
+
$bundle_selections_array[] = $v2;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
}
|
247 |
+
$product->setBundleOptionsData($bundle_options_array);
|
248 |
+
$product->setBundleSelectionsData($bundle_selections_array);
|
249 |
+
$product->setCanSaveCustomOptions(true);
|
250 |
+
$product->setCanSaveBundleSelections(true);
|
251 |
+
$i++;
|
252 |
+
}
|
253 |
+
}
|
254 |
+
}
|
255 |
+
continue;
|
256 |
+
}
|
257 |
+
$isArray = false;
|
258 |
+
$setValue = $value;
|
259 |
+
if ($attribute->getFrontendInput() == 'multiselect') {
|
260 |
+
$value = explode(self::MULTI_DELIMITER, $value);
|
261 |
+
$isArray = true;
|
262 |
+
$setValue = array();
|
263 |
+
}
|
264 |
+
if ($value && $attribute->getBackendType() == 'decimal') {
|
265 |
+
$setValue = $this->getNumber($value);
|
266 |
+
}
|
267 |
+
if ($attribute->usesSource())
|
268 |
+
{
|
269 |
+
$options = $attribute->getSource()->getAllOptions(false);
|
270 |
+
if ($isArray) {
|
271 |
+
foreach ($options as $item) {
|
272 |
+
if (in_array($item['label'], $value)) {
|
273 |
+
$setValue[] = $item['value'];
|
274 |
+
}
|
275 |
+
}
|
276 |
+
} else {
|
277 |
+
$setValue = false;
|
278 |
+
foreach ($options as $item) {
|
279 |
+
if ($item['label'] == $value) {
|
280 |
+
$setValue = $item['value'];
|
281 |
+
}
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}
|
285 |
+
$product->setData($field, $setValue);
|
286 |
+
$j++;
|
287 |
+
}
|
288 |
+
|
289 |
+
|
290 |
+
if (!$product->getVisibility()) {
|
291 |
+
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
|
292 |
+
}
|
293 |
+
|
294 |
+
$stockData = array();
|
295 |
+
$inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()])
|
296 |
+
? $this->_inventoryFieldsProductTypes[$product->getTypeId()]
|
297 |
+
: array();
|
298 |
+
foreach ($inventoryFields as $field) {
|
299 |
+
if (isset($importData[$field])) {
|
300 |
+
if (in_array($field, $this->_toNumber)) {
|
301 |
+
$stockData[$field] = $this->getNumber($importData[$field]);
|
302 |
+
}
|
303 |
+
else {
|
304 |
+
$stockData[$field] = $importData[$field];
|
305 |
+
}
|
306 |
+
}
|
307 |
+
}
|
308 |
+
$product->setStockData($stockData);
|
309 |
+
|
310 |
+
$imageData = array();
|
311 |
+
foreach ($this->_imageFields as $field) {
|
312 |
+
if (!empty($importData[$field]) && $importData[$field] != 'no_selection') {
|
313 |
+
if (!isset($imageData[$importData[$field]])) {
|
314 |
+
$imageData[$importData[$field]] = array();
|
315 |
+
}
|
316 |
+
$imageData[$importData[$field]][] = $field;
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
foreach ($imageData as $file => $fields) {
|
321 |
+
try {
|
322 |
+
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields);
|
323 |
+
}
|
324 |
+
catch (Exception $e) {}
|
325 |
+
}
|
326 |
+
|
327 |
+
$product->setIsMassupdate(true);
|
328 |
+
$product->setExcludeUrlRewrite(true);
|
329 |
+
$product->save();
|
330 |
+
$customoptionImport = $this->getImportType('customoption');
|
331 |
+
if(!is_object($customoptionImport)){
|
332 |
+
//echo 'CustomOption Class Not Found';
|
333 |
+
}else{
|
334 |
+
$customoptionImport->saveCustomOption($product,$custom_options);
|
335 |
+
}
|
336 |
+
return true;
|
337 |
+
}
|
338 |
+
|
339 |
+
|
340 |
+
|
341 |
+
|
342 |
+
public function getImportType($code)
|
343 |
+
{
|
344 |
+
$importType = Mage::getConfig()->getNode('global/advanceimport/importtype');
|
345 |
+
foreach($importType->children() as $key=>$value)
|
346 |
+
{
|
347 |
+
if($code == $key)
|
348 |
+
{
|
349 |
+
$class = $value->getClassName();
|
350 |
+
if ($class && ($model = Mage::getModel($class))) {
|
351 |
+
return $model;
|
352 |
+
}else{
|
353 |
+
false;
|
354 |
+
}
|
355 |
+
}
|
356 |
+
}
|
357 |
+
return false;
|
358 |
+
}
|
359 |
+
|
360 |
+
protected function skusToIds($userData,$product) {
|
361 |
+
$productIds = array();
|
362 |
+
foreach ($this->userCSVDataAsArray($userData) as $oneSku) {
|
363 |
+
if (($a_sku = (int)$product->getIdBySku($oneSku)) > 0) {
|
364 |
+
parse_str("position=", $productIds[$a_sku]);
|
365 |
+
}
|
366 |
+
}
|
367 |
+
return $productIds;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Silently save product (import)
|
372 |
+
*
|
373 |
+
* @param array $
|
374 |
+
* @return bool
|
375 |
+
*/
|
376 |
+
public function saveRowSilently(array $importData)
|
377 |
+
{
|
378 |
+
try {
|
379 |
+
$result = $this->saveRow($importData);
|
380 |
+
return $result;
|
381 |
+
}
|
382 |
+
catch (Exception $e) {
|
383 |
+
return false;
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Process after import data
|
389 |
+
* Init indexing process after catalog product import
|
390 |
+
*
|
391 |
+
*/
|
392 |
+
public function finish()
|
393 |
+
{
|
394 |
+
/**
|
395 |
+
* Back compatibility event
|
396 |
+
*/
|
397 |
+
Mage::dispatchEvent('catalog_product_import_after', array());
|
398 |
+
|
399 |
+
$entity = new Varien_Object();
|
400 |
+
Mage::getSingleton('index/indexer')->processEntityAction(
|
401 |
+
$entity, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
|
402 |
+
);
|
403 |
+
}
|
404 |
+
protected function userCSVDataAsArray($data) {
|
405 |
+
return explode(',', str_replace(" ", "", $data));
|
406 |
+
}
|
407 |
+
}
|
app/code/local/Maven/AdvanceImport/Model/Convert/Adapter/Configurableimport.php
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Maven_AdvanceImport_Model_Convert_Adapter_Configurableimport
|
3 |
+
extends Maven_AdvanceImport_Model_Convert_Adapter_Abstract
|
4 |
+
{
|
5 |
+
public function import($importData,$product)
|
6 |
+
{
|
7 |
+
if ($importData['type'] == 'configurable')
|
8 |
+
{
|
9 |
+
$product->setCanSaveConfigurableAttributes(true);
|
10 |
+
if(isset($importData['config_attributes']) && !empty($importData['config_attributes']))
|
11 |
+
{
|
12 |
+
$configAttributeCodes = $this->userCSVDataAsArray($importData['config_attributes']);
|
13 |
+
$usingAttributeIds = array();
|
14 |
+
|
15 |
+
//Check the product's super attributes (see catalog_product_super_attribute table), and make a determination that way.
|
16 |
+
|
17 |
+
$cspa = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
|
18 |
+
$attr_codes = array();
|
19 |
+
if(isset($cspa) && !empty($cspa)){ //found attributes
|
20 |
+
foreach($cspa as $cs_attr){
|
21 |
+
//$attr_codes[$cs_attr['attribute_id']] = $cs_attr['attribute_code'];
|
22 |
+
$attr_codes[] = $cs_attr['attribute_id'];
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
foreach($configAttributeCodes as $attributeCode)
|
28 |
+
{
|
29 |
+
$attribute = $product->getResource()->getAttribute($attributeCode);
|
30 |
+
if ($product->getTypeInstance()->canUseAttribute($attribute)) {
|
31 |
+
if (!in_array($attributeCode,$attr_codes)) { // fix for duplicating attributes error
|
32 |
+
$usingAttributeIds[] = $attribute->getAttributeId();
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
if (!empty($usingAttributeIds))
|
38 |
+
{
|
39 |
+
$product->getTypeInstance()->setUsedProductAttributeIds($usingAttributeIds);
|
40 |
+
//$product->setConfigurableAttributesData($product->getTypeInstance()->getConfigurableAttributesAsArray());
|
41 |
+
|
42 |
+
//The label MUST be set or we'll get a MySQL error
|
43 |
+
$configurableAttributesArray = $product->getTypeInstance()->getConfigurableAttributesAsArray();
|
44 |
+
|
45 |
+
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
|
46 |
+
|
47 |
+
|
48 |
+
foreach($configurableAttributesArray as &$configurableAttributeArray)
|
49 |
+
{
|
50 |
+
//Set a number of default values
|
51 |
+
$configurableAttributeArray['use_default'] = 1;
|
52 |
+
$configurableAttributeArray['position'] = 0;
|
53 |
+
|
54 |
+
/// code for value array
|
55 |
+
$attr_code = $configurableAttributeArray['attribute_code'];
|
56 |
+
|
57 |
+
$value_index = $this->userCSVDataAsArray($importData['config_code-is_per-'.$attr_code]);
|
58 |
+
$j = 0;
|
59 |
+
for($i=0;$i<count($value_index);$i++)
|
60 |
+
{
|
61 |
+
$mix = explode(':',$value_index[$i]);
|
62 |
+
if(isset($mix) && !empty($mix))
|
63 |
+
{
|
64 |
+
$select = $read->select()
|
65 |
+
->distinct()
|
66 |
+
->from('eav_attribute_option_value',array('option_id','value'))
|
67 |
+
->where('value =?',$mix[0]);
|
68 |
+
$optionArr = $read->fetchRow($select);
|
69 |
+
if(isset($optionArr) && !empty($optionArr))
|
70 |
+
{
|
71 |
+
//$data['values'][$i]['label'] = ;
|
72 |
+
$data[$i]['attribute_id'] = (int)$configurableAttributeArray["attribute_id"];
|
73 |
+
$data[$i]['value_index'] = $optionArr['option_id'];
|
74 |
+
$data[$i]['is_percent'] = $mix[1];
|
75 |
+
$data[$i]['pricing_value'] = $mix[2];
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
$dataArr[$j] = $data;
|
80 |
+
$configurableAttributeArray['values'] = $dataArr[$j];
|
81 |
+
$j++;
|
82 |
+
// End code for values Array Creation
|
83 |
+
|
84 |
+
//Use the frontend_label as label, if available
|
85 |
+
if(isset($configurableAttributeArray['frontend_label'])){
|
86 |
+
$configurableAttributeArray['label'] = $configurableAttributeArray['frontend_label'];
|
87 |
+
continue;
|
88 |
+
}
|
89 |
+
//Use the attribute_code as a label
|
90 |
+
$configurableAttributeArray['label'] = $configurableAttributeArray['attribute_code'];
|
91 |
+
}
|
92 |
+
|
93 |
+
$product->setConfigurableAttributesData($configurableAttributesArray);
|
94 |
+
$product->setCanSaveConfigurableAttributes(true);
|
95 |
+
$product->setCanSaveCustomOptions(true);
|
96 |
+
}
|
97 |
+
if (isset($importData['associated'])) {
|
98 |
+
$product->setConfigurableProductsData($this->skusToIds($importData['associated'], $product));
|
99 |
+
}
|
100 |
+
}
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
?>
|
app/code/local/Maven/AdvanceImport/Model/Product.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Maven_AdvanceImport_Model_Product extends Mage_Catalog_Model_Product
|
3 |
+
{
|
4 |
+
|
5 |
+
protected function _beforeSave()
|
6 |
+
{
|
7 |
+
parent::_beforeSave();
|
8 |
+
$this->setHasOptions(true);
|
9 |
+
}
|
10 |
+
}
|
app/code/local/Maven/AdvanceImport/etc/config.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Maven_AdvanceImport>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</Maven_AdvanceImport>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<advanceimport>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>Maven_AdvanceImport</module>
|
14 |
+
<frontName>advanceimport</frontName>
|
15 |
+
</args>
|
16 |
+
</advanceimport>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<advanceimport>
|
21 |
+
<file>advanceimport.xml</file>
|
22 |
+
</advanceimport>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
</frontend>
|
26 |
+
|
27 |
+
|
28 |
+
<global>
|
29 |
+
<models>
|
30 |
+
<advanceimport>
|
31 |
+
<class>Maven_AdvanceImport_Model</class>
|
32 |
+
</advanceimport>
|
33 |
+
<catalog>
|
34 |
+
<rewrite>
|
35 |
+
<convert_adapter_product>Maven_AdvanceImport_Model_Convert_Adapter_Abstract</convert_adapter_product>
|
36 |
+
</rewrite>
|
37 |
+
</catalog>
|
38 |
+
</models>
|
39 |
+
<advanceimport>
|
40 |
+
<importtype>
|
41 |
+
|
42 |
+
<configurable>
|
43 |
+
<class>advanceimport/convert_adapter_configurableimport</class>
|
44 |
+
</configurable>
|
45 |
+
|
46 |
+
</importtype>
|
47 |
+
</advanceimport>
|
48 |
+
|
49 |
+
</global>
|
50 |
+
</config>
|
app/etc/modules/Maven_AdvanceImport.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Maven_AdvanceImport>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</Maven_AdvanceImport>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Mavenstore_Customoptionproductimport</name>
|
4 |
+
<version>1.1</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>The Advance Import Configurable Product module allows you to import products such as t-shirts that can be modified and optimized according to the needs and requirements of the customer. You can place control and choice in the hands of individual customers, thereby increasing sales of expensive and complex products through customization.</summary>
|
10 |
+
<description>The Advance Import Configurable Product module allows you to import products such as t-shirts that can be customized and optimized according to the needs and requirements of the customer. You can add some options to the CSV file to use features outside the range of normal Magento import facilities. Its powerful re-use capabilities enable you to use it over and over again on a wide range of data feeds.
|
11 |
+
|
12 |
+
It is a perfect solution to automatically and practically update the extensive data that is associated with complex products that need to be configured according to individual requirements. Moreover, it gives you the ability to update data and options for all Magento product types.
|
13 |
+
|
14 |
+
Features:
|
15 |
+
Extends the functionality of the universally used CSV format and the Magento Import function
|
16 |
+
Gives control and choice to individual customers
|
17 |
+
Sales of expensive and complex products are increased through customization
|
18 |
+
Facilitates quick changes to existing product lines
|
19 |
+
Custom options can be defined for each type of product</description>
|
20 |
+
<notes>Please refer User and Installation guide</notes>
|
21 |
+
<authors><author><name>Maven Infosoft</name><user>auto-converted</user><email>harsh.shah@maven-infosoft.com</email></author></authors>
|
22 |
+
<date>2011-06-14</date>
|
23 |
+
<time>09:21:24</time>
|
24 |
+
<contents><target name="magelocal"><dir name="Maven"><dir name="AdvanceImport"><dir name="etc"><file name="config.xml" hash="c107c9f15a5bbd42c32d8a3b1e93efec"/></dir><dir name="Model"><file name="Product.php" hash="57862883d5f56402c04927d2a6ac2f84"/><dir name="Convert"><dir name="Adapter"><file name="Abstract.php" hash="ab7c97be6d9f59fe808e918fb1721d01"/><file name="Configurableimport.php" hash="524a746560a7fb2483e76f45b4a13358"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Maven_AdvanceImport.xml" hash="250741ea9d3679b283395c7a487e34c8"/></dir></target></contents>
|
25 |
+
<compatible/>
|
26 |
+
<dependencies><required><package><name></name><channel>community</channel><min>1.3.4</min><max>1.4.2</max></package></required></dependencies>
|
27 |
+
</package>
|