Mage_Codi - Version 4.3.0

Version Notes

Please contact our support desk if you have any problems.

Download this release

Release Info

Developer catalogondemand
Extension Mage_Codi
Version 4.3.0
Comparing to
See all releases


Code changes from version 4.2.8 to 4.3.0

app/code/community/Mage/CodiScript/Model/Files.php CHANGED
@@ -1,40 +1,59 @@
1
  <?php
2
- // 2015-07-09
3
- class ConfiguredProductLine{
 
 
4
  public $optionIds = array();
5
  public $line = NULL;
 
6
  }
7
- class COption{
 
 
8
  public $id = NULL;
9
  public $title = NULL;
10
  public $type = NULL;
11
  public $required = NULL;
12
  public $values = array();
13
- public function toString(){
14
- return "COption #".$this->id." title=".$this->title." type=".$this->type." required=".$this->required." values=".count( $this->values );
 
15
  }
 
16
  }
17
- class COValue{
 
 
18
  public $title = NULL;
19
  public $sku = NULL;
20
  public $rprice = NULL;
21
  public $sprice = NULL;
22
- public function toString(){
23
- return "COValue ".$this->title." sku=".$this->sku." rprice=".$this->rprice." sprice=".$this->sprice;
 
24
  }
 
25
  }
26
- class COValueSet{
 
 
27
  public $optionId = NULL;
28
  public $coValues = array();
29
- public function toString(){
30
- $out = "COValueSet #".$this->optionId." ";
31
- foreach( $this->coValues as $value )
32
- $out .= $value->sku ? "-".$value->sku : "-...";
 
 
33
  return $out;
34
  }
 
35
  }
 
36
  class Mage_CodiScript_Model_Files extends Mage_Core_Model_Abstract {
 
37
  public $version = __VERSION__;
 
38
  public $Store;
39
  public $StoreId;
40
  public $reviewsModel;
@@ -75,278 +94,329 @@ class Mage_CodiScript_Model_Files extends Mage_Core_Model_Abstract {
75
  public $catpathmap;
76
  public $catmap;
77
  public $catpositions = FALSE;
 
78
  public $_DEBUG;
 
79
  const TAG_P_CLOSE = '</p>';
80
  const TAG_P = '<p>';
81
  const SCRIPTNAME = __SCRIPTNAME__;
82
 
83
  public function _construct() {
84
  parent::_construct();
85
- $this->_init( 'codi/codi2' );
86
- Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID );
 
 
 
 
 
 
 
 
87
  }
88
 
89
  // Class=DataFile
90
- public function renderDataFile(){
91
- if( $this->_DEBUG ){
92
- echo "memory_get_usage real: ".memory_get_usage(TRUE)." allocated: ".memory_get_usage()."
93
- ";
94
- foreach( Mage::app()->getStores() as $store ) echo "store: ".$store->getId()." code=".$store->getCode()." isActive=".$store->getIsActive()."
95
- ";
 
 
96
  }
97
  $this->productTypeConfigurableModel = Mage::getModel('catalog/product_type_configurable');
98
  $this->productTypeGroupedModel = Mage::getModel('catalog/product_type_grouped');
99
- $this->reviewsModel = Mage::getModel('review/review')->setStoreId( $this->StoreId );
100
- $this->catalogInventoryModel = Mage::getModel('cataloginventory/stock_item')->setStoreId( $this->StoreId );
101
- $this->mediaurl = Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_MEDIA );
102
- $this->prodmediaurl = $this->mediaurl."catalog/product";
103
  $this->mageVersionArray = Mage::getVersionInfo();
104
- if( $this->_DEBUG )
105
- echo "mageVersionArray: major ".$this->mageVersionArray[ 'major' ]." minor ".$this->mageVersionArray[ 'minor' ]."
106
- ";
107
- if( $this->publishtieredpricing || $this->getgroupprices ){
 
108
  $this->customerGroups = array();
109
  $customerGroups = Mage::getModel('customer/group')->getCollection();
110
- foreach( $customerGroups as $cg ){
111
  $this->customerGroups[$cg->_data['customer_group_id']] = $cg->_data['customer_group_code'];
112
- if( $this->_DEBUG ) echo "customer group #".$cg->_data['customer_group_id']."-".$cg->_data['customer_group_code']."
113
- ";
 
 
114
  }
115
  }
116
- $products = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->getCollection();
117
- $products->addAttributeToFilter('status', 1);//enabled
118
- $products->addAttributeToFilter('visibility', 4);//catalog, search
119
  $prodIds = $products->getAllIds();
120
- if( $this->_DEBUG ) echo "StoreId: ".$this->StoreId."
121
- Products: ".count($prodIds)."
122
- Media URL: ".$this->mediaurl."
123
- memory_get_usage ".memory_get_usage()." / ".memory_get_usage(TRUE)."
124
- ";
125
- if( $this->start == 0 ) echo "itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tManufacturer\tCategory\tReviews\tSupplementalInfo\titemSequence
126
- ";
 
 
 
 
127
  $count = 0;
128
  $index = 0;
129
  $lastLine = "==EOF==
130
  ";
131
- foreach( $prodIds as $productId ){
132
- if( $count == $this->pageSize ){
133
  $lastLine = "==MORE==
134
  ";
135
  break;
136
  }
137
- if( $index < $this->start ){
138
  $index++;
139
  continue;
140
  }
141
  $index++;
142
- $product = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $productId );
143
- if( $this->_DEBUG ) echo "== PRODUCT: ".$product->getTypeId()." == ".$product->getId()."-".$product->getName()." ==
144
- ";
145
- if( $product->isConfigurable() )
146
- echo $this->ProducttoStringConfigurable( $product );
147
- else if( $product->isGrouped() ){
148
- if( $this->splitgroupedproducts ){
149
- $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds( $product );
150
- $UsedProducts = array();
151
- foreach( $AssociatedProductIds as $UsedProductid ){
152
- $_product = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $UsedProductid );
153
- echo $this->ProducttoStringSimple( $_product );
 
154
  }
155
  } else {
156
- echo $this->ProducttoStringGrouped( $product );
157
  }
 
 
 
 
 
 
 
158
  }
159
- else
160
- echo $this->ProducttoStringSimple( $product );
161
- unset( $product );
162
- if( $this->_DEBUG ) echo "#".$count.": memory_get_usage ".memory_get_usage()." / ".memory_get_usage( TRUE )."
163
- ";
164
  $count++;
165
  }
166
- echo $lastLine;
167
  }
168
 
169
- private function ProducttoStringGrouped( &$product ){
170
  $ProducttoString = "";
171
- $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds( $product );
172
  $ProductDescription = "";
173
  $shortDescription = "";
174
- if( $this->includeshortdescription ){
175
  $shortDescription = $product->getShortDescription();
176
- if( !empty( $shortDescription ) ){
177
- $shortDescription = $this->_cleanStr( $shortDescription );
178
- if( strpos( $shortDescription, self::TAG_P ) !== false ){
179
- $new = strlen( $shortDescription );
180
- $pos = strrpos( $shortDescription, self::TAG_P_CLOSE ) + 4;
181
- if( $new != $pos )
182
- $shortDescription = substr( $shortDescription, 0, $pos ).self::TAG_P.substr( $shortDescription, $pos ).self::TAG_P_CLOSE;
183
- } else
184
- $shortDescription = self::TAG_P.$shortDescription .self::TAG_P_CLOSE;
185
- $ProductDescription = $shortDescription;
186
- }
187
- }
188
- if( $this->includelongdescription ){
 
 
189
  $longDescription = $product->getDescription();
190
- if( !empty( $longDescription ) ){
191
- $longDescription = $this->_cleanStr( $longDescription );
192
- if( strpos( $longDescription, self::TAG_P ) !== false ){
193
- $new = strlen( $longDescription );
194
- $pos = strrpos( $longDescription, self::TAG_P_CLOSE ) + 4;
195
- if( $new != $pos )
196
- $longDescription = substr( $longDescription, 0, $pos ).self::TAG_P.substr( $longDescription, $pos ).self::TAG_P_CLOSE;
197
- } else
198
- $longDescription = self::TAG_P.$longDescription.self::TAG_P_CLOSE;
199
- $ProductDescription .= $longDescription;
 
 
200
  }
201
  }
202
  $attributes = $product->getAttributes();
203
  $Manufacturer = "";
204
  $ProductAttributes = "";
205
- foreach( $attributes as $attribute ){
206
- $attribute->setStoreId( $this->StoreId );
207
- if( $this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ) ){
208
  $hasData = $product->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
209
- echo "grouped prod attr: ".$attribute->getFrontend()->getLabel()."=".$attribute->getFrontend()->getValue( $product )." input=".$attribute->getFrontendInput()." data=".$product->getData($attribute->getAttributeCode())." hasData=".$hasData."
210
- ";
211
  }
212
- if( $attribute->getAttributeCode()=="manufacturer" ){
213
- if( $product->getData( $attribute->getAttributeCode() ) )
214
- $Manufacturer = $attribute->getFrontend()->getValue( $product );
215
- else
216
  $Manufacturer = "";
 
217
  continue;
218
  }
219
- if( $attribute->getIsVisibleOnFront() ||
220
- ( $this->includecustomfields && array_key_exists ( strtolower( $attribute->getAttributeCode() ), $this->includecustomfields ) ) ){
221
- $value = $attribute->getFrontend()->getValue( $product );
222
- if( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ){
223
- $hasData = $product->getData( $attribute->getAttributeCode() ) ? TRUE : FALSE;
224
- if( !$hasData )
225
  $value = "";
 
226
  }
227
- if( is_string( $value ) && strlen( $value ) ){
228
- if( !empty( $ProductAttributes ) )
229
  $ProductAttributes .= "|";
 
230
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
231
  }
232
  }
233
  }
234
- if( $this->publishtieredpricing == "1" ){
235
- $TierPriceAttributes = $this->_getTierPrices( $product );
236
- $sp = ( empty( $ProductAttributes ) || empty( $TierPriceAttributes ) ) ? "" : "|";
237
- $ProductAttributes .= $sp.$TierPriceAttributes;
238
  }
239
- if( $this->importoptionsasattributes ){
240
- $optionsAsAttributes = $this->_getCustomOptionsAsAttributes( $product );
241
- if( !empty ( $optionsAsAttributes ) ){
242
- if( !empty( $ProductAttributes ) )
243
  $ProductAttributes .= "|";
 
244
  $ProductAttributes .= $optionsAsAttributes;
245
  }
246
  }
247
- if( !empty( $ProductAttributes ) )
248
- $ProductAttributes = $this->_cleanStr( $ProductAttributes );
249
- if( $this->_DEBUG ) echo "product image: ".$product->getImage()."
250
- small image: ".$product->getSmallImage()."
251
- thumbnail: ".$product->getThumbnail()."
252
- ";
253
- $prodImages = array();
254
- $firstImageFile = trim( $product->getImage() );
255
- if( $firstImageFile == "no_selection" )
 
 
 
256
  $firstImageFile = FALSE;
257
- if( $firstImageFile ){
258
- $prodImages[] = "MagentoBase#=#".$this->prodmediaurl.$this->_formatImageURL( $firstImageFile );
259
- }
260
- $prodImageArray = $product->getMediaGallery( 'images' );
261
- if( is_array( $prodImageArray ) ){
262
- foreach( $prodImageArray as $image ){
263
- $imageFile = trim( $image['file'] );
264
- if( $this->_DEBUG ) echo "gallery image: ".$imageFile." disabled=".$image['disabled']."
265
- ";
266
- if( !$imageFile || $imageFile == $firstImageFile )
 
 
 
267
  continue;
268
- if( $this->ignoreexcludedimages && $image['disabled'] )
 
269
  continue;
270
- $prodImages[] = "Print#=#".$this->prodmediaurl.$this->_formatImageURL( $imageFile );
 
271
  }
272
  }
273
- $prodImages = implode( "#|#", $prodImages );
274
  $ProductURL = $product->getProductUrl();
275
- if( !empty( $ProductURL ) )
276
- $ProductURL = $this->_correctProdUrlStr( $ProductURL );
 
277
  $productName = $product->getName();
278
- $productName = $product->getId().'#$#'.$this->_cleanStr( $productName );
279
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
280
- if( !empty( $Reviews ) )
281
- $Reviews = $this->_cleanStr( $Reviews );
282
- if( $this->_DEBUG ){
283
- echo "associated IDs: ";
284
- foreach( $AssociatedProductIds as $UsedProductid ) echo "".$UsedProductid." ";
285
- echo "
286
- ";
 
 
 
287
  }
288
  $sequence = 1;
289
  $UsedProducts = array();
290
- foreach( $AssociatedProductIds as $UsedProductid ){
291
- $UsedProduct = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $UsedProductid );
292
- if( $UsedProduct->getStatus() == 1 ){
293
  $UsedProducts[] = $UsedProduct;
294
  } else {
295
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." enabled=".$UsedProduct->getStatus()." - bypassed.
296
- ";
297
- unset( $UsedProduct );
 
 
298
  }
299
  }
300
  $renderSPrice = FALSE;
301
- if( $this->includespecialprice ){
302
- foreach( $UsedProducts as $UsedProduct ){
303
  $SPrice = $UsedProduct->getSpecialPrice();
304
- if( trim( $SPrice ) != "" ){
305
  $renderSPrice = TRUE;
306
  break;
307
  }
308
  }
309
  }
310
- foreach( $UsedProducts as $UsedProduct ){
311
- if( $this->instockonly ){
312
- $inventory = $this->catalogInventoryModel->loadByProduct( $UsedProduct );
313
  $qty = $inventory->getQty();
314
  $minQty = $inventory->getMinQty();
315
- if( $qty <= $minQty ){
316
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." enabled=".$UsedProduct->getStatus()." qty=".$qty." minQty=".$minQty." - bypassing.
317
- ";
 
 
318
  continue;
319
  }
320
  }
321
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." enabled=".$UsedProduct->getStatus()." prices: Regular=".$UsedProduct->getData('price')." Final=".$UsedProduct->getFinalPrice()." Special=".$UsedProduct->getSpecialPrice()." FromDate=".$UsedProduct->getSpecialFromDate()." ToDate=".$UsedProduct->getSpecialToDate()."
322
- ";
323
- $ItemName= $UsedProduct->getName();
 
 
324
  $ProdRPrice = $UsedProduct->getData('price');
325
  $ProdSPrice = $UsedProduct->getSpecialPrice();
326
  $ProdSFromDate = $UsedProduct->getSpecialFromDate();
327
  $ProdSToDate = $UsedProduct->getSpecialToDate();
328
  $ProdGroupPrices = FALSE;
329
- if( $this->mageVersionArray[ 'major' ] > 1 || $this->mageVersionArray[ 'minor' ] > 6 ){
330
  $ProdGroupPrices = $UsedProduct->getData('group_price');
331
- if( $this->_DEBUG && count( $ProdGroupPrices ) > 0 ) echo "group_price: ".var_export( $ProdGroupPrices, true )."
332
- ";
 
 
333
  }
334
  $ProdSpecGroupPrices = FALSE;
335
- if( $ProdGroupPrices ){
336
  $ProdSpecGroupPrices = array();
337
- foreach( $ProdGroupPrices as $groupPrice ){
338
- if( $groupPrice[ 'cust_group' ] == '0' ){
339
- $notLoggedInPrice = 0.0 + $groupPrice[ 'price' ];
340
- if( trim( $ProdSPrice ) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice ){
341
- $ProdSPrice = $groupPrice[ 'price' ];
342
  $ProdSFromDate = FALSE;
343
  $ProdSToDate = FALSE;
344
  }
345
- } else
346
  $ProdSpecGroupPrices[] = $groupPrice;
 
347
  }
348
  }
349
- if( trim( $ProdSPrice ) == "" ){
350
  $ProdSPrice = -1;
351
  $ProdSFromDate = FALSE;
352
  $ProdSToDate = FALSE;
@@ -354,269 +424,305 @@ thumbnail: ".$product->getThumbnail()."
354
  $SFromDate = $ProdSFromDate;
355
  $SToDate = $ProdSToDate;
356
  $RPrice = $ProdRPrice;
357
- if( !empty( $RPrice ) && $this->includetaxes )
358
- $RPrice = $this->taxhelper->getPrice( $UsedProduct, $RPrice, true, null, null, null, $this->StoreId );
 
359
  $SPrice = $ProdSPrice;
360
- if( $SPrice >= 0 && $this->includetaxes )
361
- $SPrice = $this->taxhelper->getPrice( $UsedProduct, $SPrice, true, null, null, null, $this->StoreId );
362
- if( $this->_DEBUG ) echo "resulting prices: Regular=".$RPrice." Special=".$SPrice." FromDate=".$SFromDate." ToDate=".$SToDate."
363
- ";
364
- if( $this->ignoreassprodimages ) $itemImages = "";
365
- else{
366
- // echo "grouped item image: ".$UsedProduct->getImage()."
367
- //small image: ".$UsedProduct->getSmallImage()."
368
- //thumbnail: ".$UsedProduct->getThumbnail()."
369
- //";
370
- $itemImages = array();
371
- $firstImageFile = trim( $UsedProduct->getImage() );
372
- if( $firstImageFile == "no_selection" )
373
  $firstImageFile = FALSE;
374
- if( $firstImageFile )
375
- $itemImages[] = "MagentoBase#=#".$this->prodmediaurl.$this->_formatImageURL( $firstImageFile );
 
 
376
  $itemImageArray = $UsedProduct->getMediaGallery('images');
377
- if( is_array($itemImageArray) ){
378
- foreach( $itemImageArray as $image ){
379
- $imageFile = trim( $image['file'] );
380
- // echo "gallery image: ".$imageFile." disabled=".$image['disabled']."
381
- //";
382
- if( !$imageFile || $imageFile == $firstImageFile )
383
  continue;
384
- if( $this->ignoreexcludedimages && $image['disabled'] )
 
385
  continue;
386
- $itemImages[] = "Print#=#".$this->prodmediaurl.$this->_formatImageURL( $imageFile );
 
387
  }
388
  }
389
- $itemImages = implode( "#|#", $itemImages );
390
  }
391
  $attributes = $UsedProduct->getAttributes();
392
  $ItemAttributes = "";
393
- foreach( $attributes as $attribute ){
394
- $attribute->setStoreId( $this->StoreId );
395
- if( $this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ) ){
396
  $hasData = $UsedProduct->getData($attribute->getAttributeCode()) ? "YES" : "NO";
397
- echo "grouped prod attr: ".$attribute->getFrontend()->getLabel()."=".$attribute->getFrontend()->getValue( $UsedProduct )." input=".$attribute->getFrontendInput()." data=".$UsedProduct->getData($attribute->getAttributeCode())." hasData=".$hasData."
398
- ";
399
  }
400
- if( $attribute->getAttributeCode() == "manufacturer" ){
401
- if( $UsedProduct->getData( $attribute->getAttributeCode() ) )
402
- $Manufacturer = $attribute->getFrontend()->getValue( $UsedProduct );
 
403
  continue;
404
  }
405
- if( $attribute->getIsVisibleOnFront() ||
406
- ( $this->includecustomfields && array_key_exists ( strtolower( $attribute->getAttributeCode() ), $this->includecustomfields ) ) ){
407
- $value = $attribute->getFrontend()->getValue( $UsedProduct );
408
- if( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ){
409
- $hasData = $UsedProduct->getData( $attribute->getAttributeCode() ) ? TRUE : FALSE;
410
- if( !$hasData )
411
  $value = "";
 
412
  }
413
- if( is_string( $value ) && strlen( $value ) )
414
  $ItemAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|";
 
415
  }
416
  }
417
- $ItemAttributes = substr( $ItemAttributes, 0, strlen( $ItemAttributes ) - 1 );
418
- if( $this->includeinvqty ){
419
- if( !empty( $ItemAttributes ) )
420
  $ItemAttributes .= "|";
421
- $ItemAttributes .= "Inventory=".$this->_formatQty( "".$this->catalogInventoryModel->loadByProduct( $UsedProduct )->getQty() );
422
- }
423
- if( $this->publishtieredpricing == "1" ){
424
- $TierPriceAttributes = $this->_getTierPrices( $UsedProduct );
425
- $sp = ( empty( $ItemAttributes ) || empty( $TierPriceAttributes ) ) ? "" : "|";
426
- $ItemAttributes .= $sp.$TierPriceAttributes;
427
- }
428
- $RPrice = $this->_formatPrice( $RPrice );
429
- if( $this->includespecialprice ){
430
- if( $SPrice >= 0 ){
431
- $SPrice = $this->_formatPrice( $SPrice );
432
- if( !empty( $ItemAttributes ) )
 
433
  $ItemAttributes .= "|";
434
- $ItemAttributes .= "Special Price=".$SPrice;
435
- } else if( $renderSPrice ){
436
- if( !empty( $ItemAttributes ) )
 
437
  $ItemAttributes .= "|";
 
438
  $ItemAttributes .= "Special Price=";
439
  }
440
  }
441
- if( $this->includespecialpricedatefrom ){
442
- if( !empty( $SFromDate ) ){
443
- if( !empty( $ItemAttributes ) )
444
  $ItemAttributes .= "|";
445
- $ItemAttributes .= "Special Price From Date=".substr( $SFromDate, 0, 10 );
 
446
  }
447
  }
448
- if( $this->includespecialpricedateto ){
449
- if( !empty( $SToDate ) ){
450
- if( !empty( $ItemAttributes ) )
451
  $ItemAttributes .= "|";
452
- $ItemAttributes .= "Special Price To Date=".substr( $SToDate, 0, 10 );
 
453
  }
454
  }
455
- if( $this->getgroupprices && $ProdSpecGroupPrices ){
456
- foreach( $ProdSpecGroupPrices as $groupPrice ){
457
- $price = 0.0 + $groupPrice[ 'price' ];
458
- if( $price >= 0 && $this->includetaxes )
459
- $price = $this->taxhelper->getPrice( $UsedProduct, $price, true, null, null, null, $this->StoreId );
460
- if( !empty( $ItemAttributes ) )
 
461
  $ItemAttributes .= "|";
462
- $ItemAttributes .= "price_".$this->customerGroups[ $groupPrice[ 'cust_group' ] ]."=".$this->_formatPrice( $price );
 
463
  }
464
  }
465
  $itemID = $UsedProduct->getSku();
466
- $ProducttoString .= $this->_cleanStr( $itemID ) //ItemID
467
- ."\t" //ItemQty
468
- ."\t" //ItemUom
469
- ."\t" .$RPrice //ItemPrice
470
- ."\t" .$this->_cleanStr( $ItemName) //ItemDescription
471
- ."\t" //ItemLink
472
- ."\t" .$this->_cleanStr( $ItemAttributes ) //ItemAttributes
473
- ."\t" .$itemImages //ItemGraphic
474
- ."\t" .$productName //ProductName
475
- ."\t" .$ProductDescription
476
- ."\t" .$prodImages //ProductGraphic
477
- ."\t" .$ProductURL //ProductLink
478
- ."\t" .$ProductAttributes //ProductAttributes
479
- ."\t" .$Manufacturer //Manufacturer
480
- ."\t" //Category
481
- ."\t" .$Reviews //Reviews
482
- ."\t" .$shortDescription
483
- ."\t" . $sequence
484
- ."\n";
485
- unset( $UsedProduct );
486
  $sequence++;
487
  }
488
- unset( $UsedProducts );
489
- unset( $AssociatedProductIds );
490
  return $ProducttoString;
491
  }
492
 
493
- private function ProducttoStringConfigurable( &$product ){
494
  $UsedProductIds = $this->productTypeConfigurableModel->getUsedProductIds($product);
495
  $ProductDescription = "";
496
  $shortDescription = "";
497
- if( $this->includeshortdescription ){
498
  $shortDescription = $product->getShortDescription();
499
- if( !empty( $shortDescription ) ){
500
- $shortDescription = $this->_cleanStr( $shortDescription );
501
- if( strpos( $shortDescription, self::TAG_P ) !== false ){
502
- $new = strlen( $shortDescription );
503
- $pos = strrpos( $shortDescription, self::TAG_P_CLOSE ) + 4;
504
- if( $new != $pos )
505
- $shortDescription = substr( $shortDescription, 0, $pos ).self::TAG_P.substr( $shortDescription, $pos ).self::TAG_P_CLOSE;
506
- } else
507
- $shortDescription = self::TAG_P.$shortDescription .self::TAG_P_CLOSE;
508
- $ProductDescription = $shortDescription;
509
- }
510
- }
511
- if( $this->includelongdescription ){
 
 
512
  $longDescription = $product->getDescription();
513
- if( !empty( $longDescription ) ){
514
- $longDescription = $this->_cleanStr( $longDescription );
515
- if( strpos( $longDescription, self::TAG_P ) !== false ){
516
- $new = strlen( $longDescription );
517
- $pos = strrpos( $longDescription, self::TAG_P_CLOSE ) + 4;
518
- if( $new != $pos )
519
- $longDescription = substr( $longDescription, 0, $pos ).self::TAG_P.substr( $longDescription, $pos ).self::TAG_P_CLOSE;
520
- } else
521
- $longDescription = self::TAG_P.$longDescription.self::TAG_P_CLOSE;
522
- $ProductDescription .= $longDescription;
 
 
523
  }
524
  }
525
  $attributes = $product->getAttributes();
526
  $Manufacturer = "";
527
  $ProductAttributes = "";
528
- foreach( $attributes as $attribute ){
529
- $attribute->setStoreId( $this->StoreId );
530
- if( $attribute->getAttributeCode()=="manufacturer" ){
531
- if( $product->getData( $attribute->getAttributeCode() ) )
532
- $Manufacturer = $attribute->getFrontend()->getValue( $product );
533
- else
534
  $Manufacturer = "";
 
535
  continue;
536
  }
537
- if( $attribute->getIsVisibleOnFront() ||
538
- ( $this->includecustomfields && array_key_exists ( strtolower( $attribute->getAttributeCode() ), $this->includecustomfields ) ) ){
539
- $value = $attribute->getFrontend()->getValue( $product );
540
- if( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ){
541
- $hasData = $product->getData( $attribute->getAttributeCode() ) ? TRUE : FALSE;
542
- if( !$hasData )
543
  $value = "";
 
544
  }
545
- if( is_string( $value ) && strlen( $value ) ){
546
- if( !empty( $ProductAttributes ) )
547
  $ProductAttributes .= "|";
 
548
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
549
  }
550
  }
551
  }
552
- if( $this->publishtieredpricing == "1" ){
553
  $TierPriceAttributes = $this->_getTierPrices($product);
554
- $sp = ( empty( $ProductAttributes ) || empty( $TierPriceAttributes ) ) ? "" : "|";
555
- $ProductAttributes.= $sp.$TierPriceAttributes;
556
  }
557
- if( $this->importoptionsasattributes ){
558
- $optionsAsAttributes = $this->_getCustomOptionsAsAttributes( $product );
559
- if( !empty ( $optionsAsAttributes ) ){
560
- if( !empty( $ProductAttributes ) )
561
  $ProductAttributes .= "|";
 
562
  $ProductAttributes .= $optionsAsAttributes;
563
  }
564
  }
565
- if( !empty( $ProductAttributes ) )
566
- $ProductAttributes = $this->_cleanStr( $ProductAttributes );
567
- if( $this->_DEBUG ) echo "product image: ".$product->getImage()."
568
- small image: ".$product->getSmallImage()."
569
- thumbnail: ".$product->getThumbnail()."
570
- ";
571
- $prodImages = array();
572
- $firstImageFile = trim( $product->getImage() );
573
- if( $firstImageFile == "no_selection" )
 
 
 
574
  $firstImageFile = FALSE;
575
- if( $firstImageFile )
576
- $prodImages[] = "MagentoBase#=#".$this->prodmediaurl.$this->_formatImageURL( $firstImageFile );
 
 
577
  $prodImageArray = $product->getMediaGallery('images');
578
- if( is_array($prodImageArray) ){
579
- foreach( $prodImageArray as $image ){
580
- $imageFile = trim( $image['file'] );
581
- if( $this->_DEBUG ) echo "gallery image: ".$imageFile." disabled=".$image['disabled']."
582
- ";
583
- if( !$imageFile || $imageFile == $firstImageFile )
 
 
584
  continue;
585
- if( $this->ignoreexcludedimages && $image['disabled'] )
 
586
  continue;
587
- $prodImages[] = "Print#=#".$this->prodmediaurl.$this->_formatImageURL( $imageFile );
 
588
  }
589
  }
590
- $prodImages = implode( "#|#", $prodImages );
591
  $ProductURL = $product->getProductUrl();
592
- if( !empty( $ProductURL ) )
593
- $ProductURL = $this->_correctProdUrlStr( $ProductURL );
 
594
  $productName = $product->getName();
595
- $productName = $product->getId().'#$#'.$this->_cleanStr( $productName );
596
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
597
- if( !empty( $Reviews ) )
598
- $Reviews = $this->_cleanStr( $Reviews );
599
- if( ! $this->getpricefromchild ){
 
600
  $ProdRPrice = $product->getData('price');
601
  $ProdSPrice = $product->getSpecialPrice();
602
  $ProdSFromDate = $product->getSpecialFromDate();
603
  $ProdSToDate = $product->getSpecialToDate();
604
- if( $this->_DEBUG ) echo "prod prices: Regular=".$ProdRPrice." Special=".$ProdSPrice." FromDate=".$ProdSFromDate." ToDate=".$ProdSToDate."
605
- ";
 
 
606
  $ProdGroupPrices = FALSE;
607
- if( $this->mageVersionArray[ 'major' ] > 1 || $this->mageVersionArray[ 'minor' ] > 6 ){
608
  $ProdGroupPrices = $product->getData('group_price');
609
- if( $this->_DEBUG && count( $ProdGroupPrices ) > 0 ) echo "group_price: ".var_export( $ProdGroupPrices, true )."
610
- ";
 
 
611
  }
612
  $ProdSpecGroupPrices = FALSE;
613
- if( $ProdGroupPrices ){
614
  $ProdSpecGroupPrices = array();
615
- foreach( $ProdGroupPrices as $groupPrice ){
616
- if( $groupPrice[ 'cust_group' ] == '0' ){
617
- $notLoggedInPrice = 0.0 + $groupPrice[ 'price' ];
618
- if( trim( $ProdSPrice ) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice ){
619
- $ProdSPrice = $groupPrice[ 'price' ];
620
  $ProdSFromDate = FALSE;
621
  $ProdSToDate = FALSE;
622
  }
@@ -625,129 +731,142 @@ thumbnail: ".$product->getThumbnail()."
625
  }
626
  }
627
  }
628
- if( trim( $ProdSPrice ) == "" ){
629
  $ProdSPrice = -1;
630
  $ProdSFromDate = FALSE;
631
  $ProdSToDate = FALSE;
632
  }
633
  } // ! $this->getpricefromchild
634
- if( $this->_DEBUG ){
635
- echo "used product IDs: ";
636
- foreach( $UsedProductIds as $UsedProductid ) echo "".$UsedProductid." ";
637
- echo "
638
- ";
 
 
639
  }
640
  $usedConfigurableAttributes = FALSE;
641
- if( $this->importoptionsasattributes ){
642
  $usedConfigurableAttributes = array();
643
  }
644
- $ConfigurableAttributes = $product->getTypeInstance( true )->getConfigurableAttributes( $product );
645
- foreach( $ConfigurableAttributes as $attribute ){
646
- if( $this->_DEBUG ){
647
- echo "configurable attr: ".$attribute->getLabel()."
648
- ";
649
  }
650
  $configurableProdAttribute = $attribute->getProductAttribute();
651
- if( empty( $configurableProdAttribute ) ){
652
  $label = $attribute->getLabel();
653
- echo "WARNING: no product attribute for configurable attribute ".$label."
654
- ";
655
  continue;
656
  }
657
- $configurableProdAttribute->setStoreId( $this->StoreId );
658
- if( $this->_DEBUG ){
659
- echo "configurable prod attr: ".$configurableProdAttribute->getFrontend()->getLabel()."
660
- ";
661
  }
662
  $AttributeLabel = $attribute->getLabel();
663
- if( !$AttributeLabel )
664
  $AttributeLabel = $configurableProdAttribute->getFrontend()->getLabel();
665
- if( $this->importoptionsasattributes ){
666
- $usedConfigurableAttributes[ $AttributeLabel ] = array();
667
- if( $this->_DEBUG ){
668
- echo "created usedConfigurableAttributes array for \"".$AttributeLabel."\"
669
- ";
 
670
  }
671
  }
672
- foreach( $configurableProdAttribute->getSource()->getAllOptions() as $option ) {
673
- if( $this->_DEBUG ){
674
- echo "variation option: ".$option['value' ]."=>".$option['label' ]."
675
- ";
676
  }
677
- if( $this->importoptionsasattributes ){
678
- $usedConfigurableAttributes[ $AttributeLabel ][ $option['label' ] ] = FALSE;
679
- if( $this->_DEBUG ){
680
- echo "created usedConfigurableAttributes label \"".$option['label' ]."\"
681
- ";
682
  }
683
- }
684
  }
685
  }
686
  $UsedProducts = array();
687
- foreach( $UsedProductIds as $UsedProductid ){
688
- $UsedProduct = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $UsedProductid );
689
- if( $UsedProduct->getStatus() == 1 ){
690
- $UsedProducts[ $UsedProductid ] = $UsedProduct;
691
  } else {
692
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." enabled=".$UsedProduct->getStatus()." - bypassed.
693
- ";
694
- unset( $UsedProduct );
 
 
695
  }
696
  }
697
  $cpLines = array();
698
- foreach( $UsedProducts as $UsedProductid => $UsedProduct ){
699
  $cpLine = new ConfiguredProductLine();
700
- if( $this->instockonly ){
701
- $inventory = $this->catalogInventoryModel->loadByProduct( $UsedProduct );
702
  $qty = $inventory->getQty();
703
  $minQty = $inventory->getMinQty();
704
- if( $qty <= $minQty ){
705
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." qty=".$qty." minQty=".$minQty." - bypassing.
706
- ";
 
 
707
  continue;
708
  }
709
  }
710
- if( ! $this->getpricefromchild ){
711
  $RPrice = $ProdRPrice;
712
  $SPrice = $ProdSPrice;
713
  $RPrice0 = $ProdRPrice;
714
  $SPrice0 = $ProdSPrice;
715
- $SFromDate = !empty( $SPrice ) ? $ProdSFromDate : FALSE;
716
- $SToDate = !empty( $SPrice ) ? $ProdSToDate : FALSE;
717
  $SpecGroupPrices = FALSE;
718
  $SpecGroupPrices0 = FALSE;
719
- if( $ProdSpecGroupPrices ){
720
  $SpecGroupPrices = array();
721
  $SpecGroupPrices0 = array();
722
- foreach( $ProdSpecGroupPrices as $prodGroupPrice ){
723
- $SpecGroupPrices[ $prodGroupPrice[ 'cust_group' ] ] = 0.0 + $prodGroupPrice[ 'price' ];
724
- $SpecGroupPrices0[ $prodGroupPrice[ 'cust_group' ] ] = 0.0 + $prodGroupPrice[ 'price' ];
725
  }
726
  }
727
  } else { // $this->getpricefromchild
728
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." prices: Regular=".$UsedProduct->getData('price')." Final=".$UsedProduct->getFinalPrice()." Special=".$UsedProduct->getSpecialPrice()." FromDate=".$UsedProduct->getSpecialFromDate()." ToDate=".$UsedProduct->getSpecialToDate()."
729
- ";
 
 
730
  $RPrice = $UsedProduct->getData('price');
731
  $SPrice = $UsedProduct->getSpecialPrice();
732
  $SFromDate = $UsedProduct->getSpecialFromDate();
733
  $SToDate = $UsedProduct->getSpecialToDate();
734
- if( $this->_DEBUG ) echo "prod prices: Regular=".$RPrice." Special=".$SPrice." FromDate=".$SFromDate." ToDate=".$SToDate."
735
- ";
 
 
736
  $ProdGroupPrices = FALSE;
737
- if( $this->mageVersionArray[ 'major' ] > 1 || $this->mageVersionArray[ 'minor' ] > 6 ){
738
  $ProdGroupPrices = $UsedProduct->getData('group_price');
739
- if( $this->_DEBUG && count( $ProdGroupPrices ) > 0 ) echo "group_price: ".var_export( $ProdGroupPrices, true )."
740
- ";
 
 
741
  }
742
  $SpecGroupPrices = FALSE;
743
  $SpecGroupPrices0 = FALSE;
744
- if( $ProdGroupPrices ){
745
  $SpecGroupPrices = array();
746
- foreach( $ProdGroupPrices as $groupPrice ){
747
- if( $groupPrice[ 'cust_group' ] == '0' ){
748
- $notLoggedInPrice = 0.0 + $groupPrice[ 'price' ];
749
- if( trim( $SPrice ) == "" || $notLoggedInPrice < 0.0 + $SPrice ){
750
- $SPrice = $groupPrice[ 'price' ];
751
  $SFromDate = FALSE;
752
  $SToDate = FALSE;
753
  }
@@ -756,172 +875,198 @@ thumbnail: ".$product->getThumbnail()."
756
  }
757
  }
758
  }
759
- if( trim( $SPrice ) == "" ){
760
  $SPrice = -1;
761
  $SFromDate = FALSE;
762
  $SToDate = FALSE;
763
  }
764
  }
765
  $ItemAttributes = "";
766
- foreach( $ConfigurableAttributes as $attribute ){
767
  $configurableProdAttribute = $attribute->getProductAttribute();
768
- if( empty( $configurableProdAttribute ) ){
769
  $label = $attribute->getLabel();
770
- echo "WARNING: no product attribute for configurable attribute ".$label."
771
- ";
772
  $cpLine->optionIds[] = 0;
773
  continue;
774
  }
775
  $AttributeCode = $configurableProdAttribute->getAttributeCode();
776
  $AttributeLabel = $attribute->getLabel();
777
- if( !$AttributeLabel )
778
  $AttributeLabel = $configurableProdAttribute->getFrontend()->getLabel();
 
779
  $AttribId = $UsedProduct->getData($AttributeCode);
780
- $cpLine->optionIds[] = intVal( $AttribId );
781
  $AttributeValue = "";
782
- foreach( $configurableProdAttribute->getSource()->getAllOptions() as $option ){
783
- if( $option['value'] == $AttribId ){
784
  $AttributeValue = $option['label'];
785
  break;
786
  }
787
  }
788
- if( $this->importoptionsasattributes && trim( $AttributeValue ) ){
789
- $usedConfigurableAttributes[ $AttributeLabel ][ $AttributeValue ] = TRUE;
790
- }
791
- if( $this->_DEBUG ) echo "config attr code=".$AttributeCode." label=".$AttributeLabel." id=".$AttribId." value=".$AttributeValue."
792
- ";
793
- if( !empty( $ItemAttributes ) )
 
 
794
  $ItemAttributes .= "|";
795
- $ItemAttributes .= $AttributeLabel."=".$AttributeValue;
796
- if( ! $this->getpricefromchild ){
797
- foreach( $attribute->getPrices() as $addedPrice ){
798
- if( $AttributeValue == $addedPrice['label']){
799
- if( $addedPrice['is_percent'] ){
800
- $RPrice += round( $RPrice0 * $addedPrice['pricing_value'] / 100, 2 );
801
- if( $SPrice >= 0 )
802
- $SPrice += round( $SPrice0 * $addedPrice['pricing_value'] / 100, 2 );
803
- if( $SpecGroupPrices ){
804
- foreach( $SpecGroupPrices0 as $key => $value ){
805
- $SpecGroupPrices[ $key ] += round( $value * $addedPrice['pricing_value'] / 100, 2 );
 
 
806
  }
807
- }
808
  } else {
809
  $RPrice += $addedPrice['pricing_value'];
810
- if( $SPrice >= 0 )
811
  $SPrice += $addedPrice['pricing_value'];
812
- if( $SpecGroupPrices ){
813
- foreach( $SpecGroupPrices0 as $key => $value )
814
- $SpecGroupPrices[ $key ] += $addedPrice['pricing_value'];
815
- }
 
 
816
  }
817
  }
818
  }
819
  } // ! $this->getpricefromchild
820
  }
821
- if( !empty($RPrice) && $this->includetaxes )
822
- $RPrice = $this->taxhelper->getPrice( $UsedProduct, $RPrice, true, null, null, null, $this->StoreId );
823
- if( !empty($SPrice) && $this->includetaxes )
824
- $SPrice = $this->taxhelper->getPrice( $UsedProduct, $SPrice, true, null, null, null, $this->StoreId );
825
- if( $this->includeinvqty ){
826
- if( !empty( $ItemAttributes ) )
 
 
827
  $ItemAttributes .= "|";
828
- $ItemAttributes .= "Inventory=".$this->_formatQty( "".$this->catalogInventoryModel->loadByProduct( $UsedProduct )->getQty() );
829
- }
830
- if( $this->_DEBUG ) echo "resulting prices: Regular=".$RPrice." Special=".$SPrice." FromDate=".$SFromDate." ToDate=".$SToDate."
831
- ";
832
- $RPrice = $this->_formatPrice( $RPrice );
833
- if( $this->includespecialprice ){
834
- if( $SPrice >= 0 ){
835
- $SPrice = $this->_formatPrice( $SPrice );
836
- if( !empty( $ItemAttributes ) )
 
 
 
837
  $ItemAttributes .= "|";
838
- $ItemAttributes .= "Special Price=".$SPrice;
 
839
  }
840
  }
841
- if( $this->includespecialpricedatefrom ){
842
- if( !empty( $SFromDate ) ){
843
- if( !empty( $ItemAttributes ) )
844
  $ItemAttributes .= "|";
845
- $ItemAttributes .= "Special Price From Date=".substr( $SFromDate, 0, 10 );
 
846
  }
847
  }
848
- if( $this->includespecialpricedateto ){
849
- if( !empty( $SToDate ) ){
850
- if( !empty( $ItemAttributes ) )
851
  $ItemAttributes .= "|";
852
- $ItemAttributes .= "Special Price To Date=".substr( $SToDate, 0, 10 );
 
853
  }
854
  }
855
- if( $this->getgroupprices && $SpecGroupPrices ){
856
- foreach( $SpecGroupPrices as $groupID => $price ){
857
- if( $price >= 0 && $this->includetaxes )
858
- $price = $this->taxhelper->getPrice( $UsedProduct, $price, true, null, null, null, $this->StoreId );
859
- if( !empty( $ItemAttributes ) )
 
860
  $ItemAttributes .= "|";
861
- $ItemAttributes .= "price_".$this->customerGroups[ $groupID ]."=".$this->_formatPrice( $price );
 
862
  }
863
  }
864
- if( ! $this->getpricefromchild ){
865
- if( $this->publishtieredpricing == "1" ){
866
  $TierPriceAttributes = $this->_getTierPrices($UsedProduct);
867
- $sp = ( empty( $ItemAttributes ) || empty( $TierPriceAttributes ) ) ? "" : "|";
868
- $ItemAttributes.= $sp.$TierPriceAttributes;
869
  }
870
  } // ! $this->getpricefromchild
871
- if( $this->ignoreassprodimages ) $itemImages = "";
872
- else{
873
- if( $this->_DEBUG ) echo "config item image: ".$UsedProduct->getImage()."
874
- small image: ".$UsedProduct->getSmallImage()."
875
- thumbnail: ".$UsedProduct->getThumbnail()."
876
- ";
877
- $itemImages = array();
878
- $firstImageFile = trim( $UsedProduct->getImage() );
879
- if( $firstImageFile == "no_selection" )
 
 
 
880
  $firstImageFile = FALSE;
881
- if( $firstImageFile )
882
- $itemImages[] = "MagentoBase#=#".$this->prodmediaurl.$this->_formatImageURL( $firstImageFile );
 
 
883
  $itemImageArray = $UsedProduct->getMediaGallery('images');
884
- if( is_array($itemImageArray) ){
885
- foreach( $itemImageArray as $image ){
886
- $imageFile = trim( $image['file'] );
887
- if( $this->_DEBUG ) echo "gallery image: ".$imageFile." disabled=".$image['disabled']."
888
- ";
889
- if( !$imageFile || $imageFile == $firstImageFile )
 
 
890
  continue;
891
- if( $this->ignoreexcludedimages && $image['disabled'] )
 
892
  continue;
893
- $itemImages[] = "Print#=#".$this->prodmediaurl.$this->_formatImageURL( $imageFile );
 
894
  }
895
  }
896
- $itemImages = implode( "#|#", $itemImages );
897
  }
898
  $itemID = $UsedProduct->getSku();
899
- $cpLine->line = $this->_cleanStr( $itemID ) //ItemID
900
- ."\t" //ItemQty
901
- ."\t" //ItemUom
902
- ."\t" .$RPrice //ItemPrice
903
- ."\t" //ItemDescription
904
- ."\t" //ItemLink
905
- ."\t" .$this->_cleanStr( $ItemAttributes ) //ItemAttributes
906
- ."\t" .$itemImages; //ItemitemGraphic
907
  $cpLines[] = $cpLine;
908
- unset( $UsedProduct );
909
  }
910
- unset( $UsedProducts );
911
- unset( $UsedProductIds );
912
  $optionIds = array();
913
  $attrNumber = 0;
914
  $optNumbers = array();
915
  $optCounters = array();
916
- foreach( $ConfigurableAttributes as $attribute ){
917
  $configurableProdAttribute = $attribute->getProductAttribute();
918
- if( empty( $configurableProdAttribute ) ){
919
  continue;
920
  }
921
  $optionIdList = array();
922
  $optionNo = 0;
923
- foreach( $configurableProdAttribute->getSource()->getAllOptions() as $option ){
924
- $optionIdList[] = trim( $option['value'] ) == "" ? 0 : intVal( $option['value'] );
925
  $optionNo++;
926
  }
927
  $optionIds[] = $optionIdList;
@@ -929,318 +1074,370 @@ thumbnail: ".$UsedProduct->getThumbnail()."
929
  $optNumbers[] = 0;
930
  $attrNumber++;
931
  }
932
- // if( $this->_DEBUG ) foreach( $optionIds as $key => $optionIdList ) echo "optionIds[".$key."]: ".var_export( $optionIdList, true )."
933
- //";
934
  // supplement prod attrs
935
- if( $this->importoptionsasattributes ){
936
- foreach( $usedConfigurableAttributes as $attrName => $attrValues ){
937
- if( !empty( $ProductAttributes ) )
938
  $ProductAttributes .= "|";
939
- $ProductAttributes .= $attrName."=";
 
940
  $valCount = 0;
941
- foreach( $attrValues as $attrValue => $used ){
942
- if( $used ){
943
- if( $valCount > 0 )
944
  $ProductAttributes .= "<br />";
 
945
  $ProductAttributes .= $attrValue;
946
  $valCount++;
947
  }
948
  }
949
  }
950
- }
951
  // build prod part
952
- $this->prodLine = "\t" .$productName //ProductName
953
- ."\t" .$ProductDescription
954
- ."\t" .$prodImages //ProductGraphic
955
- ."\t" .$ProductURL //ProductLink
956
- ."\t" .$ProductAttributes //ProductAttributes
957
- ."\t" .$Manufacturer //Manufacturer
958
- ."\t" //Category
959
- ."\t" .$Reviews //Reviews
960
- ."\t" .$shortDescription
961
- ."\t";
962
  // build cplines matrix
963
  $cpLinesMatrix = array();
964
- foreach( $cpLines as $cpLine ){
965
- $optionId = $cpLine->optionIds[ 0 ];
966
- if( $attrNumber > 1 ){
967
- if( !isset( $cpLinesMatrix[ $optionId ] ) )
968
- $cpLinesMatrix[ $optionId ] = array();
969
- $this->_fillCPLinesMatrix( 1, $attrNumber, $cpLine, $cpLinesMatrix[ $optionId ] );
 
970
  } else {
971
- if( !isset( $cpLinesMatrix[ $optionId ] ) )
972
- $cpLinesMatrix[ $optionId ] = $cpLine;
 
973
  }
974
  }
975
  $this->configItemSequence = 1;
976
  $this->configProducttoString = "";
977
- $this->_fillConfigProdItems( 0, $attrNumber, $optNumbers, $optionIds, $optCounters, $cpLinesMatrix );
978
- unset( $optionIds );
979
- foreach( $cpLines as $cpLine ){
980
- if( $cpLine->line ) echo "WARNING: not rendered config line: ".var_export( $cpLine->optionIds, true )."
981
- ";
 
 
982
  }
983
- unset( $cpLines );
984
  return $this->configProducttoString;
985
  }
986
-
987
- private function ProducttoStringSimple( &$product ){
988
  $ProductDescription = "";
989
  $shortDescription = "";
990
- if( $this->includeshortdescription ){
991
  $shortDescription = $product->getShortDescription();
992
- if( !empty( $shortDescription ) ){
993
- $shortDescription = $this->_cleanStr( $shortDescription );
994
- if( strpos( $shortDescription, self::TAG_P ) !== false ){
995
- $new = strlen( $shortDescription );
996
- $pos = strrpos( $shortDescription, self::TAG_P_CLOSE ) + 4;
997
- if( $new != $pos )
998
- $shortDescription = substr( $shortDescription, 0, $pos ).self::TAG_P.substr( $shortDescription, $pos ).self::TAG_P_CLOSE;
999
- } else
1000
- $shortDescription = self::TAG_P.$shortDescription .self::TAG_P_CLOSE;
1001
- $ProductDescription = $shortDescription;
1002
- }
1003
- }
1004
- if( $this->includelongdescription ){
 
 
1005
  $longDescription = $product->getDescription();
1006
- if( !empty( $longDescription ) ){
1007
- $longDescription = $this->_cleanStr( $longDescription );
1008
- if( strpos( $longDescription, self::TAG_P ) !== false ){
1009
- $new = strlen( $longDescription );
1010
- $pos = strrpos( $longDescription, self::TAG_P_CLOSE ) + 4;
1011
- if( $new != $pos )
1012
- $longDescription = substr( $longDescription, 0, $pos ).self::TAG_P.substr( $longDescription, $pos ).self::TAG_P_CLOSE;
1013
- } else
1014
- $longDescription = self::TAG_P.$longDescription.self::TAG_P_CLOSE;
1015
- $ProductDescription .= $longDescription;
1016
- }
1017
- }
1018
- $prodImages = array();
1019
- if( $this->_DEBUG ) echo "product image: ".$product->getImage()."
1020
- small image: ".$product->getSmallImage()."
1021
- thumbnail: ".$product->getThumbnail()."
1022
- ";
1023
- $firstImageFile = trim( $product->getImage() );
1024
- if( $firstImageFile == "no_selection" )
 
 
 
 
1025
  $firstImageFile = FALSE;
1026
- if( $firstImageFile )
1027
- $prodImages[] = "MagentoBase#=#".$this->prodmediaurl.$this->_formatImageURL( $firstImageFile );
 
 
1028
  $prodImageArray = $product->getMediaGallery('images');
1029
- if( is_array( $prodImageArray ) ){
1030
- foreach( $prodImageArray as $image ){
1031
- $imageFile = trim( $image['file'] );
1032
- if( $this->_DEBUG ) echo "gallery image: ".$imageFile." disabled=".$image['disabled']."
1033
- ";
1034
- if( !$imageFile || $imageFile == $firstImageFile )
 
 
1035
  continue;
1036
- if( $this->ignoreexcludedimages && $image['disabled'] )
 
1037
  continue;
1038
- $prodImages[] = "Print#=#".$this->prodmediaurl.$this->_formatImageURL( $imageFile );
 
1039
  }
1040
  }
1041
- $prodImages = implode( "#|#", $prodImages );
1042
  $URL = $product->getProductUrl();
1043
- if( $this->_DEBUG ) echo "URL= ".$URL."
1044
- ";
1045
- if( !empty( $URL ) )
1046
- $URL = $this->_correctProdUrlStr( $URL );
 
 
 
1047
  $attributes = $product->getAttributes();
1048
  $Manufacturer = "";
1049
  $ProductAttributes = "";
1050
- foreach( $attributes as $attribute ){
1051
- $attribute->setStoreId( $this->StoreId );
1052
- if( $this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ) ){
1053
  $hasData = $product->getData($attribute->getAttributeCode()) ? "YES" : "NO";
1054
  $vof = $attribute->getIsVisibleOnFront() ? "YES" : "NO";
1055
- echo "simple prod attr: ".$attribute->getFrontend()->getLabel()."=".$attribute->getFrontend()->getValue( $product )." input=".$attribute->getFrontendInput()." data=".$product->getData($attribute->getAttributeCode())." hasData=".$hasData." store=".$product->_storeId." vof=".$vof."
1056
- ";
1057
  }
1058
- if( $attribute->getAttributeCode()=="manufacturer" ){
1059
- if( $product->getData( $attribute->getAttributeCode() ) )
1060
- $Manufacturer = $attribute->getFrontend()->getValue( $product );
1061
- else
1062
  $Manufacturer = "";
 
1063
  continue;
1064
  }
1065
- if( $attribute->getIsVisibleOnFront() ||
1066
- ( $this->includecustomfields && array_key_exists ( strtolower( $attribute->getAttributeCode() ), $this->includecustomfields ) ) ){
1067
- $value = $attribute->getFrontend()->getValue( $product );
1068
- if( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" ){
1069
- $hasData = $product->getData( $attribute->getAttributeCode() ) ? TRUE : FALSE;
1070
- if( !$hasData )
1071
  $value = "";
 
1072
  }
1073
- if( is_string( $value ) && strlen( $value ) ){
1074
- if( !empty( $ProductAttributes ) )
1075
  $ProductAttributes .= "|";
 
1076
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
1077
  } else {
1078
- if( $this->_DEBUG ) echo "not a string with length > 0
1079
- ";
 
 
1080
  }
1081
  }
1082
  }
1083
- if( $this->publishtieredpricing == "1" ){
1084
- $TierPriceAttributes = $this->_getTierPrices( $product );
1085
- $sp = ( empty( $ProductAttributes ) || empty( $TierPriceAttributes ) ) ? "" : "|";
1086
- $ProductAttributes.= $sp.$TierPriceAttributes;
1087
  }
1088
- if( $this->importoptionsasattributes ){
1089
- $optionsAsAttributes = $this->_getCustomOptionsAsAttributes( $product );
1090
- if( !empty ( $optionsAsAttributes ) ){
1091
- if( !empty( $ProductAttributes ) )
1092
  $ProductAttributes .= "|";
 
1093
  $ProductAttributes .= $optionsAsAttributes;
1094
  }
1095
  }
1096
- if( !empty( $ProductAttributes ) )
1097
- $ProductAttributes = $this->_cleanStr( $ProductAttributes );
 
1098
  $ProdRPrice = $product->getData('price');
1099
  $ProdSPrice = $product->getSpecialPrice();
1100
  $ProdSFromDate = $product->getSpecialFromDate();
1101
  $ProdSToDate = $product->getSpecialToDate();
1102
- if( $this->instockonly ){
1103
- $inventory = $this->catalogInventoryModel->loadByProduct( $product );
1104
  $qty = $inventory->getQty();
1105
  $minQty = $inventory->getMinQty();
1106
- if( $this->_DEBUG ) echo "sku=".$product->getSku()." qty=".$qty." minQty=".$minQty."
1107
- ";
1108
- if( $qty <= $minQty )
 
 
1109
  return;
 
 
 
 
 
1110
  }
1111
- if( $this->_DEBUG ) echo "sku=".$product->getSku()." prices: Regular=".$ProdRPrice." Special=".$ProdSPrice." FromDate=".$ProdSFromDate." ToDate=".$ProdSToDate."
1112
- ";
1113
  $ProdGroupPrices = FALSE;
1114
- if( $this->mageVersionArray[ 'major' ] > 1 || $this->mageVersionArray[ 'minor' ] > 6 ){
1115
  $ProdGroupPrices = $product->getData('group_price');
1116
- if( $this->_DEBUG && count( $ProdGroupPrices ) > 0 ) echo "group_price: ".var_export( $ProdGroupPrices, true )."
1117
- ";
 
 
1118
  }
1119
  $ProdSpecGroupPrices = FALSE;
1120
- if( $ProdGroupPrices ){
1121
  $ProdSpecGroupPrices = array();
1122
- foreach( $ProdGroupPrices as $groupPrice ){
1123
- if( $groupPrice[ 'cust_group' ] == '0' ){
1124
- $notLoggedInPrice = 0.0 + $groupPrice[ 'price' ];
1125
- if( trim( $ProdSPrice ) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice ){
1126
- $ProdSPrice = $groupPrice[ 'price' ];
1127
  $ProdSFromDate = FALSE;
1128
  $ProdSToDate = FALSE;
1129
  }
1130
- } else
1131
  $ProdSpecGroupPrices[] = $groupPrice;
 
1132
  }
1133
  }
1134
- if( trim( $ProdSPrice ) == "" ){
1135
  $ProdSPrice = -1;
1136
  $ProdSFromDate = FALSE;
1137
  $ProdSToDate = FALSE;
1138
  }
1139
- if( !$ProdRPrice && $product->getTypeId() == "bundle" ){
1140
  $priceModel = $product->getPriceModel();
1141
- $options = Mage::getSingleton('core/layout')->createBlock('bundle/catalog_product_view_type_bundle')->setProduct( $product )->getOptions();
1142
  $ProdRPrice = 0;
1143
- foreach( $options as $option ){
1144
  $selection = $option->getDefaultSelection();
1145
  $MinSelPrice = 0;
1146
- if( $selection )
1147
- $MinSelPrice = $priceModel->getSelectionPreFinalPrice( $product, $selection, $selection->getSelectionQty() );
1148
- else if( !$selection && $option->_origData["required"] == "1" ){
1149
- foreach( $option->getSelections() as $selection ){
1150
- $SelPrice = $priceModel->getSelectionPreFinalPrice( $product, $selection, $selection->getSelectionQty() );
1151
- if( ( $MinSelPrice == 0 && $SelPrice > 0 ) || ( $MinSelPrice > 0 && $SelPrice > 0 && $SelPrice < $MinSelPrice ) )
1152
  $MinSelPrice = $SelPrice;
 
1153
  }
1154
  }
1155
- if( $MinSelPrice <= 0 )
1156
  continue;
1157
- if( $this->_DEBUG ) echo "added ".$MinSelPrice."
1158
- ";
 
 
 
1159
  $ProdRPrice += $MinSelPrice;
1160
  }
1161
- if( $this->_DEBUG ) echo "Bundle=".$ProdRPrice."
1162
- ";
 
 
1163
  }
1164
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
1165
- if( !empty( $Reviews ) )
1166
- $Reviews = $this->_cleanStr( $Reviews );
 
1167
  $prodSku = $product->getSku();
1168
- $prodSku = $this->_cleanStr( $prodSku );
1169
- $cleanProdName = $this->_cleanStr( $prodName );
1170
  $prodName = $product->getName();
1171
- $cleanProdName = $this->_cleanStr( $prodName );
1172
- $prodName = $product->getId().'#$#'.$cleanProdName;
1173
  $skusAdded = false;
1174
- if( $this->importoptionsassku ){
1175
  $this->configItemSequence = 1;
1176
  $this->configProducttoString = "";
1177
  $customOptions = $product->getOptions();
1178
- if( $customOptions ){
1179
- if( $this->_DEBUG ) echo "=== customOptions ===
1180
- ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1181
- ";
 
 
1182
  $max_sort_order = 0;
1183
- foreach( $customOptions as $option ){
1184
- if( $option->getSortOrder() > $max_sort_order ){
1185
  $max_sort_order = $option->getSortOrder();
1186
- } else if( $option->getSortOrder() < 0 ){
1187
- $option->setSortOrder( -1 );
1188
  }
1189
  }
1190
  $orderedOptionValues = array();
1191
  $orderedCustomOptions = array();
1192
- for( $sortorder = -1; $sortorder <= $max_sort_order; $sortorder++ ){
1193
  foreach ($customOptions as $option) {
1194
- if( $option->getSortOrder() != $sortorder ) continue;
 
 
1195
  $orderedCustomOptions[] = $option;
1196
  $optionValues = array();
1197
- if( $option->getValues() ){
1198
  $max_v_sort_order = 0;
1199
- foreach( $option->getValues() as $_value ){
1200
- if( $_value->getSortOrder() > $max_v_sort_order ){
1201
  $max_v_sort_order = $_value->getSortOrder();
1202
- } else if( $_value->getSortOrder() < 0 ){
1203
- $_value->setSortOrder( -1 );
1204
  }
1205
  }
1206
- for( $vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++ ){
1207
- foreach( $option->getValues() as $_value ){
1208
- if( $_value->getSortOrder() != $vsortorder ) continue;
1209
- $optionValues[] = $_value;
 
 
1210
  }
1211
  }
1212
  }
1213
- $orderedOptionValues[ $option->getOptionId() ] = $optionValues;
1214
  }
1215
  }
1216
  $customOptions = array();
1217
  $customOptionsById = array();
1218
- foreach( $orderedCustomOptions as $option ){
1219
- if( $this->_DEBUG ){
1220
- echo "customOption #".$option->getOptionId()." title=".$option->getTitle()." storeTitle=".$option->getStoreTitle()." type=".$option->getType()." isRequire=".$option->getIsRequire()." sort_order".$option->getSortOrder()."
1221
- ";
1222
- if( $option->getType() == "date" ||
1223
- $option->getType() == "time" ||
1224
- $option->getType() == "date_time" ||
1225
- $option->getType() == "field" ||
1226
- $option->getType() == "area" )
1227
- echo " price=".$option->getPrice()." price_type=".$option->getPriceType()." sku=".$option->getSku()."
1228
- ";
 
1229
  }
1230
  $customOption = new COption();
1231
  $customOption->id = $option->getOptionId();
1232
  $customOption->title = $option->getStoreTitle();
1233
- if( !$customOption->title )
1234
  $customOption->title = $option->getTitle();
1235
- if( !$customOption->title )
1236
- $customOption->title = "Option #".$option->getOptionId();
 
 
1237
  $customOption->type = $option->getType();
1238
  $customOption->required = $option->getIsRequire();
1239
- if( $this->_DEBUG ) echo $customOption->toString()."
1240
- ";
1241
- $optionValues = $orderedOptionValues[ $option->getOptionId() ];
 
 
1242
  $isMultiple = ( $option->getType() == "multiple" || $option->getType() == "checkbox" );
1243
- if( !$option->getIsRequire() && !$isMultiple ){
1244
  $coValue = new COValue();
1245
  $coValue->title = FALSE;
1246
  $coValue->sku = FALSE;
@@ -1248,202 +1445,240 @@ ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1248
  $coValue->pvalue = 0;
1249
  $coValue->rprice = 0;
1250
  $coValue->sprice = 0;
1251
- if( $this->_DEBUG ) echo $coValue->toString()."
1252
- ";
 
 
1253
  $customOption->values[] = $coValue;
1254
  }
1255
- if( $option->getType() == "date" ||
1256
- $option->getType() == "time" ||
1257
- $option->getType() == "date_time" ||
1258
- $option->getType() == "field" ||
1259
- $option->getType() == "area" ){
1260
- if( $option->getSku() ){
1261
  $coValue = new COValue();
1262
  $coValue->title = "Provided";
1263
  $coValue->sku = $option->getSku();
1264
  $coValue->ifpercent = FALSE;
1265
  $coValue->pvalue = $option->getPrice();
1266
- if( $option->getPriceType() == "percent" ){
1267
  $coValue->ifpercent = TRUE;
1268
- $coValue->rprice = round( $ProdRPrice * $option->getPrice() / 100, 2 );
1269
- $coValue->sprice = $ProdSPrice > -1 ? round( $ProdSPrice * $option->getPrice() / 100, 2 ) : -1;
1270
  } else {
1271
  $coValue->rprice = $option->getPrice();
1272
  $coValue->sprice = $ProdSPrice > -1 ? $option->getPrice() : -1;
1273
  }
1274
- if( $this->_DEBUG ) echo $coValue->toString()."
1275
- ";
 
 
1276
  $customOption->values[] = $coValue;
1277
  }
1278
  } else {
1279
- foreach( $optionValues as $optionValue ){
1280
- if( $this->_DEBUG ) echo "value title=".$optionValue->getTitle()." storeTitle=".$optionValue->getStoreTitle()." price=".$optionValue->getPrice()." price_type=".$optionValue->getPriceType()." sku=".$optionValue->getSku()." sort_order=".$optionValue->getSortOrder()."
1281
- ";
1282
- if( $optionValue->getSku() ){
 
 
1283
  $coValue = new COValue();
1284
  $coValue->title = $optionValue->getStoreTitle();
1285
- if( !$coValue->title )
1286
  $coValue->title = $optionValue->getTitle();
1287
- if( !$coValue->title )
 
1288
  $coValue->title = "Option value";
 
1289
  $coValue->sku = $optionValue->getSku();
1290
  $coValue->ifpercent = FALSE;
1291
  $coValue->pvalue = $optionValue->getPrice();
1292
- if( $optionValue->getPriceType() == "percent" ){
1293
  $coValue->ifpercent = TRUE;
1294
- $coValue->rprice = round( $ProdRPrice * $optionValue->getPrice() / 100, 2 );
1295
- $coValue->sprice = $ProdSPrice > -1 ? round( $ProdSPrice * $optionValue->getPrice() / 100, 2 ) : -1;
1296
  } else {
1297
  $coValue->rprice = $optionValue->getPrice();
1298
  $coValue->sprice = $ProdSPrice > -1 ? $optionValue->getPrice() : -1;
1299
  }
1300
- if( $this->_DEBUG ) echo $coValue->toString()."
1301
- ";
 
 
1302
  $customOption->values[] = $coValue;
1303
  }
1304
  }
1305
  }
1306
- if( $isMultiple && count( $customOption->values ) > 1 )
1307
- $customOption->values = array_reverse( $customOption->values );
1308
- if( count( $customOption->values ) == 0 ){
1309
- } else if( count( $customOption->values ) == 1 ){
1310
- if( $customOption->values[ 0 ]->sku )
 
 
1311
  $customOptions[] = $customOption;
 
1312
  } else {
1313
  $customOptions[] = $customOption;
1314
  }
1315
- $customOptionsById[ $customOption->id ] = $customOption;
1316
  }
1317
- if( $this->_DEBUG ){
1318
- echo "Resulting options / values
1319
- ";
1320
- foreach( $customOptions as $option ){
1321
- echo $option->toString()."
1322
- ";
1323
- foreach( $option->values as $value ) echo $value->toString()."
1324
- ";
 
 
1325
  }
1326
  }
1327
- if( count( $customOptions ) > 0 ){
1328
  $coValueSetSequences = array();
1329
  $coValueSetSequence = array();
1330
- $this->_buildCOValueSets( $coValueSetSequences, $coValueSetSequence, 0, $customOptions );
1331
  $index = 1;
1332
- foreach( $coValueSetSequences as $coValueSetSequence ){
1333
- if( $this->_DEBUG ){
1334
- echo "coValueSetSequence #".$index."
1335
- ";
1336
- foreach( $coValueSetSequence as $coValueSet ) echo $coValueSet->toString()."
1337
- ";
 
 
1338
  }
1339
  $ItemNumber = $prodSku;
1340
  $RPrice = $ProdRPrice;
1341
  $SPrice = $ProdSPrice;
1342
  $ItemAttributes = "";
1343
- if( $this->includeinvqty ){
1344
- if( !empty( $ItemAttributes ) )
1345
  $ItemAttributes .= "|";
1346
- $ItemAttributes = "Inventory=".$this->_formatQty( "".$this->catalogInventoryModel->loadByProduct( $product )->getQty() );
 
1347
  }
1348
- foreach( $coValueSetSequence as $coValueSet ){
1349
- $cOption = $customOptionsById[ $coValueSet->optionId ];
1350
- if( !empty( $ItemAttributes ) )
1351
  $ItemAttributes .= "|";
1352
- $ItemAttributes .= $cOption->title."=";
 
1353
  $vcount = 0;
1354
- foreach( $coValueSet->coValues as $value ){
1355
- if( $value->sku ){
1356
- if( $ItemNumber ) $ItemNumber .= "-";
 
 
1357
  $ItemNumber .= $value->sku;
1358
  $RPrice += $value->rprice;
1359
- if( $SPrice >= 0 ) $SPrice += $value->sprice;
1360
- if( $vcount > 0 ) $ItemAttributes .= ", ";
 
 
 
 
1361
  $ItemAttributes .= $value->title;
1362
  $vcount++;
1363
  }
1364
  }
1365
  }
1366
- if( empty( $ItemNumber ) ){
1367
- if( $this->_DEBUG ) echo "NO ItemNumber
1368
- ";
 
 
1369
  continue;
1370
  }
1371
- if( !empty( $RPrice ) && $this->includetaxes )
1372
- $RPrice = $this->taxhelper->getPrice( $product, $RPrice, true, null, null, null, $this->StoreId );
1373
- if( $SPrice >= 0 && $this->includetaxes )
1374
- $SPrice = $this->taxhelper->getPrice( $product, $SPrice, true, null, null, null, $this->StoreId );
1375
- if( $this->_DEBUG ) echo "resulting prices: Regular=".$RPrice." Special=".$SPrice." FromDate=".$ProdSFromDate." ToDate=".$ProdSToDate."
1376
- ";
1377
- $RPrice = $this->_formatPrice( $RPrice );
1378
- if( $this->includespecialprice ){
1379
- if( $SPrice >= 0 ){
1380
- $SPrice = $this->_formatPrice( $SPrice );
1381
- if( !empty( $ItemAttributes ) )
 
 
 
 
1382
  $ItemAttributes .= "|";
1383
- $ItemAttributes .= "Special Price=".$SPrice;
 
1384
  }
1385
  }
1386
- if( $this->includespecialpricedatefrom ){
1387
- if( !empty( $ProdSFromDate ) ){
1388
- if( !empty( $ItemAttributes ) )
1389
  $ItemAttributes .= "|";
1390
- $ItemAttributes .= "Special Price From Date=".substr( $ProdSFromDate, 0, 10 );
 
1391
  }
1392
  }
1393
- if( $this->includespecialpricedateto ){
1394
- if( !empty( $ProdSToDate ) ){
1395
- if( !empty( $ItemAttributes ) )
1396
  $ItemAttributes .= "|";
1397
- $ItemAttributes .= "Special Price To Date=".substr( $ProdSToDate, 0, 10 );
 
1398
  }
1399
  }
1400
- if( $this->getgroupprices && $ProdSpecGroupPrices ){
1401
- foreach( $ProdSpecGroupPrices as $groupPrice ){
1402
- $price = 0.0 + $groupPrice[ 'price' ];
1403
  $price0 = $price;
1404
- foreach( $coValueSetSequence as $coValueSet ){
1405
- foreach( $coValueSet->coValues as $value ){
1406
- if( $value->sku ){
1407
- if( $value->ifpercent ){
1408
- $price = $price + round( $price0 * $value->pvalue / 100, 2 );
1409
  } else {
1410
  $price = $price + $value->pvalue;
1411
  }
1412
  }
1413
  }
1414
  }
1415
- if( $price >= 0 && $this->includetaxes )
1416
- $price = $this->taxhelper->getPrice( $product, $price, true, null, null, null, $this->StoreId );
1417
- if( !empty( $ItemAttributes ) )
 
1418
  $ItemAttributes .= "|";
1419
- $ItemAttributes .= "price_".$this->customerGroups[ $groupPrice[ 'cust_group' ] ]."=".$this->_formatPrice( $price );
 
1420
  }
1421
  }
1422
- if( $this->_DEBUG ) echo "resulting attrs: ".$ItemAttributes."
1423
- ";
 
 
1424
  $ProducttoString .= $ItemNumber //ItemID
1425
- ."\t" //ItemQty
1426
- ."\t" //ItemUom
1427
- ."\t" .$RPrice //ItemPrice
1428
- ."\t" //ItemDescription
1429
- ."\t" //ItemLink
1430
- ."\t" .$ItemAttributes //ItemAttributes
1431
- ."\t" //ItemitemGraphic
1432
- ."\t" .$prodName //ProductName
1433
- ."\t" .$ProductDescription //ProductDescription
1434
- ."\t" .$prodImages //ProductGraphic
1435
- ."\t" .$URL //ProductLink
1436
- ."\t" .$ProductAttributes //ProductAttributes
1437
- ."\t" .$Manufacturer //Manufacturer
1438
- ."\t" //Category
1439
- ."\t" .$Reviews //Reviews
1440
- ."\t" .$shortDescription
1441
- ."\t" .$index
1442
- ."\n";
1443
  $skusAdded = TRUE;
1444
  // https://objectpublisher.basecamphq.com/projects/257020-odp/posts/87233819/comments#comment_312388129
1445
- if( $index >= 200 ){
1446
- $ProducttoString .= "REPORTWARNING: Not all options were converted to items for the product #".$product->getId()." - \"".$cleanProdName."\".
1447
  ";
1448
  break;
1449
  }
@@ -1452,70 +1687,80 @@ ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1452
  }
1453
  }
1454
  }
1455
- if( !$skusAdded ){
1456
  $RPrice = $ProdRPrice;
1457
- if( !empty( $RPrice ) && $this->includetaxes )
1458
- $RPrice = $this->taxhelper->getPrice( $product, $RPrice, true, null, null, null, $this->StoreId );
 
1459
  $SPrice = $ProdSPrice;
1460
- if( $SPrice >= 0 && $this->includetaxes )
1461
- $SPrice = $this->taxhelper->getPrice( $product, $SPrice, true, null, null, null, $this->StoreId );
1462
- if( $this->_DEBUG ) echo "resulting prices: Regular=".$RPrice." Special=".$SPrice." FromDate=".$ProdSFromDate." ToDate=".$ProdSToDate."
1463
- ";
 
 
 
1464
  $ItemAttributes = "";
1465
- if( $this->includeinvqty )
1466
- $ItemAttributes = "Inventory=".$this->_formatQty( "".$this->catalogInventoryModel->loadByProduct( $product )->getQty() );
1467
- $RPrice = $this->_formatPrice( $RPrice );
1468
- if( $this->includespecialprice ){
1469
- if( $SPrice >= 0 ){
1470
- $SPrice = $this->_formatPrice( $SPrice );
1471
- if( !empty( $ItemAttributes ) )
 
1472
  $ItemAttributes .= "|";
1473
- $ItemAttributes .= "Special Price=".$SPrice;
 
1474
  }
1475
  }
1476
- if( $this->includespecialpricedatefrom ){
1477
- if( !empty( $ProdSFromDate ) ){
1478
- if( !empty( $ItemAttributes ) )
1479
  $ItemAttributes .= "|";
1480
- $ItemAttributes .= "Special Price From Date=".substr( $ProdSFromDate, 0, 10 );
 
1481
  }
1482
  }
1483
- if( $this->includespecialpricedateto ){
1484
- if( !empty( $ProdSToDate ) ){
1485
- if( !empty( $ItemAttributes ) )
1486
  $ItemAttributes .= "|";
1487
- $ItemAttributes .= "Special Price To Date=".substr( $ProdSToDate, 0, 10 );
 
1488
  }
1489
  }
1490
- if( $this->getgroupprices && $ProdSpecGroupPrices ){
1491
- foreach( $ProdSpecGroupPrices as $groupPrice ){
1492
- $price = 0.0 + $groupPrice[ 'price' ];
1493
- if( $price >= 0 && $this->includetaxes )
1494
- $price = $this->taxhelper->getPrice( $product, $price, true, null, null, null, $this->StoreId );
1495
- if( !empty( $ItemAttributes ) )
 
1496
  $ItemAttributes .= "|";
1497
- $ItemAttributes .= "price_".$this->customerGroups[ $groupPrice[ 'cust_group' ] ]."=".$this->_formatPrice( $price );
 
1498
  }
1499
  }
1500
  $ProducttoString = $prodSku //ItemID
1501
- ."\t" //ItemQty
1502
- ."\t" //ItemUom
1503
- ."\t" .$RPrice //ItemPrice
1504
- ."\t" //ItemDescription
1505
- ."\t" //ItemLink
1506
- ."\t" .$ItemAttributes //ItemAttributes
1507
- ."\t" //ItemitemGraphic
1508
- ."\t" .$prodName //ProductName
1509
- ."\t" .$ProductDescription //ProductDescription
1510
- ."\t" .$prodImages //ProductGraphic
1511
- ."\t" .$URL //ProductLink
1512
- ."\t" .$ProductAttributes //ProductAttributes
1513
- ."\t" .$Manufacturer //Manufacturer
1514
- ."\t" //Category
1515
- ."\t" .$Reviews //Reviews
1516
- ."\t" .$shortDescription
1517
- ."\t1"
1518
- ."\n";
1519
  }
1520
  return $ProducttoString;
1521
  }
@@ -1524,33 +1769,35 @@ ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1524
  private $configItemSequence = 0;
1525
  private $configProducttoString = "";
1526
 
1527
- private function _fillCPLinesMatrix( $attrNumber, $optNo, &$cpLine, &$cpLinesMatrix ){
1528
- $optionId = $cpLine->optionIds[ $attrNumber ];
1529
- if( $attrNumber < $optNo - 1 ){
1530
- if( !isset( $cpLinesMatrix[ $optionId ] ) )
1531
- $cpLinesMatrix[ $optionId ] = array();
1532
- $this->_fillCPLinesMatrix( $attrNumber + 1, $optNo, $cpLine, $cpLinesMatrix[ $optionId ] );
 
1533
  } else {
1534
- if( !isset( $cpLinesMatrix[ $optionId ] ) )
1535
- $cpLinesMatrix[ $optionId ] = $cpLine;
 
1536
  }
1537
  }
1538
 
1539
- private function _fillConfigProdItems( $attrNumber, $attrNo, &$optNumbers, &$optionIds, &$optCounters, &$cpLinesMatrix ){
1540
  $optNumber = 0;
1541
- $optionIdNo = $optCounters[ $attrNumber ];
1542
- while( $optNumber < $optionIdNo ){
1543
- $optionID = $optionIds[ $attrNumber ][ $optNumber ];
1544
- if( isset( $cpLinesMatrix[ $optionID ] ) ){
1545
- if( $attrNumber < $attrNo - 1 ){
1546
- $optNumbers[ $attrNumber ] = $optNumber;
1547
- $this->_fillConfigProdItems( $attrNumber + 1, $attrNo, $optNumbers, $optionIds, $optCounters, $cpLinesMatrix[ $optionID ] );
1548
  } else {
1549
- $cpLine = $cpLinesMatrix[ $optionID ];
1550
  $this->configProducttoString .= $cpLine->line
1551
- .$this->prodLine
1552
- .$this->configItemSequence
1553
- ."\n";
1554
  $cpLine->line = FALSE;
1555
  $this->configItemSequence++;
1556
  }
@@ -1558,107 +1805,124 @@ ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1558
  $optNumber++;
1559
  }
1560
  }
1561
-
1562
- private function _getCustomOptionsAsAttributes( &$product ){
1563
  $attributes = "";
1564
  $customOptions = $product->getOptions();
1565
- if( $customOptions ){
1566
  //We should support all 4 selects: dropdown, radio buttons, checkbox, and multiple select.
1567
  //\app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php
1568
- if( $this->_DEBUG ) echo "=== customOptions ===
1569
- ";
 
 
1570
  $max_sort_order = 0;
1571
- foreach( $customOptions as $option ){
1572
- if( $option->getSortOrder() > $max_sort_order ){
1573
  $max_sort_order = $option->getSortOrder();
1574
- } else if( $option->getSortOrder() < 0 ){
1575
- $option->setSortOrder( -1 );
1576
  }
1577
  }
1578
- if( $this->_DEBUG ){
1579
- for( $sortorder = -1; $sortorder <= $max_sort_order; $sortorder++ ){
1580
  foreach ($customOptions as $option) {
1581
- if( $option->getSortOrder() != $sortorder ) continue;
1582
- echo "customOption #".$option->getOptionId()." title=".$option->getTitle()." storeTitle=".$option->getStoreTitle()." type=".$option->getType()." sort_order".$option->getSortOrder()."
1583
- ";
1584
- if( $option->getValues() ){
 
 
1585
  $max_v_sort_order = 0;
1586
  foreach ($option->getValues() as $_value) {
1587
- if( $_value->getSortOrder() > $max_v_sort_order ){
1588
  $max_v_sort_order = $_value->getSortOrder();
1589
- } else if( $_value->getSortOrder() < 0 ){
1590
- $_value->setSortOrder( -1 );
1591
  }
1592
  }
1593
- for( $vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++ ){
1594
- if( $_value->getSortOrder() != $vsortorder ) continue;
 
 
1595
  foreach ($option->getValues() as $_value) {
1596
- echo "value title=".$_value->getTitle()." storeTitle=".$option->getStoreTitle()." price=".$_value->getPrice()." price_type=".$_value->getPriceType()." sku=".$_value->getSku()." sort_order=".$_value->getSortOrder()."
1597
- ";
1598
  }
1599
  }
1600
  }
1601
  }
1602
  }
1603
  }
1604
- for( $sortorder = -1; $sortorder <= $max_sort_order; $sortorder++ ){
1605
  foreach ($customOptions as $option) {
1606
- if( $option->getSortOrder() != $sortorder ) continue;
1607
- if( $option->getType() != "drop_down" && $option->getType() != "radio" && $option->getType() != "multiple" && $option->getType() != "checkbox" ) continue;
 
 
 
 
1608
  $optionTitle = $option->getStoreTitle();
1609
- if( empty( $optionTitle ) )
1610
  $optionTitle = $option->getTitle();
 
1611
  $optionValues = "";
1612
- if( $option->getValues() ){
1613
  $max_v_sort_order = 0;
1614
- foreach( $option->getValues() as $_value ){
1615
- if( $_value->getSortOrder() > $max_v_sort_order ){
1616
  $max_v_sort_order = $_value->getSortOrder();
1617
- } else if( $_value->getSortOrder() < 0 ){
1618
- $_value->setSortOrder( -1 );
1619
  }
1620
  }
1621
- for( $vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++ ){
1622
- foreach( $option->getValues() as $_value ){
1623
- if( $_value->getSortOrder() != $vsortorder ) continue;
1624
- if( !empty( $optionValues ) )
 
 
1625
  $optionValues .= "<br/>";
 
1626
  $valueTitle = $_value->getStoreTitle();
1627
- if( empty( $valueTitle ) )
1628
  $valueTitle = $_value->getTitle();
 
1629
  $optionValues .= $valueTitle;
1630
  }
1631
  }
1632
  }
1633
- if( !empty( $attributes ) )
1634
  $attributes .= "|";
 
1635
  $attributes .= $optionTitle . "=" . $optionValues;
1636
  }
1637
  }
1638
  }
1639
  return $attributes;
1640
  }
1641
-
1642
- private function _buildCOValueSets( &$coValueSetSequences, $coValueSetSequence, $index, &$customOptions ){
1643
- $cOption = $customOptions[ $index ];
1644
- $customOptionCount = count( $customOptions );
1645
  $coValueSetList = array();
1646
- if( $cOption->type == "multiple" || $cOption->type == "checkbox" ){
1647
  // all combinations + empty if not required
1648
- $valuesCount = count( $cOption->values );
1649
  $indexList = array();
1650
  $indices = array();
1651
- $this->_buildCOValueIndices( $indexList, $indices, $valuesCount - 1 );
1652
- foreach( $indexList as $indices ){
1653
  $coValueSet = new COValueSet();
1654
  $coValueSet->optionId = $cOption->id;
1655
  $valueIndexNo = 0;
1656
- foreach( $indices as $valueIndex ){
1657
- if( $valueIndex == 1 )
1658
- $coValueSet->coValues[] = $cOption->values[ $valueIndexNo ];
 
1659
  $valueIndexNo++;
1660
  }
1661
- if( !$cOption->required && count( $coValueSet->coValues ) == 0 ){
1662
  $coValue = new COValue();
1663
  $coValue->title = FALSE;
1664
  $coValue->sku = FALSE;
@@ -1666,539 +1930,689 @@ ProdRPrice=".$ProdRPrice." ProdSPrice=".$ProdSPrice."
1666
  $coValue->sprice = 0;
1667
  $coValueSet->coValues[] = $coValue;
1668
  }
1669
- if( count( $coValueSet->coValues ) == 0 )
1670
  continue;
1671
- if( count( $coValueSet->coValues ) > 1 )
1672
- $coValueSet->coValues = array_reverse( $coValueSet->coValues );
 
 
1673
  $coValueSetList[] = $coValueSet;
1674
  }
1675
  } else {
1676
- foreach( $cOption->values as $optionValue ){
1677
  $coValueSet = new COValueSet();
1678
  $coValueSet->optionId = $cOption->id;
1679
  $coValueSet->coValues[] = $optionValue;
1680
  $coValueSetList[] = $coValueSet;
1681
  }
1682
  }
1683
- $coValueSetListCount = count( $coValueSetList );
1684
- foreach( $coValueSetList as $coValueSet ){
1685
- $coValueSetSequence[ $index ] = $coValueSet;
1686
- if( $index == $customOptionCount - 1 )
1687
  $coValueSetSequences[] = $coValueSetSequence;
1688
  else
1689
- $this->_buildCOValueSets( $coValueSetSequences, $coValueSetSequence, $index + 1, $customOptions );
1690
  }
1691
  }
1692
 
1693
- private function _buildCOValueIndices( &$indexList, $indices, $index ){
1694
- for( $i = 0; $i < 2; $i++ ){
1695
- $indices[ $index ] = $i;
1696
- if( $index == 0 )
1697
  $indexList[] = $indices;
1698
- else
1699
- $this->_buildCOValueIndices( $indexList, $indices, $index - 1 );
 
1700
  }
1701
  }
1702
 
1703
- private function _cleanStr( &$str ){
1704
- return str_replace("\n"," ", str_replace("\r"," ", str_replace("\r\n"," ", str_replace("\t"," ", $str ) ) ) );
1705
  }
1706
 
1707
- private function _correctProdUrlStr( &$str ){
1708
- $str = str_replace( self::SCRIPTNAME, "index.php", $str );
1709
- $pos = strpos( $str, "?" );
1710
- if( $pos === false )
1711
  return $str;
1712
- else if( substr( $str, $pos ) == "?___store=default" )
1713
- return substr( $str, 0, $pos );
1714
- else return $str;
 
 
1715
  }
1716
 
1717
- private function _getReviews( $productid ){
1718
  $reviewsCollection = $this->reviewsModel->getCollection()
1719
- ->addStoreFilter( $this->StoreId )
1720
- ->addStatusFilter( 'approved' )
1721
- ->addEntityFilter( 'product', $productid )
1722
- ->setDateOrder();
1723
  $Reviews = "";
1724
- foreach( $reviewsCollection as $review )
1725
- $Reviews .= "<p><b>".$review->getTitle()."(". $review->getNickname() .")</b><br>".$review->getDetail().self::TAG_P_CLOSE;
1726
- unset( $reviewsCollection );
 
1727
  return $Reviews;
1728
  }
1729
 
1730
- private function _formatPrice( $Price ){
1731
- $v = 0.0;
1732
- if( is_string( $Price ) ){
1733
- $rv = str_replace("\n"," ", str_replace("\r"," ", str_replace("\r\n"," ", str_replace("\t"," ", $Price ) ) ) );
1734
- if( empty( $rv ) || $rv == "0" )
1735
- return "";
1736
- $v = floatval( $Price );
1737
- } else if( is_float( $Price ) ) {
1738
- $v = $Price;
 
1739
  } else {
1740
- $v = floatval( $Price );
1741
  }
1742
- if( $v <= 0 ){
1743
- return "";
1744
  }
1745
  $v100 = $v * 100;
1746
- $iv100 = intval( $v100 );
1747
- if( $v100 - $iv100 >= 0.5 )
1748
  $iv100 = $iv100 + 1;
1749
- $rv = strval( floatval( $iv100 ) / 100 );
1750
- $tail = strrchr( $rv, "." );
1751
- if( !empty( $tail ) && strlen( $tail ) > 3 )
1752
- $rv = substr( $rv, 0, strlen( $rv ) - ( strlen( $tail ) - 3 ) );
1753
- else if( !empty( $tail ) && strlen( $tail ) == 2 )
1754
- $rv = $rv."0";
1755
- else if( !empty( $tail ) && strlen( $tail ) == 1 )
1756
- $rv = $rv."00";
1757
- else if( !$tail )
1758
- $rv = $rv.".00";
 
 
1759
  return $rv;
1760
  }
1761
 
1762
- private function _formatQty( $qty ){
1763
- $tail = strrchr( $qty, "." );
1764
- if( !empty( $tail ) )
1765
- $qty = substr( $qty, 0, strlen( $qty ) - strlen( $tail ) );
 
1766
  return $qty;
1767
  }
1768
-
1769
- private function _formatImageURL( $str ){
1770
- if( $str[0] != '/' )
1771
- $str = "/".$str;
 
1772
  return $str;
1773
  }
1774
-
1775
- private function _getTierPrices( &$product ){
1776
- $res="";
1777
  $prices = $product->getFormatedTierPrice();
1778
- if( $this->_DEBUG && isset( $prices ) ) echo "public tier prices: ".var_export( $prices, true )."
1779
- ";
 
 
1780
  $rightstr = "";
1781
- if( is_array( $prices ) ){
1782
- $count = count( $prices );
1783
- if( $count > 0 ){
1784
  $prodFinalPrice = $this->includetaxes ?
1785
- $this->taxhelper->getPrice( $product, $product->getData('price'), true, null, null, null, $this->StoreId ) :
1786
- $product->getData('price');
1787
- if( $this->_DEBUG ) echo "prodFinalPrice: ".$prodFinalPrice."
1788
- ";
1789
- $res='[TierPriceTable]#$$#'.$this->quantitylabel.'#$#'.$this->pricelabel.'#$#'.$this->savingslabel."=";
1790
- $i = 1;
1791
- foreach( $prices as $price ){
 
 
1792
  $price['price_qty'] = $price['price_qty'] * 1;
1793
  $tierPrice = $this->includetaxes ?
1794
- $this->taxhelper->getPrice( $product, $price['price'], true, null, null, null, $this->StoreId ) :
1795
- $price['price'];
1796
- if( $tierPrice < $prodFinalPrice ){
1797
- $tierPrice = $this->_formatPrice( "".$tierPrice );
1798
- $rightstr .= $price['price_qty'].'#$#';
1799
- $rightstr.=$tierPrice.'#$#';
1800
- if( $i == $count )
1801
- $rightstr .= ceil(100 - (( 100/$prodFinalPrice ) * $tierPrice )).'%';
1802
- else
1803
- $rightstr .= ceil(100 - (( 100/$prodFinalPrice ) * $tierPrice )).'%#$$#';
 
1804
  }
1805
  $i++;
1806
  }
1807
  }
1808
- if( empty( $rightstr ) ){
1809
- $res="";
1810
  }
1811
  }
1812
- unset( $prices );
1813
- if( $this->getgroupprices ){
1814
  $pairs = array();
1815
- if( !empty( $res ) ){
1816
- $pairs[] = $res.$rightstr;
1817
  }
1818
  $prices = $product->getData('tier_price');
1819
- if( $this->_DEBUG && isset( $prices ) ) echo "all tier prices: ".var_export( $prices, true )."
1820
- ";
1821
- foreach( $this->customerGroups as $gid => $gname ){
1822
- if( $this->_DEBUG ) echo "group: ".$gid."=>".$gname."
1823
- ";
1824
- if( $gid == 0 ){
 
 
 
 
1825
  continue;
1826
  }
1827
- $res="";
1828
  $rightstr = "";
1829
  $gprices = array();
1830
- foreach( $prices as $price ){
1831
- if( $price[ 'all_groups' ] == '1' || $price[ 'cust_group' ] == $gid ){
1832
  $gprices[] = $price;
1833
  }
1834
  }
1835
- $count = count( $gprices );
1836
- if( $count > 0 ){
1837
- if( !isset( $prodFinalPrice ) ){
1838
  $prodFinalPrice = $this->includetaxes ?
1839
- $this->taxhelper->getPrice( $product, $product->getData('price'), true, null, null, null, $this->StoreId ) :
1840
- $product->getData('price');
1841
- if( $this->_DEBUG ) echo "prodFinalPrice: ".$prodFinalPrice."
1842
- ";
 
 
1843
  }
1844
- $res='[TierPriceTable_'.$gname.']#$$#'.$this->quantitylabel.'#$#'.$this->pricelabel.'#$#'.$this->savingslabel."=";
1845
- $i = 1;
1846
- foreach( $gprices as $price ){
1847
  $price['price_qty'] = $price['price_qty'] * 1;
1848
  $tierPrice = $this->includetaxes ?
1849
- $this->taxhelper->getPrice( $product, $price['price'], true, null, null, null, $this->StoreId ) :
1850
- $price['price'];
1851
- if( $tierPrice < $prodFinalPrice ){
1852
- $tierPrice = $this->_formatPrice( "".$tierPrice );
1853
- $rightstr .= $price['price_qty'].'#$#';
1854
- $rightstr.=$tierPrice.'#$#';
1855
- if( $i == $count )
1856
- $rightstr .= ceil(100 - (( 100/$prodFinalPrice ) * $tierPrice )).'%';
1857
- else
1858
- $rightstr .= ceil(100 - (( 100/$prodFinalPrice ) * $tierPrice )).'%#$$#';
 
1859
  }
1860
  $i++;
1861
  }
1862
  }
1863
- if( !empty( $rightstr ) ){
1864
- $pairs[] = $res.$rightstr;
1865
  }
1866
  }
1867
- return count ( $pairs ) > 0 ? implode( "|", $pairs ) : FALSE;
1868
- } else return $res.$rightstr;
 
1869
  }
1870
 
1871
  // Class=CatalogSection
1872
- public function renderCatalogSection(){
1873
  $categories = Mage::getModel('catalog/category')
1874
- ->setStoreId( $this->StoreId )
1875
- ->getCollection()
1876
- ->addAttributeToSelect('name')
1877
- ->addAttributeToFilter('level', array('eq' => 2))
1878
- ->addAttributeToFilter('is_active', array('eq' => 1))
1879
- ->addAttributeToSort('position', 'asc');
1880
- $i = 1;
1881
- $count = count( $categories );
1882
- if( $this->_DEBUG ) echo "StoreId: ".$this->StoreId." Top categories: ".$count."
1883
- ";
1884
- echo "sec_Project\tsec_Sequence\tsec_HierarchyPath\tsec_Flag\n";
1885
- if( $count > 0 ){
1886
- if( $this->ignoretopcategory ){
1887
- foreach( $categories as $topcategory ){
 
 
1888
  $children = $topcategory->getCollection();
1889
- $children->setStoreId( $this->StoreId )
1890
  ->addAttributeToSelect('name')
1891
  ->addAttributeToFilter('is_active', array('eq' => 1))
1892
  ->addAttributeToSort('position', 'asc')
1893
  ->addIdFilter($topcategory->getChildren())
1894
- ->load();
1895
- foreach( $children as $category ){
1896
  $name = $category->getName();
1897
  $id = $category->getId();
1898
- echo $this->_drawCategory( $category, 1, $name, $i );
1899
  $i++;
1900
  }
1901
  }
1902
- }else{
1903
- foreach( $categories as $category ){
1904
  $name = $category->getName();
1905
  $id = $category->getId();
1906
- echo $this->_drawCategory( $category, 1, $name, $i );
1907
  $i++;
1908
  }
1909
  }
1910
  }
1911
  $lastId = $i;
1912
- echo "General\t".$lastId."\tUncategorized\t
1913
- ";
1914
- echo "==EOF==";
1915
  }
1916
 
1917
- private function _drawCategory( &$category, $level=0, $hpath='', $i=1, $j=1, $path='' ){
1918
  $html = "";
1919
  $children = $category->getCollection();
1920
- $children->setStoreId( $this->StoreId )
1921
  ->addAttributeToSelect('name')
1922
  ->addAttributeToFilter('is_active', array('eq' => 1))
1923
  ->addAttributeToSort('position', 'asc')
1924
  ->addIdFilter($category->getChildren())
1925
- ->load();
1926
- $id = $category->getId();
1927
  $sec_path = "";
1928
- if( $level != 1 ){
1929
  $path .= '-' . $j;
1930
- $hpath = $hpath.'#$#'.$category->getName(); //.' '.$i.$path;
1931
- $sec_path .= str_replace( "-", ",", $path );
1932
- $seq = $i.$sec_path;
1933
- }else{
1934
  $hpath = $category->getName(); //.' '.$i;
1935
  $seq = $i;
1936
  }
1937
- $html = "General\t".$seq."\t".$hpath."\t\n";
1938
  $htmlChildren = "";
1939
- if( count( $children ) ){
1940
  $j = 1;
1941
- foreach( $children as $cat ){
1942
- $htmlChildren .= $this->_drawCategory( $cat, $level + 1, $hpath, $i, $j, $path );
1943
  $j++;
1944
  }
1945
  }
1946
- unset( $children );
1947
  return $html .= $htmlChildren;
1948
  }
1949
 
1950
  // Class=CatalogProject
1951
- public function renderCatalogProject(){
1952
- if( $this->splitgroupedproducts ){
1953
  $this->productTypeGroupedModel = Mage::getModel('catalog/product_type_grouped');
1954
  }
1955
  $this->productTypeConfigurableModel = Mage::getModel('catalog/product_type_configurable');
 
1956
  $categories = Mage::getModel('catalog/category')
1957
- ->setStoreId( $this->StoreId )
1958
- ->getCollection()
1959
- ->addAttributeToSelect('name')
1960
- ->addAttributeToFilter('level', array('eq' => 2))
1961
- ->addAttributeToFilter('is_active', array('eq' => 1))
1962
- ->addAttributeToSort('position', 'asc');
1963
- $count = count( $categories );
1964
- if( $this->_DEBUG ) echo "StoreId: ".$this->StoreId." Top categories: ".$count."
1965
- ";
1966
- if( $count > 0 ){
 
 
 
1967
  $hpath = "";
1968
- if( $this->ignoretopcategory ){
1969
- foreach( $categories as $topcategory ){
 
 
 
 
 
 
1970
  $children = $topcategory->getCollection();
1971
- $children->setStoreId( $this->StoreId )
1972
  ->addAttributeToSelect('name')
 
1973
  ->addAttributeToFilter('is_active', array('eq' => 1))
1974
  ->addAttributeToSort('position', 'asc')
1975
  ->addIdFilter($topcategory->getChildren())
1976
- ->load();
1977
- foreach( $children as $category ){
1978
- $this->catmap[ $category->getId() ] = $category;
1979
- $this->_processCategory( $category, 1, $hpath );
 
 
 
 
 
 
 
 
1980
  }
1981
  }
1982
- }else{
1983
- foreach( $categories as $category ){
1984
- $this->catmap[ $category->getId() ] = $category;
1985
- $this->_processCategory( $category, 1, $hpath );
 
 
 
 
 
 
 
 
1986
  }
1987
  }
1988
  }
1989
  $this->unCatPosition = 1;
1990
- if( $this->start == 0 ) echo "proj_Key\tproj_ProdName\tproj_Sequence\tproj_Name\tproj_HierarchyPath\tproj_Flag\tproj_ProdLayout
1991
- ";
1992
- $products = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->getCollection();
1993
- $products->addAttributeToFilter('status', 1);//enabled
1994
- $products->addAttributeToFilter('visibility', 4);//catalog, search
1995
- $prodIds = $this->_DEBUG ? $products->getAllIds(1000,0) : $products->getAllIds();
1996
- if( $this->_DEBUG ) echo "StoreId: ".$this->StoreId."
1997
- Products: ".count( $prodIds )."
1998
- ";
 
 
 
1999
  $count = 0;
2000
  $index = 0;
2001
  $lastLine = "==EOF==
2002
  ";
2003
- foreach( $prodIds as $productId ){
2004
- if( $count == $this->pageSize ){
2005
  $lastLine = "==MORE==
2006
  ";
2007
  break;
2008
  }
2009
- if( $index < $this->start ){
2010
  $index++;
2011
  continue;
2012
  }
2013
  $index++;
2014
- $product = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $productId );
2015
- if( $product->isConfigurable() ){
2016
- echo $this->CatalogProjectStringConfigurable( $product );
2017
- } else if( $product->isGrouped() && $this->splitgroupedproducts ){
2018
- echo $this->CatalogProjectStringGroupedAsSimple( $product );
2019
  } else {
2020
- echo $this->CatalogProjectStringGroupedOrSimple( $product );
 
 
 
 
 
2021
  }
2022
- unset( $product );
2023
- if( $this->_DEBUG ) echo "#".$count.": memory_get_usage ".memory_get_usage()." / ".memory_get_usage(TRUE)."
2024
- ";
2025
  $count++;
2026
  }
2027
- echo $lastLine;
2028
  }
2029
 
2030
- private function _processCategory( &$category, $level=0, $hpath='', $path='' ){
2031
- $hpath = $level != 1 ? $hpath.'#$#'.$category->getName() : $hpath = $category->getName();
2032
- $this->catpathmap[ $category->getId() ] = $hpath;
2033
- if( $this->_DEBUG ) echo "Category: ".$category->getId()." path=".$hpath."
2034
- ";
 
 
2035
  $children = $category->getCollection();
2036
- $children->setStoreId( $this->StoreId )
2037
  ->addAttributeToSelect('name')
 
2038
  ->addAttributeToFilter('is_active', array('eq' => 1))
2039
  ->addAttributeToSort('position', 'asc')
2040
  ->addIdFilter($category->getChildren())
2041
- ->load();
2042
  $htmlChildren = "";
2043
- if( count( $children ) ) foreach( $children as $childcategory ){
2044
- $this->catmap[ $childcategory->getId() ] = $childcategory;
2045
- $htmlChildren .= $this->_processCategory( $childcategory, $level + 1, $hpath, $path );
2046
- }
 
 
 
 
 
 
 
 
 
 
2047
  }
2048
 
2049
- private function CatalogProjectStringGroupedOrSimple( &$product ){
2050
  $ProducttoString = "";
2051
  $categoryIds = $product->getCategoryIds();
2052
  $listed = FALSE;
2053
- if( $categoryIds ){
2054
- foreach( $categoryIds as $k => $category_id ){
2055
- if( !isset( $this->catmap[ $category_id ] ) ){
2056
- if( $this->_DEBUG ) echo "No category: ".$category_id."
2057
- ";
 
 
2058
  continue;
2059
  }
2060
- $category = $this->catmap[ $category_id ];
2061
- $hpath = $this->catpathmap[ $category_id ];
2062
  $position = "";
2063
  $positions = $category->getProductsPosition();
2064
- if( count( $positions ) > 0 )
2065
- $position = $positions[ $product->getId() ];
2066
- $productName = $product->getName();
2067
- $ProducttoString .= $product->getId().'#$#'.$this->_cleanStr( $productName ) //ProductKey
2068
- . "\t" . $product->getId().'#$#'.$this->_cleanStr( $productName ) //Product Name
2069
- . "\t" . $position //Prod Sequence
2070
- . "\tGeneral" //Proj Name
2071
- . "\t" . $hpath //Hirarachi Path
2072
- . "\t" //Proj Flag
2073
- . "\t" //Proj Prod layout
2074
- . "\n";
 
 
 
 
 
 
 
2075
  $listed = TRUE;
2076
  }
2077
  }
2078
- if( !$listed ){
2079
- $productName = $product->getName();
2080
- $ProducttoString .= $product->getId().'#$#'.$this->_cleanStr( $productName ) //ProductKey
2081
- . "\t" . $product->getId().'#$#'.$this->_cleanStr( $productName ) //Product Name
2082
- . "\t" . $this->unCatPosition //Prod Sequence
2083
- . "\tGeneral" //Proj Name
2084
- . "\tUncategorized" //Hirarachi Path
2085
- . "\t" //Proj Flag
2086
- . "\t" //Proj Prod layout
2087
- . "\n";
 
2088
  $this->unCatPosition++;
2089
  }
2090
  return $ProducttoString;
2091
  }
2092
 
2093
- private function CatalogProjectStringGroupedAsSimple( &$product ){
2094
- $ProducttoString = "";
2095
- $categoryIds = $product->getCategoryIds();
2096
- $listed = FALSE;
2097
- if( $categoryIds ){
2098
- $prodNames = array();
2099
- $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds( $product );
2100
- foreach( $AssociatedProductIds as $UsedProductid ){
2101
- $UsedProduct = Mage::getModel('catalog/product')->setStoreId( $this->StoreId )->load( $UsedProductid );
2102
- if( $UsedProduct->getStatus() == 1 ){
2103
- $prodName = $UsedProduct->getName();
2104
- $prodNames[] = $UsedProduct->getId().'#$#'.$this->_cleanStr( $prodName );
2105
- } else {
2106
- if( $this->_DEBUG ) echo "sku=".$UsedProduct->getSku()." enabled=".$UsedProduct->getStatus()." - bypassed.
2107
- ";
2108
  }
2109
- unset( $UsedProduct );
2110
  }
2111
- if( count( $prodNames ) == 0 )
2112
- return $ProducttoString;
2113
- foreach( $categoryIds as $k => $category_id ){
2114
- if( !isset( $this->catmap[ $category_id ] ) ){
2115
- if( $this->_DEBUG ) echo "No category: ".$category_id."
2116
- ";
 
 
 
 
 
 
 
 
2117
  continue;
2118
  }
2119
- $category = $this->catmap[ $category_id ];
2120
- $hpath = $this->catpathmap[ $category_id ];
2121
  $position = "";
2122
  $positions = $category->getProductsPosition();
2123
- if( count( $positions ) > 0 )
2124
- $position = $positions[ $product->getId() ];
2125
- foreach( $prodNames as $prodName ){
2126
- $ProducttoString .= $prodName //ProductKey
2127
- . "\t" . $prodName //Product Name
2128
- . "\t" . $position //Prod Sequence
2129
- . "\tGeneral" //Proj Name
2130
- . "\t" . $hpath //Hirarachi Path
2131
- . "\t" //Proj Flag
2132
- . "\t" //Proj Prod layout
2133
- . "\n";
 
 
 
 
2134
  $position += 0.001;
2135
  }
2136
  $listed = TRUE;
2137
  }
2138
  }
2139
- if( !$listed ){
2140
- foreach( $prodNames as $prodName ){
2141
- $ProducttoString .= $prodName //ProductKey
2142
- . "\t" . $prodName //Product Name
2143
- . "\t" . $this->unCatPosition //Prod Sequence
2144
- . "\tGeneral" //Proj Name
2145
- . "\tUncategorized" //Hirarachi Path
2146
- . "\t" //Proj Flag
2147
- . "\t" //Proj Prod layout
2148
- . "\n";
 
 
2149
  $this->unCatPosition++;
2150
  }
2151
  }
 
 
 
2152
  return $ProducttoString;
2153
  }
2154
 
2155
- private function CatalogProjectStringConfigurable( &$product ){
2156
  $UsedProductIds = $this->productTypeConfigurableModel->getUsedProductIds($product);
2157
- $countUsedProductIds = count( $UsedProductIds );
2158
- if( $countUsedProductIds > 0 ){
2159
  $listed = FALSE;
2160
  $ProducttoString = "";
2161
  $categoryIds = $product->getCategoryIds();
2162
- if( $categoryIds ){
2163
- foreach( $categoryIds as $k => $category_id ){
2164
- if( !isset( $this->catmap[ $category_id ] ) ){
2165
- if( $this->_DEBUG ) echo "No category: ".$category_id."
2166
- ";
 
 
2167
  continue;
2168
  }
2169
- $category = $this->catmap[ $category_id ];
2170
- $hpath = $this->catpathmap[ $category_id ];
2171
  $position = "";
2172
  $positions = $category->getProductsPosition();
2173
- if( count( $positions ) > 0 )
2174
- $position = $positions[ $product->getId() ];
2175
- $productName = $product->getName();
2176
- $ProducttoString .= $product->getId().'#$#'. $this->_cleanStr( $productName ) //ProductKey
2177
- . "\t" . $product->getId().'#$#'.$this->_cleanStr( $productName ) //Product Name
2178
- . "\t" . $position //Prod Sequence
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2179
  . "\tGeneral" //Proj Name
2180
- . "\t" . $hpath //Hirarachi Path
2181
- . "\t" //Proj Flag
2182
- . "\t" //Proj Prod layout
2183
  . "\n";
2184
- $listed = TRUE;
2185
- }
2186
- }
2187
- if( !$listed ){
2188
- $productName = $product->getName();
2189
- $ProducttoString .= $product->getId().'#$#'.$this->_cleanStr( $productName ) //ProductKey
2190
- . "\t" . $product->getId().'#$#'.$this->_cleanStr( $productName ) //Product Name
2191
- . "\t" . $this->unCatPosition //Prod Sequence
2192
- . "\tGeneral" //Proj Name
2193
- . "\tUncategorized" //Hirarachi Path
2194
- . "\t" //Proj Flag
2195
- . "\t" //Proj Prod layout
2196
- . "\n";
2197
  $this->unCatPosition++;
2198
- }
2199
- } else
2200
  $ProducttoString = "";
2201
- unset( $UsedProductIds );
 
2202
  return $ProducttoString;
2203
  }
2204
- } // Mage_CodiScript_Model_Files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+
3
+ // 2016-05-30
4
+ class ConfiguredProductLine {
5
+
6
  public $optionIds = array();
7
  public $line = NULL;
8
+
9
  }
10
+
11
+ class COption {
12
+
13
  public $id = NULL;
14
  public $title = NULL;
15
  public $type = NULL;
16
  public $required = NULL;
17
  public $values = array();
18
+
19
+ public function toString() {
20
+ return "COption #" . $this->id . " title=" . $this->title . " type=" . $this->type . " required=" . $this->required . " values=" . count($this->values);
21
  }
22
+
23
  }
24
+
25
+ class COValue {
26
+
27
  public $title = NULL;
28
  public $sku = NULL;
29
  public $rprice = NULL;
30
  public $sprice = NULL;
31
+
32
+ public function toString() {
33
+ return "COValue " . $this->title . " sku=" . $this->sku . " rprice=" . $this->rprice . " sprice=" . $this->sprice;
34
  }
35
+
36
  }
37
+
38
+ class COValueSet {
39
+
40
  public $optionId = NULL;
41
  public $coValues = array();
42
+
43
+ public function toString() {
44
+ $out = "COValueSet #" . $this->optionId . " ";
45
+ foreach ($this->coValues as $value) {
46
+ $out .= $value->sku ? "-" . $value->sku : "-...";
47
+ }
48
  return $out;
49
  }
50
+
51
  }
52
+
53
  class Mage_CodiScript_Model_Files extends Mage_Core_Model_Abstract {
54
+
55
  public $version = __VERSION__;
56
+ public $controller;
57
  public $Store;
58
  public $StoreId;
59
  public $reviewsModel;
94
  public $catpathmap;
95
  public $catmap;
96
  public $catpositions = FALSE;
97
+ public $storeSorting = "position";
98
  public $_DEBUG;
99
+
100
  const TAG_P_CLOSE = '</p>';
101
  const TAG_P = '<p>';
102
  const SCRIPTNAME = __SCRIPTNAME__;
103
 
104
  public function _construct() {
105
  parent::_construct();
106
+ $this->_init('codi/codi2');
107
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
108
+ }
109
+
110
+ // Class=Settings
111
+ public function renderConfiguration() {
112
+ $this->controller->getResponse()->appendBody("Configuration: start
113
+ ProductListDefaultSortBy: " . Mage::getSingleton('catalog/config')->getProductListDefaultSortBy($this->StoreId) . "
114
+ Configuration: end
115
+ ");
116
  }
117
 
118
  // Class=DataFile
119
+ public function renderDataFile() {
120
+ if ($this->_DEBUG) {
121
+ $this->controller->getResponse()->appendBody("memory_get_usage real: " . memory_get_usage(TRUE) . " allocated: " . memory_get_usage() . "
122
+ ");
123
+ foreach (Mage::app()->getStores() as $store) {
124
+ $this->controller->getResponse()->appendBody("store: " . $store->getId() . " code=" . $store->getCode() . " isActive=" . $store->getIsActive() . "
125
+ ");
126
+ }
127
  }
128
  $this->productTypeConfigurableModel = Mage::getModel('catalog/product_type_configurable');
129
  $this->productTypeGroupedModel = Mage::getModel('catalog/product_type_grouped');
130
+ $this->reviewsModel = Mage::getModel('review/review')->setStoreId($this->StoreId);
131
+ $this->catalogInventoryModel = Mage::getModel('cataloginventory/stock_item')->setStoreId($this->StoreId);
132
+ $this->mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
133
+ $this->prodmediaurl = $this->mediaurl . "catalog/product";
134
  $this->mageVersionArray = Mage::getVersionInfo();
135
+ if ($this->_DEBUG) {
136
+ $this->controller->getResponse()->appendBody("mageVersionArray: major " . $this->mageVersionArray['major'] . " minor " . $this->mageVersionArray['minor'] . "
137
+ ");
138
+ }
139
+ if ($this->publishtieredpricing || $this->getgroupprices) {
140
  $this->customerGroups = array();
141
  $customerGroups = Mage::getModel('customer/group')->getCollection();
142
+ foreach ($customerGroups as $cg) {
143
  $this->customerGroups[$cg->_data['customer_group_id']] = $cg->_data['customer_group_code'];
144
+ if ($this->_DEBUG) {
145
+ $this->controller->getResponse()->appendBody("customer group #" . $cg->_data['customer_group_id'] . "-" . $cg->_data['customer_group_code'] . "
146
+ ");
147
+ }
148
  }
149
  }
150
+ $products = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->getCollection();
151
+ $products->addAttributeToFilter('status', 1); //enabled
152
+ $products->addAttributeToFilter('visibility', 4); //catalog, search
153
  $prodIds = $products->getAllIds();
154
+ if ($this->_DEBUG) {
155
+ $this->controller->getResponse()->appendBody("StoreId: " . $this->StoreId . "
156
+ Products: " . count($prodIds) . "
157
+ Media URL: " . $this->mediaurl . "
158
+ memory_get_usage " . memory_get_usage() . " / " . memory_get_usage(TRUE) . "
159
+ ");
160
+ }
161
+ if ($this->start == 0) {
162
+ $this->controller->getResponse()->appendBody("itemNumber\titemQty\titemUom\titemPrice\titemDescription\titemLink\titemAttributes\titemGraphic\tproductName\tproductDescription\tproductGraphic\tproductLink\tproductAttributes\tManufacturer\tCategory\tReviews\tSupplementalInfo\titemSequence
163
+ ");
164
+ }
165
  $count = 0;
166
  $index = 0;
167
  $lastLine = "==EOF==
168
  ";
169
+ foreach ($prodIds as $productId) {
170
+ if ($count == $this->pageSize) {
171
  $lastLine = "==MORE==
172
  ";
173
  break;
174
  }
175
+ if ($index < $this->start) {
176
  $index++;
177
  continue;
178
  }
179
  $index++;
180
+ $product = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($productId);
181
+ if ($this->_DEBUG) {
182
+ $this->controller->getResponse()->appendBody("== PRODUCT: " . $product->getTypeId() . " == " . $product->getId() . "-" . $product->getName() . " ==
183
+ ");
184
+ }
185
+ if ($product->isConfigurable()) {
186
+ $this->controller->getResponse()->appendBody($this->ProducttoStringConfigurable($product));
187
+ } else if ($product->isGrouped()) {
188
+ if ($this->splitgroupedproducts) {
189
+ $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds($product);
190
+ foreach ($AssociatedProductIds as $UsedProductid) {
191
+ $_product = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($UsedProductid);
192
+ $this->controller->getResponse()->appendBody($this->ProducttoStringSimple($_product));
193
  }
194
  } else {
195
+ $this->controller->getResponse()->appendBody($this->ProducttoStringGrouped($product));
196
  }
197
+ } else {
198
+ $this->controller->getResponse()->appendBody($this->ProducttoStringSimple($product));
199
+ }
200
+ unset($product);
201
+ if ($this->_DEBUG) {
202
+ $this->controller->getResponse()->appendBody("#" . $count . ": memory_get_usage " . memory_get_usage() . " / " . memory_get_usage(TRUE) . "
203
+ ");
204
  }
 
 
 
 
 
205
  $count++;
206
  }
207
+ $this->controller->getResponse()->appendBody($lastLine);
208
  }
209
 
210
+ private function ProducttoStringGrouped(&$product) {
211
  $ProducttoString = "";
212
+ $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds($product);
213
  $ProductDescription = "";
214
  $shortDescription = "";
215
+ if ($this->includeshortdescription) {
216
  $shortDescription = $product->getShortDescription();
217
+ if (!empty($shortDescription)) {
218
+ $shortDescription = $this->_cleanStr($shortDescription);
219
+ if (strpos($shortDescription, self::TAG_P) !== false) {
220
+ $new = strlen($shortDescription);
221
+ $pos = strrpos($shortDescription, self::TAG_P_CLOSE) + 4;
222
+ if ($new != $pos) {
223
+ $shortDescription = substr($shortDescription, 0, $pos) . self::TAG_P . substr($shortDescription, $pos) . self::TAG_P_CLOSE;
224
+ }
225
+ } else {
226
+ $shortDescription = self::TAG_P . $shortDescription . self::TAG_P_CLOSE;
227
+ }
228
+ $ProductDescription = $shortDescription;
229
+ }
230
+ }
231
+ if ($this->includelongdescription) {
232
  $longDescription = $product->getDescription();
233
+ if (!empty($longDescription)) {
234
+ $longDescription = $this->_cleanStr($longDescription);
235
+ if (strpos($longDescription, self::TAG_P) !== false) {
236
+ $new = strlen($longDescription);
237
+ $pos = strrpos($longDescription, self::TAG_P_CLOSE) + 4;
238
+ if ($new != $pos) {
239
+ $longDescription = substr($longDescription, 0, $pos) . self::TAG_P . substr($longDescription, $pos) . self::TAG_P_CLOSE;
240
+ }
241
+ } else {
242
+ $longDescription = self::TAG_P . $longDescription . self::TAG_P_CLOSE;
243
+ }
244
+ $ProductDescription .= $longDescription;
245
  }
246
  }
247
  $attributes = $product->getAttributes();
248
  $Manufacturer = "";
249
  $ProductAttributes = "";
250
+ foreach ($attributes as $attribute) {
251
+ $attribute->setStoreId($this->StoreId);
252
+ if ($this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" )) {
253
  $hasData = $product->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
254
+ $this->controller->getResponse()->appendBody("grouped prod attr: " . $attribute->getFrontend()->getLabel() . "=" . $attribute->getFrontend()->getValue($product) . " input=" . $attribute->getFrontendInput() . " data=" . $product->getData($attribute->getAttributeCode()) . " hasData=" . $hasData . "
255
+ ");
256
  }
257
+ if ($attribute->getAttributeCode() == "manufacturer") {
258
+ if ($product->getData($attribute->getAttributeCode())) {
259
+ $Manufacturer = $attribute->getFrontend()->getValue($product);
260
+ } else {
261
  $Manufacturer = "";
262
+ }
263
  continue;
264
  }
265
+ if ($attribute->getIsVisibleOnFront() ||
266
+ ( $this->includecustomfields && array_key_exists(strtolower($attribute->getAttributeCode()), $this->includecustomfields) )) {
267
+ $value = $attribute->getFrontend()->getValue($product);
268
+ if ($attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect") {
269
+ $hasData = $product->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
270
+ if (!$hasData) {
271
  $value = "";
272
+ }
273
  }
274
+ if (is_string($value) && strlen($value)) {
275
+ if (!empty($ProductAttributes)) {
276
  $ProductAttributes .= "|";
277
+ }
278
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
279
  }
280
  }
281
  }
282
+ if ($this->publishtieredpricing == "1") {
283
+ $TierPriceAttributes = $this->_getTierPrices($product);
284
+ $sp = ( empty($ProductAttributes) || empty($TierPriceAttributes) ) ? "" : "|";
285
+ $ProductAttributes .= $sp . $TierPriceAttributes;
286
  }
287
+ if ($this->importoptionsasattributes) {
288
+ $optionsAsAttributes = $this->_getCustomOptionsAsAttributes($product);
289
+ if (!empty($optionsAsAttributes)) {
290
+ if (!empty($ProductAttributes)) {
291
  $ProductAttributes .= "|";
292
+ }
293
  $ProductAttributes .= $optionsAsAttributes;
294
  }
295
  }
296
+ if (!empty($ProductAttributes)) {
297
+ $ProductAttributes = $this->_cleanStr($ProductAttributes);
298
+ }
299
+ if ($this->_DEBUG) {
300
+ $this->controller->getResponse()->appendBody("product image: " . $product->getImage() . "
301
+ small image: " . $product->getSmallImage() . "
302
+ thumbnail: " . $product->getThumbnail() . "
303
+ ");
304
+ }
305
+ $prodImages = array();
306
+ $firstImageFile = trim($product->getImage());
307
+ if ($firstImageFile == "no_selection") {
308
  $firstImageFile = FALSE;
309
+ }
310
+ if ($firstImageFile) {
311
+ $prodImages[] = "MagentoBase#=#" . $this->prodmediaurl . $this->_formatImageURL($firstImageFile);
312
+ }
313
+ $prodImageArray = $product->getMediaGallery('images');
314
+ if (is_array($prodImageArray)) {
315
+ foreach ($prodImageArray as $image) {
316
+ $imageFile = trim($image['file']);
317
+ if ($this->_DEBUG) {
318
+ $this->controller->getResponse()->appendBody("gallery image: " . $imageFile . " disabled=" . $image['disabled'] . "
319
+ ");
320
+ }
321
+ if (!$imageFile || $imageFile == $firstImageFile) {
322
  continue;
323
+ }
324
+ if ($this->ignoreexcludedimages && $image['disabled']) {
325
  continue;
326
+ }
327
+ $prodImages[] = "Print#=#" . $this->prodmediaurl . $this->_formatImageURL($imageFile);
328
  }
329
  }
330
+ $prodImages = implode("#|#", $prodImages);
331
  $ProductURL = $product->getProductUrl();
332
+ if (!empty($ProductURL)) {
333
+ $ProductURL = $this->_correctProdUrlStr($ProductURL);
334
+ }
335
  $productName = $product->getName();
336
+ $productName = $product->getId() . '#$#' . $this->_cleanStr($productName);
337
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
338
+ if (!empty($Reviews)) {
339
+ $Reviews = $this->_cleanStr($Reviews);
340
+ }
341
+ if ($this->_DEBUG) {
342
+ $this->controller->getResponse()->appendBody("associated IDs: ");
343
+ foreach ($AssociatedProductIds as $UsedProductid) {
344
+ $this->controller->getResponse()->appendBody("" . $UsedProductid . " ");
345
+ }
346
+ $this->controller->getResponse()->appendBody("
347
+ ");
348
  }
349
  $sequence = 1;
350
  $UsedProducts = array();
351
+ foreach ($AssociatedProductIds as $UsedProductid) {
352
+ $UsedProduct = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($UsedProductid);
353
+ if ($UsedProduct->getStatus() == 1) {
354
  $UsedProducts[] = $UsedProduct;
355
  } else {
356
+ if ($this->_DEBUG) {
357
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " enabled=" . $UsedProduct->getStatus() . " - bypassed.
358
+ ");
359
+ }
360
+ unset($UsedProduct);
361
  }
362
  }
363
  $renderSPrice = FALSE;
364
+ if ($this->includespecialprice) {
365
+ foreach ($UsedProducts as $UsedProduct) {
366
  $SPrice = $UsedProduct->getSpecialPrice();
367
+ if (trim($SPrice) != "") {
368
  $renderSPrice = TRUE;
369
  break;
370
  }
371
  }
372
  }
373
+ foreach ($UsedProducts as $UsedProduct) {
374
+ if ($this->instockonly) {
375
+ $inventory = $this->catalogInventoryModel->loadByProduct($UsedProduct);
376
  $qty = $inventory->getQty();
377
  $minQty = $inventory->getMinQty();
378
+ if ($qty <= $minQty) {
379
+ if ($this->_DEBUG) {
380
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " enabled=" . $UsedProduct->getStatus() . " qty=" . $qty . " minQty=" . $minQty . " - bypassing.
381
+ ");
382
+ }
383
  continue;
384
  }
385
  }
386
+ if ($this->_DEBUG) {
387
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " enabled=" . $UsedProduct->getStatus() . " prices: Regular=" . $UsedProduct->getData('price') . " Final=" . $UsedProduct->getFinalPrice() . " Special=" . $UsedProduct->getSpecialPrice() . " FromDate=" . $UsedProduct->getSpecialFromDate() . " ToDate=" . $UsedProduct->getSpecialToDate() . "
388
+ ");
389
+ }
390
+ $ItemName = $UsedProduct->getName();
391
  $ProdRPrice = $UsedProduct->getData('price');
392
  $ProdSPrice = $UsedProduct->getSpecialPrice();
393
  $ProdSFromDate = $UsedProduct->getSpecialFromDate();
394
  $ProdSToDate = $UsedProduct->getSpecialToDate();
395
  $ProdGroupPrices = FALSE;
396
+ if ($this->mageVersionArray['major'] > 1 || $this->mageVersionArray['minor'] > 6) {
397
  $ProdGroupPrices = $UsedProduct->getData('group_price');
398
+ if ($this->_DEBUG && count($ProdGroupPrices) > 0) {
399
+ $this->controller->getResponse()->appendBody("group_price: " . var_export($ProdGroupPrices, true) . "
400
+ ");
401
+ }
402
  }
403
  $ProdSpecGroupPrices = FALSE;
404
+ if ($ProdGroupPrices) {
405
  $ProdSpecGroupPrices = array();
406
+ foreach ($ProdGroupPrices as $groupPrice) {
407
+ if ($groupPrice['cust_group'] == '0') {
408
+ $notLoggedInPrice = 0.0 + $groupPrice['price'];
409
+ if (trim($ProdSPrice) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice) {
410
+ $ProdSPrice = $groupPrice['price'];
411
  $ProdSFromDate = FALSE;
412
  $ProdSToDate = FALSE;
413
  }
414
+ } else {
415
  $ProdSpecGroupPrices[] = $groupPrice;
416
+ }
417
  }
418
  }
419
+ if (trim($ProdSPrice) == "") {
420
  $ProdSPrice = -1;
421
  $ProdSFromDate = FALSE;
422
  $ProdSToDate = FALSE;
424
  $SFromDate = $ProdSFromDate;
425
  $SToDate = $ProdSToDate;
426
  $RPrice = $ProdRPrice;
427
+ if (!empty($RPrice) && $this->includetaxes) {
428
+ $RPrice = $this->taxhelper->getPrice($UsedProduct, $RPrice, true, null, null, null, $this->StoreId);
429
+ }
430
  $SPrice = $ProdSPrice;
431
+ if ($SPrice >= 0 && $this->includetaxes) {
432
+ $SPrice = $this->taxhelper->getPrice($UsedProduct, $SPrice, true, null, null, null, $this->StoreId);
433
+ }
434
+ if ($this->_DEBUG) {
435
+ $this->controller->getResponse()->appendBody("resulting prices: Regular=" . $RPrice . " Special=" . $SPrice . " FromDate=" . $SFromDate . " ToDate=" . $SToDate . "
436
+ ");
437
+ }
438
+ if ($this->ignoreassprodimages) {
439
+ $itemImages = "";
440
+ } else {
441
+ $itemImages = array();
442
+ $firstImageFile = trim($UsedProduct->getImage());
443
+ if ($firstImageFile == "no_selection") {
444
  $firstImageFile = FALSE;
445
+ }
446
+ if ($firstImageFile) {
447
+ $itemImages[] = "MagentoBase#=#" . $this->prodmediaurl . $this->_formatImageURL($firstImageFile);
448
+ }
449
  $itemImageArray = $UsedProduct->getMediaGallery('images');
450
+ if (is_array($itemImageArray)) {
451
+ foreach ($itemImageArray as $image) {
452
+ $imageFile = trim($image['file']);
453
+ if (!$imageFile || $imageFile == $firstImageFile) {
 
 
454
  continue;
455
+ }
456
+ if ($this->ignoreexcludedimages && $image['disabled']) {
457
  continue;
458
+ }
459
+ $itemImages[] = "Print#=#" . $this->prodmediaurl . $this->_formatImageURL($imageFile);
460
  }
461
  }
462
+ $itemImages = implode("#|#", $itemImages);
463
  }
464
  $attributes = $UsedProduct->getAttributes();
465
  $ItemAttributes = "";
466
+ foreach ($attributes as $attribute) {
467
+ $attribute->setStoreId($this->StoreId);
468
+ if ($this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" )) {
469
  $hasData = $UsedProduct->getData($attribute->getAttributeCode()) ? "YES" : "NO";
470
+ $this->controller->getResponse()->appendBody("grouped prod attr: " . $attribute->getFrontend()->getLabel() . "=" . $attribute->getFrontend()->getValue($UsedProduct) . " input=" . $attribute->getFrontendInput() . " data=" . $UsedProduct->getData($attribute->getAttributeCode()) . " hasData=" . $hasData . "
471
+ ");
472
  }
473
+ if ($attribute->getAttributeCode() == "manufacturer") {
474
+ if ($UsedProduct->getData($attribute->getAttributeCode())) {
475
+ $Manufacturer = $attribute->getFrontend()->getValue($UsedProduct);
476
+ }
477
  continue;
478
  }
479
+ if ($attribute->getIsVisibleOnFront() ||
480
+ ( $this->includecustomfields && array_key_exists(strtolower($attribute->getAttributeCode()), $this->includecustomfields) )) {
481
+ $value = $attribute->getFrontend()->getValue($UsedProduct);
482
+ if ($attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect") {
483
+ $hasData = $UsedProduct->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
484
+ if (!$hasData) {
485
  $value = "";
486
+ }
487
  }
488
+ if (is_string($value) && strlen($value)) {
489
  $ItemAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value . "|";
490
+ }
491
  }
492
  }
493
+ $ItemAttributes = substr($ItemAttributes, 0, strlen($ItemAttributes) - 1);
494
+ if ($this->includeinvqty) {
495
+ if (!empty($ItemAttributes)) {
496
  $ItemAttributes .= "|";
497
+ }
498
+ $ItemAttributes .= "Inventory=" . $this->_formatQty("" . $this->catalogInventoryModel->loadByProduct($UsedProduct)->getQty());
499
+ }
500
+ if ($this->publishtieredpricing == "1") {
501
+ $TierPriceAttributes = $this->_getTierPrices($UsedProduct);
502
+ $sp = ( empty($ItemAttributes) || empty($TierPriceAttributes) ) ? "" : "|";
503
+ $ItemAttributes .= $sp . $TierPriceAttributes;
504
+ }
505
+ $RPrice = $this->_formatPrice($RPrice);
506
+ if ($this->includespecialprice) {
507
+ if ($SPrice >= 0) {
508
+ $SPrice = $this->_formatPrice($SPrice);
509
+ if (!empty($ItemAttributes)) {
510
  $ItemAttributes .= "|";
511
+ }
512
+ $ItemAttributes .= "Special Price=" . $SPrice;
513
+ } else if ($renderSPrice) {
514
+ if (!empty($ItemAttributes)) {
515
  $ItemAttributes .= "|";
516
+ }
517
  $ItemAttributes .= "Special Price=";
518
  }
519
  }
520
+ if ($this->includespecialpricedatefrom) {
521
+ if (!empty($SFromDate)) {
522
+ if (!empty($ItemAttributes)) {
523
  $ItemAttributes .= "|";
524
+ }
525
+ $ItemAttributes .= "Special Price From Date=" . substr($SFromDate, 0, 10);
526
  }
527
  }
528
+ if ($this->includespecialpricedateto) {
529
+ if (!empty($SToDate)) {
530
+ if (!empty($ItemAttributes)) {
531
  $ItemAttributes .= "|";
532
+ }
533
+ $ItemAttributes .= "Special Price To Date=" . substr($SToDate, 0, 10);
534
  }
535
  }
536
+ if ($this->getgroupprices && $ProdSpecGroupPrices) {
537
+ foreach ($ProdSpecGroupPrices as $groupPrice) {
538
+ $price = 0.0 + $groupPrice['price'];
539
+ if ($price >= 0 && $this->includetaxes) {
540
+ $price = $this->taxhelper->getPrice($UsedProduct, $price, true, null, null, null, $this->StoreId);
541
+ }
542
+ if (!empty($ItemAttributes)) {
543
  $ItemAttributes .= "|";
544
+ }
545
+ $ItemAttributes .= "price_" . $this->customerGroups[$groupPrice['cust_group']] . "=" . $this->_formatPrice($price);
546
  }
547
  }
548
  $itemID = $UsedProduct->getSku();
549
+ $ProducttoString .= $this->_cleanStr($itemID) //ItemID
550
+ . "\t" //ItemQty
551
+ . "\t" //ItemUom
552
+ . "\t" . $RPrice //ItemPrice
553
+ . "\t" . $this->_cleanStr($ItemName) //ItemDescription
554
+ . "\t" //ItemLink
555
+ . "\t" . $this->_cleanStr($ItemAttributes) //ItemAttributes
556
+ . "\t" . $itemImages //ItemGraphic
557
+ . "\t" . $productName //ProductName
558
+ . "\t" . $ProductDescription
559
+ . "\t" . $prodImages //ProductGraphic
560
+ . "\t" . $ProductURL //ProductLink
561
+ . "\t" . $ProductAttributes //ProductAttributes
562
+ . "\t" . $Manufacturer //Manufacturer
563
+ . "\t" //Category
564
+ . "\t" . $Reviews //Reviews
565
+ . "\t" . $shortDescription
566
+ . "\t" . $sequence
567
+ . "\n";
568
+ unset($UsedProduct);
569
  $sequence++;
570
  }
571
+ unset($UsedProducts);
572
+ unset($AssociatedProductIds);
573
  return $ProducttoString;
574
  }
575
 
576
+ private function ProducttoStringConfigurable(&$product) {
577
  $UsedProductIds = $this->productTypeConfigurableModel->getUsedProductIds($product);
578
  $ProductDescription = "";
579
  $shortDescription = "";
580
+ if ($this->includeshortdescription) {
581
  $shortDescription = $product->getShortDescription();
582
+ if (!empty($shortDescription)) {
583
+ $shortDescription = $this->_cleanStr($shortDescription);
584
+ if (strpos($shortDescription, self::TAG_P) !== false) {
585
+ $new = strlen($shortDescription);
586
+ $pos = strrpos($shortDescription, self::TAG_P_CLOSE) + 4;
587
+ if ($new != $pos) {
588
+ $shortDescription = substr($shortDescription, 0, $pos) . self::TAG_P . substr($shortDescription, $pos) . self::TAG_P_CLOSE;
589
+ }
590
+ } else {
591
+ $shortDescription = self::TAG_P . $shortDescription . self::TAG_P_CLOSE;
592
+ }
593
+ $ProductDescription = $shortDescription;
594
+ }
595
+ }
596
+ if ($this->includelongdescription) {
597
  $longDescription = $product->getDescription();
598
+ if (!empty($longDescription)) {
599
+ $longDescription = $this->_cleanStr($longDescription);
600
+ if (strpos($longDescription, self::TAG_P) !== false) {
601
+ $new = strlen($longDescription);
602
+ $pos = strrpos($longDescription, self::TAG_P_CLOSE) + 4;
603
+ if ($new != $pos) {
604
+ $longDescription = substr($longDescription, 0, $pos) . self::TAG_P . substr($longDescription, $pos) . self::TAG_P_CLOSE;
605
+ }
606
+ } else {
607
+ $longDescription = self::TAG_P . $longDescription . self::TAG_P_CLOSE;
608
+ }
609
+ $ProductDescription .= $longDescription;
610
  }
611
  }
612
  $attributes = $product->getAttributes();
613
  $Manufacturer = "";
614
  $ProductAttributes = "";
615
+ foreach ($attributes as $attribute) {
616
+ $attribute->setStoreId($this->StoreId);
617
+ if ($attribute->getAttributeCode() == "manufacturer") {
618
+ if ($product->getData($attribute->getAttributeCode())) {
619
+ $Manufacturer = $attribute->getFrontend()->getValue($product);
620
+ } else {
621
  $Manufacturer = "";
622
+ }
623
  continue;
624
  }
625
+ if ($attribute->getIsVisibleOnFront() ||
626
+ ( $this->includecustomfields && array_key_exists(strtolower($attribute->getAttributeCode()), $this->includecustomfields) )) {
627
+ $value = $attribute->getFrontend()->getValue($product);
628
+ if ($attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect") {
629
+ $hasData = $product->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
630
+ if (!$hasData) {
631
  $value = "";
632
+ }
633
  }
634
+ if (is_string($value) && strlen($value)) {
635
+ if (!empty($ProductAttributes)) {
636
  $ProductAttributes .= "|";
637
+ }
638
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
639
  }
640
  }
641
  }
642
+ if ($this->publishtieredpricing == "1") {
643
  $TierPriceAttributes = $this->_getTierPrices($product);
644
+ $sp = ( empty($ProductAttributes) || empty($TierPriceAttributes) ) ? "" : "|";
645
+ $ProductAttributes.= $sp . $TierPriceAttributes;
646
  }
647
+ if ($this->importoptionsasattributes) {
648
+ $optionsAsAttributes = $this->_getCustomOptionsAsAttributes($product);
649
+ if (!empty($optionsAsAttributes)) {
650
+ if (!empty($ProductAttributes)) {
651
  $ProductAttributes .= "|";
652
+ }
653
  $ProductAttributes .= $optionsAsAttributes;
654
  }
655
  }
656
+ if (!empty($ProductAttributes)) {
657
+ $ProductAttributes = $this->_cleanStr($ProductAttributes);
658
+ }
659
+ if ($this->_DEBUG) {
660
+ $this->controller->getResponse()->appendBody("product image: " . $product->getImage() . "
661
+ small image: " . $product->getSmallImage() . "
662
+ thumbnail: " . $product->getThumbnail() . "
663
+ ");
664
+ }
665
+ $prodImages = array();
666
+ $firstImageFile = trim($product->getImage());
667
+ if ($firstImageFile == "no_selection") {
668
  $firstImageFile = FALSE;
669
+ }
670
+ if ($firstImageFile) {
671
+ $prodImages[] = "MagentoBase#=#" . $this->prodmediaurl . $this->_formatImageURL($firstImageFile);
672
+ }
673
  $prodImageArray = $product->getMediaGallery('images');
674
+ if (is_array($prodImageArray)) {
675
+ foreach ($prodImageArray as $image) {
676
+ $imageFile = trim($image['file']);
677
+ if ($this->_DEBUG) {
678
+ $this->controller->getResponse()->appendBody("gallery image: " . $imageFile . " disabled=" . $image['disabled'] . "
679
+ ");
680
+ }
681
+ if (!$imageFile || $imageFile == $firstImageFile) {
682
  continue;
683
+ }
684
+ if ($this->ignoreexcludedimages && $image['disabled']) {
685
  continue;
686
+ }
687
+ $prodImages[] = "Print#=#" . $this->prodmediaurl . $this->_formatImageURL($imageFile);
688
  }
689
  }
690
+ $prodImages = implode("#|#", $prodImages);
691
  $ProductURL = $product->getProductUrl();
692
+ if (!empty($ProductURL)) {
693
+ $ProductURL = $this->_correctProdUrlStr($ProductURL);
694
+ }
695
  $productName = $product->getName();
696
+ $productName = $product->getId() . '#$#' . $this->_cleanStr($productName);
697
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
698
+ if (!empty($Reviews)) {
699
+ $Reviews = $this->_cleanStr($Reviews);
700
+ }
701
+ if (!$this->getpricefromchild) {
702
  $ProdRPrice = $product->getData('price');
703
  $ProdSPrice = $product->getSpecialPrice();
704
  $ProdSFromDate = $product->getSpecialFromDate();
705
  $ProdSToDate = $product->getSpecialToDate();
706
+ if ($this->_DEBUG) {
707
+ $this->controller->getResponse()->appendBody("prod prices: Regular=" . $ProdRPrice . " Special=" . $ProdSPrice . " FromDate=" . $ProdSFromDate . " ToDate=" . $ProdSToDate . "
708
+ ");
709
+ }
710
  $ProdGroupPrices = FALSE;
711
+ if ($this->mageVersionArray['major'] > 1 || $this->mageVersionArray['minor'] > 6) {
712
  $ProdGroupPrices = $product->getData('group_price');
713
+ if ($this->_DEBUG && count($ProdGroupPrices) > 0) {
714
+ $this->controller->getResponse()->appendBody("group_price: " . var_export($ProdGroupPrices, true) . "
715
+ ");
716
+ }
717
  }
718
  $ProdSpecGroupPrices = FALSE;
719
+ if ($ProdGroupPrices) {
720
  $ProdSpecGroupPrices = array();
721
+ foreach ($ProdGroupPrices as $groupPrice) {
722
+ if ($groupPrice['cust_group'] == '0') {
723
+ $notLoggedInPrice = 0.0 + $groupPrice['price'];
724
+ if (trim($ProdSPrice) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice) {
725
+ $ProdSPrice = $groupPrice['price'];
726
  $ProdSFromDate = FALSE;
727
  $ProdSToDate = FALSE;
728
  }
731
  }
732
  }
733
  }
734
+ if (trim($ProdSPrice) == "") {
735
  $ProdSPrice = -1;
736
  $ProdSFromDate = FALSE;
737
  $ProdSToDate = FALSE;
738
  }
739
  } // ! $this->getpricefromchild
740
+ if ($this->_DEBUG) {
741
+ $this->controller->getResponse()->appendBody("used product IDs: ");
742
+ foreach ($UsedProductIds as $UsedProductid) {
743
+ $this->controller->getResponse()->appendBody("" . $UsedProductid . " ");
744
+ }
745
+ $this->controller->getResponse()->appendBody("
746
+ ");
747
  }
748
  $usedConfigurableAttributes = FALSE;
749
+ if ($this->importoptionsasattributes) {
750
  $usedConfigurableAttributes = array();
751
  }
752
+ $ConfigurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
753
+ foreach ($ConfigurableAttributes as $attribute) {
754
+ if ($this->_DEBUG) {
755
+ $this->controller->getResponse()->appendBody("configurable attr: " . $attribute->getLabel() . "
756
+ ");
757
  }
758
  $configurableProdAttribute = $attribute->getProductAttribute();
759
+ if (empty($configurableProdAttribute)) {
760
  $label = $attribute->getLabel();
761
+ $this->controller->getResponse()->appendBody("WARNING: no product attribute for configurable attribute " . $label . "
762
+ ");
763
  continue;
764
  }
765
+ $configurableProdAttribute->setStoreId($this->StoreId);
766
+ if ($this->_DEBUG) {
767
+ $this->controller->getResponse()->appendBody("configurable prod attr: " . $configurableProdAttribute->getFrontend()->getLabel() . "
768
+ ");
769
  }
770
  $AttributeLabel = $attribute->getLabel();
771
+ if (!$AttributeLabel) {
772
  $AttributeLabel = $configurableProdAttribute->getFrontend()->getLabel();
773
+ }
774
+ if ($this->importoptionsasattributes) {
775
+ $usedConfigurableAttributes[$AttributeLabel] = array();
776
+ if ($this->_DEBUG) {
777
+ $this->controller->getResponse()->appendBody("created usedConfigurableAttributes array for \"" . $AttributeLabel . "\"
778
+ ");
779
  }
780
  }
781
+ foreach ($configurableProdAttribute->getSource()->getAllOptions() as $option) {
782
+ if ($this->_DEBUG) {
783
+ $this->controller->getResponse()->appendBody("variation option: " . $option['value'] . "=>" . $option['label'] . "
784
+ ");
785
  }
786
+ if ($this->importoptionsasattributes) {
787
+ $usedConfigurableAttributes[$AttributeLabel][$option['label']] = FALSE;
788
+ if ($this->_DEBUG) {
789
+ $this->controller->getResponse()->appendBody("created usedConfigurableAttributes label \"" . $option['label'] . "\"
790
+ ");
791
  }
792
+ }
793
  }
794
  }
795
  $UsedProducts = array();
796
+ foreach ($UsedProductIds as $UsedProductid) {
797
+ $UsedProduct = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($UsedProductid);
798
+ if ($UsedProduct->getStatus() == 1) {
799
+ $UsedProducts[$UsedProductid] = $UsedProduct;
800
  } else {
801
+ if ($this->_DEBUG) {
802
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " enabled=" . $UsedProduct->getStatus() . " - bypassed.
803
+ ");
804
+ }
805
+ unset($UsedProduct);
806
  }
807
  }
808
  $cpLines = array();
809
+ foreach ($UsedProducts as $UsedProductid => $UsedProduct) {
810
  $cpLine = new ConfiguredProductLine();
811
+ if ($this->instockonly) {
812
+ $inventory = $this->catalogInventoryModel->loadByProduct($UsedProduct);
813
  $qty = $inventory->getQty();
814
  $minQty = $inventory->getMinQty();
815
+ if ($qty <= $minQty) {
816
+ if ($this->_DEBUG) {
817
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " qty=" . $qty . " minQty=" . $minQty . " - bypassing.
818
+ ");
819
+ }
820
  continue;
821
  }
822
  }
823
+ if (!$this->getpricefromchild) {
824
  $RPrice = $ProdRPrice;
825
  $SPrice = $ProdSPrice;
826
  $RPrice0 = $ProdRPrice;
827
  $SPrice0 = $ProdSPrice;
828
+ $SFromDate = !empty($SPrice) ? $ProdSFromDate : FALSE;
829
+ $SToDate = !empty($SPrice) ? $ProdSToDate : FALSE;
830
  $SpecGroupPrices = FALSE;
831
  $SpecGroupPrices0 = FALSE;
832
+ if ($ProdSpecGroupPrices) {
833
  $SpecGroupPrices = array();
834
  $SpecGroupPrices0 = array();
835
+ foreach ($ProdSpecGroupPrices as $prodGroupPrice) {
836
+ $SpecGroupPrices[$prodGroupPrice['cust_group']] = 0.0 + $prodGroupPrice['price'];
837
+ $SpecGroupPrices0[$prodGroupPrice['cust_group']] = 0.0 + $prodGroupPrice['price'];
838
  }
839
  }
840
  } else { // $this->getpricefromchild
841
+ if ($this->_DEBUG) {
842
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " prices: Regular=" . $UsedProduct->getData('price') . " Final=" . $UsedProduct->getFinalPrice() . " Special=" . $UsedProduct->getSpecialPrice() . " FromDate=" . $UsedProduct->getSpecialFromDate() . " ToDate=" . $UsedProduct->getSpecialToDate() . "
843
+ ");
844
+ }
845
  $RPrice = $UsedProduct->getData('price');
846
  $SPrice = $UsedProduct->getSpecialPrice();
847
  $SFromDate = $UsedProduct->getSpecialFromDate();
848
  $SToDate = $UsedProduct->getSpecialToDate();
849
+ if ($this->_DEBUG) {
850
+ $this->controller->getResponse()->appendBody("prod prices: Regular=" . $RPrice . " Special=" . $SPrice . " FromDate=" . $SFromDate . " ToDate=" . $SToDate . "
851
+ ");
852
+ }
853
  $ProdGroupPrices = FALSE;
854
+ if ($this->mageVersionArray['major'] > 1 || $this->mageVersionArray['minor'] > 6) {
855
  $ProdGroupPrices = $UsedProduct->getData('group_price');
856
+ if ($this->_DEBUG && count($ProdGroupPrices) > 0) {
857
+ $this->controller->getResponse()->appendBody("group_price: " . var_export($ProdGroupPrices, true) . "
858
+ ");
859
+ }
860
  }
861
  $SpecGroupPrices = FALSE;
862
  $SpecGroupPrices0 = FALSE;
863
+ if ($ProdGroupPrices) {
864
  $SpecGroupPrices = array();
865
+ foreach ($ProdGroupPrices as $groupPrice) {
866
+ if ($groupPrice['cust_group'] == '0') {
867
+ $notLoggedInPrice = 0.0 + $groupPrice['price'];
868
+ if (trim($SPrice) == "" || $notLoggedInPrice < 0.0 + $SPrice) {
869
+ $SPrice = $groupPrice['price'];
870
  $SFromDate = FALSE;
871
  $SToDate = FALSE;
872
  }
875
  }
876
  }
877
  }
878
+ if (trim($SPrice) == "") {
879
  $SPrice = -1;
880
  $SFromDate = FALSE;
881
  $SToDate = FALSE;
882
  }
883
  }
884
  $ItemAttributes = "";
885
+ foreach ($ConfigurableAttributes as $attribute) {
886
  $configurableProdAttribute = $attribute->getProductAttribute();
887
+ if (empty($configurableProdAttribute)) {
888
  $label = $attribute->getLabel();
889
+ $this->controller->getResponse()->appendBody("WARNING: no product attribute for configurable attribute " . $label . "
890
+ ");
891
  $cpLine->optionIds[] = 0;
892
  continue;
893
  }
894
  $AttributeCode = $configurableProdAttribute->getAttributeCode();
895
  $AttributeLabel = $attribute->getLabel();
896
+ if (!$AttributeLabel) {
897
  $AttributeLabel = $configurableProdAttribute->getFrontend()->getLabel();
898
+ }
899
  $AttribId = $UsedProduct->getData($AttributeCode);
900
+ $cpLine->optionIds[] = intVal($AttribId);
901
  $AttributeValue = "";
902
+ foreach ($configurableProdAttribute->getSource()->getAllOptions() as $option) {
903
+ if ($option['value'] == $AttribId) {
904
  $AttributeValue = $option['label'];
905
  break;
906
  }
907
  }
908
+ if ($this->importoptionsasattributes && trim($AttributeValue)) {
909
+ $usedConfigurableAttributes[$AttributeLabel][$AttributeValue] = TRUE;
910
+ }
911
+ if ($this->_DEBUG) {
912
+ $this->controller->getResponse()->appendBody("config attr code=" . $AttributeCode . " label=" . $AttributeLabel . " id=" . $AttribId . " value=" . $AttributeValue . "
913
+ ");
914
+ }
915
+ if (!empty($ItemAttributes)) {
916
  $ItemAttributes .= "|";
917
+ }
918
+ $ItemAttributes .= $AttributeLabel . "=" . $AttributeValue;
919
+ if (!$this->getpricefromchild) {
920
+ foreach ($attribute->getPrices() as $addedPrice) {
921
+ if ($AttributeValue == $addedPrice['label']) {
922
+ if ($addedPrice['is_percent']) {
923
+ $RPrice += round($RPrice0 * $addedPrice['pricing_value'] / 100, 2);
924
+ if ($SPrice >= 0) {
925
+ $SPrice += round($SPrice0 * $addedPrice['pricing_value'] / 100, 2);
926
+ }
927
+ if ($SpecGroupPrices) {
928
+ foreach ($SpecGroupPrices0 as $key => $value) {
929
+ $SpecGroupPrices[$key] += round($value * $addedPrice['pricing_value'] / 100, 2);
930
  }
931
+ }
932
  } else {
933
  $RPrice += $addedPrice['pricing_value'];
934
+ if ($SPrice >= 0) {
935
  $SPrice += $addedPrice['pricing_value'];
936
+ }
937
+ if ($SpecGroupPrices) {
938
+ foreach ($SpecGroupPrices0 as $key => $value) {
939
+ $SpecGroupPrices[$key] += $addedPrice['pricing_value'];
940
+ }
941
+ }
942
  }
943
  }
944
  }
945
  } // ! $this->getpricefromchild
946
  }
947
+ if (!empty($RPrice) && $this->includetaxes) {
948
+ $RPrice = $this->taxhelper->getPrice($UsedProduct, $RPrice, true, null, null, null, $this->StoreId);
949
+ }
950
+ if (!empty($SPrice) && $this->includetaxes) {
951
+ $SPrice = $this->taxhelper->getPrice($UsedProduct, $SPrice, true, null, null, null, $this->StoreId);
952
+ }
953
+ if ($this->includeinvqty) {
954
+ if (!empty($ItemAttributes)) {
955
  $ItemAttributes .= "|";
956
+ }
957
+ $ItemAttributes .= "Inventory=" . $this->_formatQty("" . $this->catalogInventoryModel->loadByProduct($UsedProduct)->getQty());
958
+ }
959
+ if ($this->_DEBUG) {
960
+ $this->controller->getResponse()->appendBody("resulting prices: Regular=" . $RPrice . " Special=" . $SPrice . " FromDate=" . $SFromDate . " ToDate=" . $SToDate . "
961
+ ");
962
+ }
963
+ $RPrice = $this->_formatPrice($RPrice);
964
+ if ($this->includespecialprice) {
965
+ if ($SPrice >= 0) {
966
+ $SPrice = $this->_formatPrice($SPrice);
967
+ if (!empty($ItemAttributes)) {
968
  $ItemAttributes .= "|";
969
+ }
970
+ $ItemAttributes .= "Special Price=" . $SPrice;
971
  }
972
  }
973
+ if ($this->includespecialpricedatefrom) {
974
+ if (!empty($SFromDate)) {
975
+ if (!empty($ItemAttributes)) {
976
  $ItemAttributes .= "|";
977
+ }
978
+ $ItemAttributes .= "Special Price From Date=" . substr($SFromDate, 0, 10);
979
  }
980
  }
981
+ if ($this->includespecialpricedateto) {
982
+ if (!empty($SToDate)) {
983
+ if (!empty($ItemAttributes)) {
984
  $ItemAttributes .= "|";
985
+ }
986
+ $ItemAttributes .= "Special Price To Date=" . substr($SToDate, 0, 10);
987
  }
988
  }
989
+ if ($this->getgroupprices && $SpecGroupPrices) {
990
+ foreach ($SpecGroupPrices as $groupID => $price) {
991
+ if ($price >= 0 && $this->includetaxes) {
992
+ $price = $this->taxhelper->getPrice($UsedProduct, $price, true, null, null, null, $this->StoreId);
993
+ }
994
+ if (!empty($ItemAttributes)) {
995
  $ItemAttributes .= "|";
996
+ }
997
+ $ItemAttributes .= "price_" . $this->customerGroups[$groupID] . "=" . $this->_formatPrice($price);
998
  }
999
  }
1000
+ if (!$this->getpricefromchild) {
1001
+ if ($this->publishtieredpricing == "1") {
1002
  $TierPriceAttributes = $this->_getTierPrices($UsedProduct);
1003
+ $sp = ( empty($ItemAttributes) || empty($TierPriceAttributes) ) ? "" : "|";
1004
+ $ItemAttributes.= $sp . $TierPriceAttributes;
1005
  }
1006
  } // ! $this->getpricefromchild
1007
+ if ($this->ignoreassprodimages) {
1008
+ $itemImages = "";
1009
+ } else {
1010
+ if ($this->_DEBUG) {
1011
+ $this->controller->getResponse()->appendBody("config item image: " . $UsedProduct->getImage() . "
1012
+ small image: " . $UsedProduct->getSmallImage() . "
1013
+ thumbnail: " . $UsedProduct->getThumbnail() . "
1014
+ ");
1015
+ }
1016
+ $itemImages = array();
1017
+ $firstImageFile = trim($UsedProduct->getImage());
1018
+ if ($firstImageFile == "no_selection") {
1019
  $firstImageFile = FALSE;
1020
+ }
1021
+ if ($firstImageFile) {
1022
+ $itemImages[] = "MagentoBase#=#" . $this->prodmediaurl . $this->_formatImageURL($firstImageFile);
1023
+ }
1024
  $itemImageArray = $UsedProduct->getMediaGallery('images');
1025
+ if (is_array($itemImageArray)) {
1026
+ foreach ($itemImageArray as $image) {
1027
+ $imageFile = trim($image['file']);
1028
+ if ($this->_DEBUG) {
1029
+ $this->controller->getResponse()->appendBody("gallery image: " . $imageFile . " disabled=" . $image['disabled'] . "
1030
+ ");
1031
+ }
1032
+ if (!$imageFile || $imageFile == $firstImageFile) {
1033
  continue;
1034
+ }
1035
+ if ($this->ignoreexcludedimages && $image['disabled']) {
1036
  continue;
1037
+ }
1038
+ $itemImages[] = "Print#=#" . $this->prodmediaurl . $this->_formatImageURL($imageFile);
1039
  }
1040
  }
1041
+ $itemImages = implode("#|#", $itemImages);
1042
  }
1043
  $itemID = $UsedProduct->getSku();
1044
+ $cpLine->line = $this->_cleanStr($itemID) //ItemID
1045
+ . "\t" //ItemQty
1046
+ . "\t" //ItemUom
1047
+ . "\t" . $RPrice //ItemPrice
1048
+ . "\t" //ItemDescription
1049
+ . "\t" //ItemLink
1050
+ . "\t" . $this->_cleanStr($ItemAttributes) //ItemAttributes
1051
+ . "\t" . $itemImages; //ItemitemGraphic
1052
  $cpLines[] = $cpLine;
1053
+ unset($UsedProduct);
1054
  }
1055
+ unset($UsedProducts);
1056
+ unset($UsedProductIds);
1057
  $optionIds = array();
1058
  $attrNumber = 0;
1059
  $optNumbers = array();
1060
  $optCounters = array();
1061
+ foreach ($ConfigurableAttributes as $attribute) {
1062
  $configurableProdAttribute = $attribute->getProductAttribute();
1063
+ if (empty($configurableProdAttribute)) {
1064
  continue;
1065
  }
1066
  $optionIdList = array();
1067
  $optionNo = 0;
1068
+ foreach ($configurableProdAttribute->getSource()->getAllOptions() as $option) {
1069
+ $optionIdList[] = trim($option['value']) == "" ? 0 : intVal($option['value']);
1070
  $optionNo++;
1071
  }
1072
  $optionIds[] = $optionIdList;
1074
  $optNumbers[] = 0;
1075
  $attrNumber++;
1076
  }
 
 
1077
  // supplement prod attrs
1078
+ if ($this->importoptionsasattributes) {
1079
+ foreach ($usedConfigurableAttributes as $attrName => $attrValues) {
1080
+ if (!empty($ProductAttributes)) {
1081
  $ProductAttributes .= "|";
1082
+ }
1083
+ $ProductAttributes .= $attrName . "=";
1084
  $valCount = 0;
1085
+ foreach ($attrValues as $attrValue => $used) {
1086
+ if ($used) {
1087
+ if ($valCount > 0) {
1088
  $ProductAttributes .= "<br />";
1089
+ }
1090
  $ProductAttributes .= $attrValue;
1091
  $valCount++;
1092
  }
1093
  }
1094
  }
1095
+ }
1096
  // build prod part
1097
+ $this->prodLine = "\t" . $productName //ProductName
1098
+ . "\t" . $ProductDescription
1099
+ . "\t" . $prodImages //ProductGraphic
1100
+ . "\t" . $ProductURL //ProductLink
1101
+ . "\t" . $ProductAttributes //ProductAttributes
1102
+ . "\t" . $Manufacturer //Manufacturer
1103
+ . "\t" //Category
1104
+ . "\t" . $Reviews //Reviews
1105
+ . "\t" . $shortDescription
1106
+ . "\t";
1107
  // build cplines matrix
1108
  $cpLinesMatrix = array();
1109
+ foreach ($cpLines as $cpLine) {
1110
+ $optionId = $cpLine->optionIds[0];
1111
+ if ($attrNumber > 1) {
1112
+ if (!isset($cpLinesMatrix[$optionId])) {
1113
+ $cpLinesMatrix[$optionId] = array();
1114
+ }
1115
+ $this->_fillCPLinesMatrix(1, $attrNumber, $cpLine, $cpLinesMatrix[$optionId]);
1116
  } else {
1117
+ if (!isset($cpLinesMatrix[$optionId])) {
1118
+ $cpLinesMatrix[$optionId] = $cpLine;
1119
+ }
1120
  }
1121
  }
1122
  $this->configItemSequence = 1;
1123
  $this->configProducttoString = "";
1124
+ $this->_fillConfigProdItems(0, $attrNumber, $optNumbers, $optionIds, $optCounters, $cpLinesMatrix);
1125
+ unset($optionIds);
1126
+ foreach ($cpLines as $cpLine) {
1127
+ if ($cpLine->line) {
1128
+ $this->controller->getResponse()->appendBody("WARNING: not rendered config line: " . var_export($cpLine->optionIds, true) . "
1129
+ ");
1130
+ }
1131
  }
1132
+ unset($cpLines);
1133
  return $this->configProducttoString;
1134
  }
1135
+
1136
+ private function ProducttoStringSimple(&$product) {
1137
  $ProductDescription = "";
1138
  $shortDescription = "";
1139
+ if ($this->includeshortdescription) {
1140
  $shortDescription = $product->getShortDescription();
1141
+ if (!empty($shortDescription)) {
1142
+ $shortDescription = $this->_cleanStr($shortDescription);
1143
+ if (strpos($shortDescription, self::TAG_P) !== false) {
1144
+ $new = strlen($shortDescription);
1145
+ $pos = strrpos($shortDescription, self::TAG_P_CLOSE) + 4;
1146
+ if ($new != $pos) {
1147
+ $shortDescription = substr($shortDescription, 0, $pos) . self::TAG_P . substr($shortDescription, $pos) . self::TAG_P_CLOSE;
1148
+ }
1149
+ } else {
1150
+ $shortDescription = self::TAG_P . $shortDescription . self::TAG_P_CLOSE;
1151
+ }
1152
+ $ProductDescription = $shortDescription;
1153
+ }
1154
+ }
1155
+ if ($this->includelongdescription) {
1156
  $longDescription = $product->getDescription();
1157
+ if (!empty($longDescription)) {
1158
+ $longDescription = $this->_cleanStr($longDescription);
1159
+ if (strpos($longDescription, self::TAG_P) !== false) {
1160
+ $new = strlen($longDescription);
1161
+ $pos = strrpos($longDescription, self::TAG_P_CLOSE) + 4;
1162
+ if ($new != $pos) {
1163
+ $longDescription = substr($longDescription, 0, $pos) . self::TAG_P . substr($longDescription, $pos) . self::TAG_P_CLOSE;
1164
+ }
1165
+ } else {
1166
+ $longDescription = self::TAG_P . $longDescription . self::TAG_P_CLOSE;
1167
+ }
1168
+ $ProductDescription .= $longDescription;
1169
+ }
1170
+ }
1171
+ $prodImages = array();
1172
+ if ($this->_DEBUG) {
1173
+ $this->controller->getResponse()->appendBody("product image: " . $product->getImage() . "
1174
+ small image: " . $product->getSmallImage() . "
1175
+ thumbnail: " . $product->getThumbnail() . "
1176
+ ");
1177
+ }
1178
+ $firstImageFile = trim($product->getImage());
1179
+ if ($firstImageFile == "no_selection") {
1180
  $firstImageFile = FALSE;
1181
+ }
1182
+ if ($firstImageFile) {
1183
+ $prodImages[] = "MagentoBase#=#" . $this->prodmediaurl . $this->_formatImageURL($firstImageFile);
1184
+ }
1185
  $prodImageArray = $product->getMediaGallery('images');
1186
+ if (is_array($prodImageArray)) {
1187
+ foreach ($prodImageArray as $image) {
1188
+ $imageFile = trim($image['file']);
1189
+ if ($this->_DEBUG) {
1190
+ $this->controller->getResponse()->appendBody("gallery image: " . $imageFile . " disabled=" . $image['disabled'] . "
1191
+ ");
1192
+ }
1193
+ if (!$imageFile || $imageFile == $firstImageFile) {
1194
  continue;
1195
+ }
1196
+ if ($this->ignoreexcludedimages && $image['disabled']) {
1197
  continue;
1198
+ }
1199
+ $prodImages[] = "Print#=#" . $this->prodmediaurl . $this->_formatImageURL($imageFile);
1200
  }
1201
  }
1202
+ $prodImages = implode("#|#", $prodImages);
1203
  $URL = $product->getProductUrl();
1204
+ if ($this->_DEBUG) {
1205
+ $this->controller->getResponse()->appendBody("URL= " . $URL . "
1206
+ ");
1207
+ }
1208
+ if (!empty($URL)) {
1209
+ $URL = $this->_correctProdUrlStr($URL);
1210
+ }
1211
  $attributes = $product->getAttributes();
1212
  $Manufacturer = "";
1213
  $ProductAttributes = "";
1214
+ foreach ($attributes as $attribute) {
1215
+ $attribute->setStoreId($this->StoreId);
1216
+ if ($this->_DEBUG && ( $attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect" )) {
1217
  $hasData = $product->getData($attribute->getAttributeCode()) ? "YES" : "NO";
1218
  $vof = $attribute->getIsVisibleOnFront() ? "YES" : "NO";
1219
+ $this->controller->getResponse()->appendBody("simple prod attr: " . $attribute->getFrontend()->getLabel() . "=" . $attribute->getFrontend()->getValue($product) . " input=" . $attribute->getFrontendInput() . " data=" . $product->getData($attribute->getAttributeCode()) . " hasData=" . $hasData . " store=" . $product->_storeId . " vof=" . $vof . "
1220
+ ");
1221
  }
1222
+ if ($attribute->getAttributeCode() == "manufacturer") {
1223
+ if ($product->getData($attribute->getAttributeCode())) {
1224
+ $Manufacturer = $attribute->getFrontend()->getValue($product);
1225
+ } else {
1226
  $Manufacturer = "";
1227
+ }
1228
  continue;
1229
  }
1230
+ if ($attribute->getIsVisibleOnFront() ||
1231
+ ( $this->includecustomfields && array_key_exists(strtolower($attribute->getAttributeCode()), $this->includecustomfields) )) {
1232
+ $value = $attribute->getFrontend()->getValue($product);
1233
+ if ($attribute->getFrontendInput() == "select" || $attribute->getFrontendInput() == "multiselect") {
1234
+ $hasData = $product->getData($attribute->getAttributeCode()) ? TRUE : FALSE;
1235
+ if (!$hasData) {
1236
  $value = "";
1237
+ }
1238
  }
1239
+ if (is_string($value) && strlen($value)) {
1240
+ if (!empty($ProductAttributes)) {
1241
  $ProductAttributes .= "|";
1242
+ }
1243
  $ProductAttributes .= $attribute->getFrontend()->getLabel() . "=" . $value;
1244
  } else {
1245
+ if ($this->_DEBUG) {
1246
+ $this->controller->getResponse()->appendBody("not a string with length > 0
1247
+ ");
1248
+ }
1249
  }
1250
  }
1251
  }
1252
+ if ($this->publishtieredpricing == "1") {
1253
+ $TierPriceAttributes = $this->_getTierPrices($product);
1254
+ $sp = ( empty($ProductAttributes) || empty($TierPriceAttributes) ) ? "" : "|";
1255
+ $ProductAttributes.= $sp . $TierPriceAttributes;
1256
  }
1257
+ if ($this->importoptionsasattributes) {
1258
+ $optionsAsAttributes = $this->_getCustomOptionsAsAttributes($product);
1259
+ if (!empty($optionsAsAttributes)) {
1260
+ if (!empty($ProductAttributes)) {
1261
  $ProductAttributes .= "|";
1262
+ }
1263
  $ProductAttributes .= $optionsAsAttributes;
1264
  }
1265
  }
1266
+ if (!empty($ProductAttributes)) {
1267
+ $ProductAttributes = $this->_cleanStr($ProductAttributes);
1268
+ }
1269
  $ProdRPrice = $product->getData('price');
1270
  $ProdSPrice = $product->getSpecialPrice();
1271
  $ProdSFromDate = $product->getSpecialFromDate();
1272
  $ProdSToDate = $product->getSpecialToDate();
1273
+ if ($this->instockonly) {
1274
+ $inventory = $this->catalogInventoryModel->loadByProduct($product);
1275
  $qty = $inventory->getQty();
1276
  $minQty = $inventory->getMinQty();
1277
+ if ($this->_DEBUG) {
1278
+ $this->controller->getResponse()->appendBody("sku=" . $product->getSku() . " qty=" . $qty . " minQty=" . $minQty . "
1279
+ ");
1280
+ }
1281
+ if ($qty <= $minQty) {
1282
  return;
1283
+ }
1284
+ }
1285
+ if ($this->_DEBUG) {
1286
+ $this->controller->getResponse()->appendBody("sku=" . $product->getSku() . " prices: Regular=" . $ProdRPrice . " Special=" . $ProdSPrice . " FromDate=" . $ProdSFromDate . " ToDate=" . $ProdSToDate . "
1287
+ ");
1288
  }
 
 
1289
  $ProdGroupPrices = FALSE;
1290
+ if ($this->mageVersionArray['major'] > 1 || $this->mageVersionArray['minor'] > 6) {
1291
  $ProdGroupPrices = $product->getData('group_price');
1292
+ if ($this->_DEBUG && count($ProdGroupPrices) > 0) {
1293
+ $this->controller->getResponse()->appendBody("group_price: " . var_export($ProdGroupPrices, true) . "
1294
+ ");
1295
+ }
1296
  }
1297
  $ProdSpecGroupPrices = FALSE;
1298
+ if ($ProdGroupPrices) {
1299
  $ProdSpecGroupPrices = array();
1300
+ foreach ($ProdGroupPrices as $groupPrice) {
1301
+ if ($groupPrice['cust_group'] == '0') {
1302
+ $notLoggedInPrice = 0.0 + $groupPrice['price'];
1303
+ if (trim($ProdSPrice) == "" || $notLoggedInPrice < 0.0 + $ProdSPrice) {
1304
+ $ProdSPrice = $groupPrice['price'];
1305
  $ProdSFromDate = FALSE;
1306
  $ProdSToDate = FALSE;
1307
  }
1308
+ } else {
1309
  $ProdSpecGroupPrices[] = $groupPrice;
1310
+ }
1311
  }
1312
  }
1313
+ if (trim($ProdSPrice) == "") {
1314
  $ProdSPrice = -1;
1315
  $ProdSFromDate = FALSE;
1316
  $ProdSToDate = FALSE;
1317
  }
1318
+ if (!$ProdRPrice && $product->getTypeId() == "bundle") {
1319
  $priceModel = $product->getPriceModel();
1320
+ $options = Mage::getSingleton('core/layout')->createBlock('bundle/catalog_product_view_type_bundle')->setProduct($product)->getOptions();
1321
  $ProdRPrice = 0;
1322
+ foreach ($options as $option) {
1323
  $selection = $option->getDefaultSelection();
1324
  $MinSelPrice = 0;
1325
+ if ($selection) {
1326
+ $MinSelPrice = $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
1327
+ } else if (!$selection && $option->_origData["required"] == "1") {
1328
+ foreach ($option->getSelections() as $selection) {
1329
+ $SelPrice = $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
1330
+ if (( $MinSelPrice == 0 && $SelPrice > 0 ) || ( $MinSelPrice > 0 && $SelPrice > 0 && $SelPrice < $MinSelPrice )) {
1331
  $MinSelPrice = $SelPrice;
1332
+ }
1333
  }
1334
  }
1335
+ if ($MinSelPrice <= 0) {
1336
  continue;
1337
+ }
1338
+ if ($this->_DEBUG) {
1339
+ $this->controller->getResponse()->appendBody("added " . $MinSelPrice . "
1340
+ ");
1341
+ }
1342
  $ProdRPrice += $MinSelPrice;
1343
  }
1344
+ if ($this->_DEBUG) {
1345
+ $this->controller->getResponse()->appendBody("Bundle=" . $ProdRPrice . "
1346
+ ");
1347
+ }
1348
  }
1349
  $Reviews = $this->enablereviews ? $this->_getReviews($product->getId()) : '';
1350
+ if (!empty($Reviews)) {
1351
+ $Reviews = $this->_cleanStr($Reviews);
1352
+ }
1353
  $prodSku = $product->getSku();
1354
+ $prodSku = $this->_cleanStr($prodSku);
1355
+ $cleanProdName = $this->_cleanStr($prodName);
1356
  $prodName = $product->getName();
1357
+ $cleanProdName = $this->_cleanStr($prodName);
1358
+ $prodName = $product->getId() . '#$#' . $cleanProdName;
1359
  $skusAdded = false;
1360
+ if ($this->importoptionsassku) {
1361
  $this->configItemSequence = 1;
1362
  $this->configProducttoString = "";
1363
  $customOptions = $product->getOptions();
1364
+ if ($customOptions) {
1365
+ if ($this->_DEBUG) {
1366
+ $this->controller->getResponse()->appendBody("=== customOptions ===
1367
+ ProdRPrice=" . $ProdRPrice . " ProdSPrice=" . $ProdSPrice . "
1368
+ ");
1369
+ }
1370
  $max_sort_order = 0;
1371
+ foreach ($customOptions as $option) {
1372
+ if ($option->getSortOrder() > $max_sort_order) {
1373
  $max_sort_order = $option->getSortOrder();
1374
+ } else if ($option->getSortOrder() < 0) {
1375
+ $option->setSortOrder(-1);
1376
  }
1377
  }
1378
  $orderedOptionValues = array();
1379
  $orderedCustomOptions = array();
1380
+ for ($sortorder = -1; $sortorder <= $max_sort_order; $sortorder++) {
1381
  foreach ($customOptions as $option) {
1382
+ if ($option->getSortOrder() != $sortorder) {
1383
+ continue;
1384
+ }
1385
  $orderedCustomOptions[] = $option;
1386
  $optionValues = array();
1387
+ if ($option->getValues()) {
1388
  $max_v_sort_order = 0;
1389
+ foreach ($option->getValues() as $_value) {
1390
+ if ($_value->getSortOrder() > $max_v_sort_order) {
1391
  $max_v_sort_order = $_value->getSortOrder();
1392
+ } else if ($_value->getSortOrder() < 0) {
1393
+ $_value->setSortOrder(-1);
1394
  }
1395
  }
1396
+ for ($vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++) {
1397
+ foreach ($option->getValues() as $_value) {
1398
+ if ($_value->getSortOrder() != $vsortorder) {
1399
+ continue;
1400
+ }
1401
+ $optionValues[] = $_value;
1402
  }
1403
  }
1404
  }
1405
+ $orderedOptionValues[$option->getOptionId()] = $optionValues;
1406
  }
1407
  }
1408
  $customOptions = array();
1409
  $customOptionsById = array();
1410
+ foreach ($orderedCustomOptions as $option) {
1411
+ if ($this->_DEBUG) {
1412
+ $this->controller->getResponse()->appendBody("customOption #" . $option->getOptionId() . " title=" . $option->getTitle() . " storeTitle=" . $option->getStoreTitle() . " type=" . $option->getType() . " isRequire=" . $option->getIsRequire() . " sort_order" . $option->getSortOrder() . "
1413
+ ");
1414
+ if ($option->getType() == "date" ||
1415
+ $option->getType() == "time" ||
1416
+ $option->getType() == "date_time" ||
1417
+ $option->getType() == "field" ||
1418
+ $option->getType() == "area") {
1419
+ $this->controller->getResponse()->appendBody(" price=" . $option->getPrice() . " price_type=" . $option->getPriceType() . " sku=" . $option->getSku() . "
1420
+ ");
1421
+ }
1422
  }
1423
  $customOption = new COption();
1424
  $customOption->id = $option->getOptionId();
1425
  $customOption->title = $option->getStoreTitle();
1426
+ if (!$customOption->title) {
1427
  $customOption->title = $option->getTitle();
1428
+ }
1429
+ if (!$customOption->title) {
1430
+ $customOption->title = "Option #" . $option->getOptionId();
1431
+ }
1432
  $customOption->type = $option->getType();
1433
  $customOption->required = $option->getIsRequire();
1434
+ if ($this->_DEBUG) {
1435
+ $this->controller->getResponse()->appendBody($customOption->toString() . "
1436
+ ");
1437
+ }
1438
+ $optionValues = $orderedOptionValues[$option->getOptionId()];
1439
  $isMultiple = ( $option->getType() == "multiple" || $option->getType() == "checkbox" );
1440
+ if (!$option->getIsRequire() && !$isMultiple) {
1441
  $coValue = new COValue();
1442
  $coValue->title = FALSE;
1443
  $coValue->sku = FALSE;
1445
  $coValue->pvalue = 0;
1446
  $coValue->rprice = 0;
1447
  $coValue->sprice = 0;
1448
+ if ($this->_DEBUG) {
1449
+ $this->controller->getResponse()->appendBody($coValue->toString() . "
1450
+ ");
1451
+ }
1452
  $customOption->values[] = $coValue;
1453
  }
1454
+ if ($option->getType() == "date" ||
1455
+ $option->getType() == "time" ||
1456
+ $option->getType() == "date_time" ||
1457
+ $option->getType() == "field" ||
1458
+ $option->getType() == "area") {
1459
+ if ($option->getSku()) {
1460
  $coValue = new COValue();
1461
  $coValue->title = "Provided";
1462
  $coValue->sku = $option->getSku();
1463
  $coValue->ifpercent = FALSE;
1464
  $coValue->pvalue = $option->getPrice();
1465
+ if ($option->getPriceType() == "percent") {
1466
  $coValue->ifpercent = TRUE;
1467
+ $coValue->rprice = round($ProdRPrice * $option->getPrice() / 100, 2);
1468
+ $coValue->sprice = $ProdSPrice > -1 ? round($ProdSPrice * $option->getPrice() / 100, 2) : -1;
1469
  } else {
1470
  $coValue->rprice = $option->getPrice();
1471
  $coValue->sprice = $ProdSPrice > -1 ? $option->getPrice() : -1;
1472
  }
1473
+ if ($this->_DEBUG) {
1474
+ $this->controller->getResponse()->appendBody($coValue->toString() . "
1475
+ ");
1476
+ }
1477
  $customOption->values[] = $coValue;
1478
  }
1479
  } else {
1480
+ foreach ($optionValues as $optionValue) {
1481
+ if ($this->_DEBUG) {
1482
+ $this->controller->getResponse()->appendBody("value title=" . $optionValue->getTitle() . " storeTitle=" . $optionValue->getStoreTitle() . " price=" . $optionValue->getPrice() . " price_type=" . $optionValue->getPriceType() . " sku=" . $optionValue->getSku() . " sort_order=" . $optionValue->getSortOrder() . "
1483
+ ");
1484
+ }
1485
+ if ($optionValue->getSku()) {
1486
  $coValue = new COValue();
1487
  $coValue->title = $optionValue->getStoreTitle();
1488
+ if (!$coValue->title) {
1489
  $coValue->title = $optionValue->getTitle();
1490
+ }
1491
+ if (!$coValue->title) {
1492
  $coValue->title = "Option value";
1493
+ }
1494
  $coValue->sku = $optionValue->getSku();
1495
  $coValue->ifpercent = FALSE;
1496
  $coValue->pvalue = $optionValue->getPrice();
1497
+ if ($optionValue->getPriceType() == "percent") {
1498
  $coValue->ifpercent = TRUE;
1499
+ $coValue->rprice = round($ProdRPrice * $optionValue->getPrice() / 100, 2);
1500
+ $coValue->sprice = $ProdSPrice > -1 ? round($ProdSPrice * $optionValue->getPrice() / 100, 2) : -1;
1501
  } else {
1502
  $coValue->rprice = $optionValue->getPrice();
1503
  $coValue->sprice = $ProdSPrice > -1 ? $optionValue->getPrice() : -1;
1504
  }
1505
+ if ($this->_DEBUG) {
1506
+ $this->controller->getResponse()->appendBody($coValue->toString() . "
1507
+ ");
1508
+ }
1509
  $customOption->values[] = $coValue;
1510
  }
1511
  }
1512
  }
1513
+ if ($isMultiple && count($customOption->values) > 1) {
1514
+ $customOption->values = array_reverse($customOption->values);
1515
+ }
1516
+ if (count($customOption->values) == 0) {
1517
+ // OK
1518
+ } else if (count($customOption->values) == 1) {
1519
+ if ($customOption->values[0]->sku) {
1520
  $customOptions[] = $customOption;
1521
+ }
1522
  } else {
1523
  $customOptions[] = $customOption;
1524
  }
1525
+ $customOptionsById[$customOption->id] = $customOption;
1526
  }
1527
+ if ($this->_DEBUG) {
1528
+ $this->controller->getResponse()->appendBody("Resulting options / values
1529
+ ");
1530
+ foreach ($customOptions as $option) {
1531
+ $this->controller->getResponse()->appendBody($option->toString() . "
1532
+ ");
1533
+ foreach ($option->values as $value) {
1534
+ $this->controller->getResponse()->appendBody($value->toString() . "
1535
+ ");
1536
+ }
1537
  }
1538
  }
1539
+ if (count($customOptions) > 0) {
1540
  $coValueSetSequences = array();
1541
  $coValueSetSequence = array();
1542
+ $this->_buildCOValueSets($coValueSetSequences, $coValueSetSequence, 0, $customOptions);
1543
  $index = 1;
1544
+ foreach ($coValueSetSequences as $coValueSetSequence) {
1545
+ if ($this->_DEBUG) {
1546
+ $this->controller->getResponse()->appendBody("coValueSetSequence #" . $index . "
1547
+ ");
1548
+ foreach ($coValueSetSequence as $coValueSet) {
1549
+ $this->controller->getResponse()->appendBody($coValueSet->toString() . "
1550
+ ");
1551
+ }
1552
  }
1553
  $ItemNumber = $prodSku;
1554
  $RPrice = $ProdRPrice;
1555
  $SPrice = $ProdSPrice;
1556
  $ItemAttributes = "";
1557
+ if ($this->includeinvqty) {
1558
+ if (!empty($ItemAttributes)) {
1559
  $ItemAttributes .= "|";
1560
+ }
1561
+ $ItemAttributes = "Inventory=" . $this->_formatQty("" . $this->catalogInventoryModel->loadByProduct($product)->getQty());
1562
  }
1563
+ foreach ($coValueSetSequence as $coValueSet) {
1564
+ $cOption = $customOptionsById[$coValueSet->optionId];
1565
+ if (!empty($ItemAttributes)) {
1566
  $ItemAttributes .= "|";
1567
+ }
1568
+ $ItemAttributes .= $cOption->title . "=";
1569
  $vcount = 0;
1570
+ foreach ($coValueSet->coValues as $value) {
1571
+ if ($value->sku) {
1572
+ if ($ItemNumber) {
1573
+ $ItemNumber .= "-";
1574
+ }
1575
  $ItemNumber .= $value->sku;
1576
  $RPrice += $value->rprice;
1577
+ if ($SPrice >= 0) {
1578
+ $SPrice += $value->sprice;
1579
+ }
1580
+ if ($vcount > 0) {
1581
+ $ItemAttributes .= ", ";
1582
+ }
1583
  $ItemAttributes .= $value->title;
1584
  $vcount++;
1585
  }
1586
  }
1587
  }
1588
+ if (empty($ItemNumber)) {
1589
+ if ($this->_DEBUG) {
1590
+ $this->controller->getResponse()->appendBody("NO ItemNumber
1591
+ ");
1592
+ }
1593
  continue;
1594
  }
1595
+ if (!empty($RPrice) && $this->includetaxes) {
1596
+ $RPrice = $this->taxhelper->getPrice($product, $RPrice, true, null, null, null, $this->StoreId);
1597
+ }
1598
+ if ($SPrice >= 0 && $this->includetaxes) {
1599
+ $SPrice = $this->taxhelper->getPrice($product, $SPrice, true, null, null, null, $this->StoreId);
1600
+ }
1601
+ if ($this->_DEBUG) {
1602
+ $this->controller->getResponse()->appendBody("resulting prices: Regular=" . $RPrice . " Special=" . $SPrice . " FromDate=" . $ProdSFromDate . " ToDate=" . $ProdSToDate . "
1603
+ ");
1604
+ }
1605
+ $RPrice = $this->_formatPrice($RPrice);
1606
+ if ($this->includespecialprice) {
1607
+ if ($SPrice >= 0) {
1608
+ $SPrice = $this->_formatPrice($SPrice);
1609
+ if (!empty($ItemAttributes)) {
1610
  $ItemAttributes .= "|";
1611
+ }
1612
+ $ItemAttributes .= "Special Price=" . $SPrice;
1613
  }
1614
  }
1615
+ if ($this->includespecialpricedatefrom) {
1616
+ if (!empty($ProdSFromDate)) {
1617
+ if (!empty($ItemAttributes)) {
1618
  $ItemAttributes .= "|";
1619
+ }
1620
+ $ItemAttributes .= "Special Price From Date=" . substr($ProdSFromDate, 0, 10);
1621
  }
1622
  }
1623
+ if ($this->includespecialpricedateto) {
1624
+ if (!empty($ProdSToDate)) {
1625
+ if (!empty($ItemAttributes)) {
1626
  $ItemAttributes .= "|";
1627
+ }
1628
+ $ItemAttributes .= "Special Price To Date=" . substr($ProdSToDate, 0, 10);
1629
  }
1630
  }
1631
+ if ($this->getgroupprices && $ProdSpecGroupPrices) {
1632
+ foreach ($ProdSpecGroupPrices as $groupPrice) {
1633
+ $price = 0.0 + $groupPrice['price'];
1634
  $price0 = $price;
1635
+ foreach ($coValueSetSequence as $coValueSet) {
1636
+ foreach ($coValueSet->coValues as $value) {
1637
+ if ($value->sku) {
1638
+ if ($value->ifpercent) {
1639
+ $price = $price + round($price0 * $value->pvalue / 100, 2);
1640
  } else {
1641
  $price = $price + $value->pvalue;
1642
  }
1643
  }
1644
  }
1645
  }
1646
+ if ($price >= 0 && $this->includetaxes) {
1647
+ $price = $this->taxhelper->getPrice($product, $price, true, null, null, null, $this->StoreId);
1648
+ }
1649
+ if (!empty($ItemAttributes)) {
1650
  $ItemAttributes .= "|";
1651
+ }
1652
+ $ItemAttributes .= "price_" . $this->customerGroups[$groupPrice['cust_group']] . "=" . $this->_formatPrice($price);
1653
  }
1654
  }
1655
+ if ($this->_DEBUG) {
1656
+ $this->controller->getResponse()->appendBody("resulting attrs: " . $ItemAttributes . "
1657
+ ");
1658
+ }
1659
  $ProducttoString .= $ItemNumber //ItemID
1660
+ . "\t" //ItemQty
1661
+ . "\t" //ItemUom
1662
+ . "\t" . $RPrice //ItemPrice
1663
+ . "\t" //ItemDescription
1664
+ . "\t" //ItemLink
1665
+ . "\t" . $ItemAttributes //ItemAttributes
1666
+ . "\t" //ItemitemGraphic
1667
+ . "\t" . $prodName //ProductName
1668
+ . "\t" . $ProductDescription //ProductDescription
1669
+ . "\t" . $prodImages //ProductGraphic
1670
+ . "\t" . $URL //ProductLink
1671
+ . "\t" . $ProductAttributes //ProductAttributes
1672
+ . "\t" . $Manufacturer //Manufacturer
1673
+ . "\t" //Category
1674
+ . "\t" . $Reviews //Reviews
1675
+ . "\t" . $shortDescription
1676
+ . "\t" . $index
1677
+ . "\n";
1678
  $skusAdded = TRUE;
1679
  // https://objectpublisher.basecamphq.com/projects/257020-odp/posts/87233819/comments#comment_312388129
1680
+ if ($index >= 200) {
1681
+ $ProducttoString .= "REPORTWARNING: Not all options were converted to items for the product #" . $product->getId() . " - \"" . $cleanProdName . "\".
1682
  ";
1683
  break;
1684
  }
1687
  }
1688
  }
1689
  }
1690
+ if (!$skusAdded) {
1691
  $RPrice = $ProdRPrice;
1692
+ if (!empty($RPrice) && $this->includetaxes) {
1693
+ $RPrice = $this->taxhelper->getPrice($product, $RPrice, true, null, null, null, $this->StoreId);
1694
+ }
1695
  $SPrice = $ProdSPrice;
1696
+ if ($SPrice >= 0 && $this->includetaxes) {
1697
+ $SPrice = $this->taxhelper->getPrice($product, $SPrice, true, null, null, null, $this->StoreId);
1698
+ }
1699
+ if ($this->_DEBUG) {
1700
+ $this->controller->getResponse()->appendBody("resulting prices: Regular=" . $RPrice . " Special=" . $SPrice . " FromDate=" . $ProdSFromDate . " ToDate=" . $ProdSToDate . "
1701
+ ");
1702
+ }
1703
  $ItemAttributes = "";
1704
+ if ($this->includeinvqty) {
1705
+ $ItemAttributes = "Inventory=" . $this->_formatQty("" . $this->catalogInventoryModel->loadByProduct($product)->getQty());
1706
+ }
1707
+ $RPrice = $this->_formatPrice($RPrice);
1708
+ if ($this->includespecialprice) {
1709
+ if ($SPrice >= 0) {
1710
+ $SPrice = $this->_formatPrice($SPrice);
1711
+ if (!empty($ItemAttributes)) {
1712
  $ItemAttributes .= "|";
1713
+ }
1714
+ $ItemAttributes .= "Special Price=" . $SPrice;
1715
  }
1716
  }
1717
+ if ($this->includespecialpricedatefrom) {
1718
+ if (!empty($ProdSFromDate)) {
1719
+ if (!empty($ItemAttributes)) {
1720
  $ItemAttributes .= "|";
1721
+ }
1722
+ $ItemAttributes .= "Special Price From Date=" . substr($ProdSFromDate, 0, 10);
1723
  }
1724
  }
1725
+ if ($this->includespecialpricedateto) {
1726
+ if (!empty($ProdSToDate)) {
1727
+ if (!empty($ItemAttributes)) {
1728
  $ItemAttributes .= "|";
1729
+ }
1730
+ $ItemAttributes .= "Special Price To Date=" . substr($ProdSToDate, 0, 10);
1731
  }
1732
  }
1733
+ if ($this->getgroupprices && $ProdSpecGroupPrices) {
1734
+ foreach ($ProdSpecGroupPrices as $groupPrice) {
1735
+ $price = 0.0 + $groupPrice['price'];
1736
+ if ($price >= 0 && $this->includetaxes) {
1737
+ $price = $this->taxhelper->getPrice($product, $price, true, null, null, null, $this->StoreId);
1738
+ }
1739
+ if (!empty($ItemAttributes)) {
1740
  $ItemAttributes .= "|";
1741
+ }
1742
+ $ItemAttributes .= "price_" . $this->customerGroups[$groupPrice['cust_group']] . "=" . $this->_formatPrice($price);
1743
  }
1744
  }
1745
  $ProducttoString = $prodSku //ItemID
1746
+ . "\t" //ItemQty
1747
+ . "\t" //ItemUom
1748
+ . "\t" . $RPrice //ItemPrice
1749
+ . "\t" //ItemDescription
1750
+ . "\t" //ItemLink
1751
+ . "\t" . $ItemAttributes //ItemAttributes
1752
+ . "\t" //ItemitemGraphic
1753
+ . "\t" . $prodName //ProductName
1754
+ . "\t" . $ProductDescription //ProductDescription
1755
+ . "\t" . $prodImages //ProductGraphic
1756
+ . "\t" . $URL //ProductLink
1757
+ . "\t" . $ProductAttributes //ProductAttributes
1758
+ . "\t" . $Manufacturer //Manufacturer
1759
+ . "\t" //Category
1760
+ . "\t" . $Reviews //Reviews
1761
+ . "\t" . $shortDescription
1762
+ . "\t1"
1763
+ . "\n";
1764
  }
1765
  return $ProducttoString;
1766
  }
1769
  private $configItemSequence = 0;
1770
  private $configProducttoString = "";
1771
 
1772
+ private function _fillCPLinesMatrix($attrNumber, $optNo, &$cpLine, &$cpLinesMatrix) {
1773
+ $optionId = $cpLine->optionIds[$attrNumber];
1774
+ if ($attrNumber < $optNo - 1) {
1775
+ if (!isset($cpLinesMatrix[$optionId])) {
1776
+ $cpLinesMatrix[$optionId] = array();
1777
+ }
1778
+ $this->_fillCPLinesMatrix($attrNumber + 1, $optNo, $cpLine, $cpLinesMatrix[$optionId]);
1779
  } else {
1780
+ if (!isset($cpLinesMatrix[$optionId])) {
1781
+ $cpLinesMatrix[$optionId] = $cpLine;
1782
+ }
1783
  }
1784
  }
1785
 
1786
+ private function _fillConfigProdItems($attrNumber, $attrNo, &$optNumbers, &$optionIds, &$optCounters, &$cpLinesMatrix) {
1787
  $optNumber = 0;
1788
+ $optionIdNo = $optCounters[$attrNumber];
1789
+ while ($optNumber < $optionIdNo) {
1790
+ $optionID = $optionIds[$attrNumber][$optNumber];
1791
+ if (isset($cpLinesMatrix[$optionID])) {
1792
+ if ($attrNumber < $attrNo - 1) {
1793
+ $optNumbers[$attrNumber] = $optNumber;
1794
+ $this->_fillConfigProdItems($attrNumber + 1, $attrNo, $optNumbers, $optionIds, $optCounters, $cpLinesMatrix[$optionID]);
1795
  } else {
1796
+ $cpLine = $cpLinesMatrix[$optionID];
1797
  $this->configProducttoString .= $cpLine->line
1798
+ . $this->prodLine
1799
+ . $this->configItemSequence
1800
+ . "\n";
1801
  $cpLine->line = FALSE;
1802
  $this->configItemSequence++;
1803
  }
1805
  $optNumber++;
1806
  }
1807
  }
1808
+
1809
+ private function _getCustomOptionsAsAttributes(&$product) {
1810
  $attributes = "";
1811
  $customOptions = $product->getOptions();
1812
+ if ($customOptions) {
1813
  //We should support all 4 selects: dropdown, radio buttons, checkbox, and multiple select.
1814
  //\app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php
1815
+ if ($this->_DEBUG) {
1816
+ $this->controller->getResponse()->appendBody("=== customOptions ===
1817
+ ");
1818
+ }
1819
  $max_sort_order = 0;
1820
+ foreach ($customOptions as $option) {
1821
+ if ($option->getSortOrder() > $max_sort_order) {
1822
  $max_sort_order = $option->getSortOrder();
1823
+ } else if ($option->getSortOrder() < 0) {
1824
+ $option->setSortOrder(-1);
1825
  }
1826
  }
1827
+ if ($this->_DEBUG) {
1828
+ for ($sortorder = -1; $sortorder <= $max_sort_order; $sortorder++) {
1829
  foreach ($customOptions as $option) {
1830
+ if ($option->getSortOrder() != $sortorder) {
1831
+ continue;
1832
+ }
1833
+ $this->controller->getResponse()->appendBody("customOption #" . $option->getOptionId() . " title=" . $option->getTitle() . " storeTitle=" . $option->getStoreTitle() . " type=" . $option->getType() . " sort_order" . $option->getSortOrder() . "
1834
+ ");
1835
+ if ($option->getValues()) {
1836
  $max_v_sort_order = 0;
1837
  foreach ($option->getValues() as $_value) {
1838
+ if ($_value->getSortOrder() > $max_v_sort_order) {
1839
  $max_v_sort_order = $_value->getSortOrder();
1840
+ } else if ($_value->getSortOrder() < 0) {
1841
+ $_value->setSortOrder(-1);
1842
  }
1843
  }
1844
+ for ($vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++) {
1845
+ if ($_value->getSortOrder() != $vsortorder) {
1846
+ continue;
1847
+ }
1848
  foreach ($option->getValues() as $_value) {
1849
+ $this->controller->getResponse()->appendBody("value title=" . $_value->getTitle() . " storeTitle=" . $option->getStoreTitle() . " price=" . $_value->getPrice() . " price_type=" . $_value->getPriceType() . " sku=" . $_value->getSku() . " sort_order=" . $_value->getSortOrder() . "
1850
+ ");
1851
  }
1852
  }
1853
  }
1854
  }
1855
  }
1856
  }
1857
+ for ($sortorder = -1; $sortorder <= $max_sort_order; $sortorder++) {
1858
  foreach ($customOptions as $option) {
1859
+ if ($option->getSortOrder() != $sortorder) {
1860
+ continue;
1861
+ }
1862
+ if ($option->getType() != "drop_down" && $option->getType() != "radio" && $option->getType() != "multiple" && $option->getType() != "checkbox") {
1863
+ continue;
1864
+ }
1865
  $optionTitle = $option->getStoreTitle();
1866
+ if (empty($optionTitle)) {
1867
  $optionTitle = $option->getTitle();
1868
+ }
1869
  $optionValues = "";
1870
+ if ($option->getValues()) {
1871
  $max_v_sort_order = 0;
1872
+ foreach ($option->getValues() as $_value) {
1873
+ if ($_value->getSortOrder() > $max_v_sort_order) {
1874
  $max_v_sort_order = $_value->getSortOrder();
1875
+ } else if ($_value->getSortOrder() < 0) {
1876
+ $_value->setSortOrder(-1);
1877
  }
1878
  }
1879
+ for ($vsortorder = -1; $vsortorder <= $max_v_sort_order; $vsortorder++) {
1880
+ foreach ($option->getValues() as $_value) {
1881
+ if ($_value->getSortOrder() != $vsortorder) {
1882
+ continue;
1883
+ }
1884
+ if (!empty($optionValues)) {
1885
  $optionValues .= "<br/>";
1886
+ }
1887
  $valueTitle = $_value->getStoreTitle();
1888
+ if (empty($valueTitle)) {
1889
  $valueTitle = $_value->getTitle();
1890
+ }
1891
  $optionValues .= $valueTitle;
1892
  }
1893
  }
1894
  }
1895
+ if (!empty($attributes)) {
1896
  $attributes .= "|";
1897
+ }
1898
  $attributes .= $optionTitle . "=" . $optionValues;
1899
  }
1900
  }
1901
  }
1902
  return $attributes;
1903
  }
1904
+
1905
+ private function _buildCOValueSets(&$coValueSetSequences, $coValueSetSequence, $index, &$customOptions) {
1906
+ $cOption = $customOptions[$index];
1907
+ $customOptionCount = count($customOptions);
1908
  $coValueSetList = array();
1909
+ if ($cOption->type == "multiple" || $cOption->type == "checkbox") {
1910
  // all combinations + empty if not required
1911
+ $valuesCount = count($cOption->values);
1912
  $indexList = array();
1913
  $indices = array();
1914
+ $this->_buildCOValueIndices($indexList, $indices, $valuesCount - 1);
1915
+ foreach ($indexList as $indices) {
1916
  $coValueSet = new COValueSet();
1917
  $coValueSet->optionId = $cOption->id;
1918
  $valueIndexNo = 0;
1919
+ foreach ($indices as $valueIndex) {
1920
+ if ($valueIndex == 1) {
1921
+ $coValueSet->coValues[] = $cOption->values[$valueIndexNo];
1922
+ }
1923
  $valueIndexNo++;
1924
  }
1925
+ if (!$cOption->required && count($coValueSet->coValues) == 0) {
1926
  $coValue = new COValue();
1927
  $coValue->title = FALSE;
1928
  $coValue->sku = FALSE;
1930
  $coValue->sprice = 0;
1931
  $coValueSet->coValues[] = $coValue;
1932
  }
1933
+ if (count($coValueSet->coValues) == 0) {
1934
  continue;
1935
+ }
1936
+ if (count($coValueSet->coValues) > 1) {
1937
+ $coValueSet->coValues = array_reverse($coValueSet->coValues);
1938
+ }
1939
  $coValueSetList[] = $coValueSet;
1940
  }
1941
  } else {
1942
+ foreach ($cOption->values as $optionValue) {
1943
  $coValueSet = new COValueSet();
1944
  $coValueSet->optionId = $cOption->id;
1945
  $coValueSet->coValues[] = $optionValue;
1946
  $coValueSetList[] = $coValueSet;
1947
  }
1948
  }
1949
+ $coValueSetListCount = count($coValueSetList);
1950
+ foreach ($coValueSetList as $coValueSet) {
1951
+ $coValueSetSequence[$index] = $coValueSet;
1952
+ if ($index == $customOptionCount - 1)
1953
  $coValueSetSequences[] = $coValueSetSequence;
1954
  else
1955
+ $this->_buildCOValueSets($coValueSetSequences, $coValueSetSequence, $index + 1, $customOptions);
1956
  }
1957
  }
1958
 
1959
+ private function _buildCOValueIndices(&$indexList, $indices, $index) {
1960
+ for ($i = 0; $i < 2; $i++) {
1961
+ $indices[$index] = $i;
1962
+ if ($index == 0) {
1963
  $indexList[] = $indices;
1964
+ } else {
1965
+ $this->_buildCOValueIndices($indexList, $indices, $index - 1);
1966
+ }
1967
  }
1968
  }
1969
 
1970
+ private function _cleanStr(&$str) {
1971
+ return str_replace("\n", " ", str_replace("\r", " ", str_replace("\r\n", " ", str_replace("\t", " ", $str))));
1972
  }
1973
 
1974
+ private function _correctProdUrlStr(&$str) {
1975
+ $str = str_replace(self::SCRIPTNAME, "index.php", $str);
1976
+ $pos = strpos($str, "?");
1977
+ if ($pos === false) {
1978
  return $str;
1979
+ } else if (substr($str, $pos) == "?___store=default") {
1980
+ return substr($str, 0, $pos);
1981
+ } else {
1982
+ return $str;
1983
+ }
1984
  }
1985
 
1986
+ private function _getReviews($productid) {
1987
  $reviewsCollection = $this->reviewsModel->getCollection()
1988
+ ->addStoreFilter($this->StoreId)
1989
+ ->addStatusFilter('approved')
1990
+ ->addEntityFilter('product', $productid)
1991
+ ->setDateOrder();
1992
  $Reviews = "";
1993
+ foreach ($reviewsCollection as $review) {
1994
+ $Reviews .= "<p><b>" . $review->getTitle() . "(" . $review->getNickname() . ")</b><br>" . $review->getDetail() . self::TAG_P_CLOSE;
1995
+ }
1996
+ unset($reviewsCollection);
1997
  return $Reviews;
1998
  }
1999
 
2000
+ private function _formatPrice($Price) {
2001
+ $v = 0.0;
2002
+ if (is_string($Price)) {
2003
+ $rv = str_replace("\n", " ", str_replace("\r", " ", str_replace("\r\n", " ", str_replace("\t", " ", $Price))));
2004
+ if (empty($rv) || $rv == "0") {
2005
+ return "";
2006
+ }
2007
+ $v = floatval($Price);
2008
+ } else if (is_float($Price)) {
2009
+ $v = $Price;
2010
  } else {
2011
+ $v = floatval($Price);
2012
  }
2013
+ if ($v <= 0) {
2014
+ return "";
2015
  }
2016
  $v100 = $v * 100;
2017
+ $iv100 = intval($v100);
2018
+ if ($v100 - $iv100 >= 0.5) {
2019
  $iv100 = $iv100 + 1;
2020
+ }
2021
+ $rv = strval(floatval($iv100) / 100);
2022
+ $tail = strrchr($rv, ".");
2023
+ if (!empty($tail) && strlen($tail) > 3) {
2024
+ $rv = substr($rv, 0, strlen($rv) - ( strlen($tail) - 3 ));
2025
+ } else if (!empty($tail) && strlen($tail) == 2) {
2026
+ $rv = $rv . "0";
2027
+ } else if (!empty($tail) && strlen($tail) == 1) {
2028
+ $rv = $rv . "00";
2029
+ } else if (!$tail) {
2030
+ $rv = $rv . ".00";
2031
+ }
2032
  return $rv;
2033
  }
2034
 
2035
+ private function _formatQty($qty) {
2036
+ $tail = strrchr($qty, ".");
2037
+ if (!empty($tail)) {
2038
+ $qty = substr($qty, 0, strlen($qty) - strlen($tail));
2039
+ }
2040
  return $qty;
2041
  }
2042
+
2043
+ private function _formatImageURL($str) {
2044
+ if ($str[0] != '/') {
2045
+ $str = "/" . $str;
2046
+ }
2047
  return $str;
2048
  }
2049
+
2050
+ private function _getTierPrices(&$product) {
2051
+ $res = "";
2052
  $prices = $product->getFormatedTierPrice();
2053
+ if ($this->_DEBUG && isset($prices)) {
2054
+ $this->controller->getResponse()->appendBody("public tier prices: " . var_export($prices, true) . "
2055
+ ");
2056
+ }
2057
  $rightstr = "";
2058
+ if (is_array($prices)) {
2059
+ $count = count($prices);
2060
+ if ($count > 0) {
2061
  $prodFinalPrice = $this->includetaxes ?
2062
+ $this->taxhelper->getPrice($product, $product->getData('price'), true, null, null, null, $this->StoreId) :
2063
+ $product->getData('price');
2064
+ if ($this->_DEBUG) {
2065
+ $this->controller->getResponse()->appendBody("prodFinalPrice: " . $prodFinalPrice . "
2066
+ ");
2067
+ }
2068
+ $res = '[TierPriceTable]#$$#' . $this->quantitylabel . '#$#' . $this->pricelabel . '#$#' . $this->savingslabel . "=";
2069
+ $i = 1;
2070
+ foreach ($prices as $price) {
2071
  $price['price_qty'] = $price['price_qty'] * 1;
2072
  $tierPrice = $this->includetaxes ?
2073
+ $this->taxhelper->getPrice($product, $price['price'], true, null, null, null, $this->StoreId) :
2074
+ $price['price'];
2075
+ if ($tierPrice < $prodFinalPrice) {
2076
+ $tierPrice = $this->_formatPrice("" . $tierPrice);
2077
+ $rightstr .= $price['price_qty'] . '#$#';
2078
+ $rightstr.=$tierPrice . '#$#';
2079
+ if ($i == $count) {
2080
+ $rightstr .= ceil(100 - (( 100 / $prodFinalPrice ) * $tierPrice )) . '%';
2081
+ } else {
2082
+ $rightstr .= ceil(100 - (( 100 / $prodFinalPrice ) * $tierPrice )) . '%#$$#';
2083
+ }
2084
  }
2085
  $i++;
2086
  }
2087
  }
2088
+ if (empty($rightstr)) {
2089
+ $res = "";
2090
  }
2091
  }
2092
+ unset($prices);
2093
+ if ($this->getgroupprices) {
2094
  $pairs = array();
2095
+ if (!empty($res)) {
2096
+ $pairs[] = $res . $rightstr;
2097
  }
2098
  $prices = $product->getData('tier_price');
2099
+ if ($this->_DEBUG && isset($prices)) {
2100
+ $this->controller->getResponse()->appendBody("all tier prices: " . var_export($prices, true) . "
2101
+ ");
2102
+ }
2103
+ foreach ($this->customerGroups as $gid => $gname) {
2104
+ if ($this->_DEBUG) {
2105
+ $this->controller->getResponse()->appendBody("group: " . $gid . "=>" . $gname . "
2106
+ ");
2107
+ }
2108
+ if ($gid == 0) {
2109
  continue;
2110
  }
2111
+ $res = "";
2112
  $rightstr = "";
2113
  $gprices = array();
2114
+ foreach ($prices as $price) {
2115
+ if ($price['all_groups'] == '1' || $price['cust_group'] == $gid) {
2116
  $gprices[] = $price;
2117
  }
2118
  }
2119
+ $count = count($gprices);
2120
+ if ($count > 0) {
2121
+ if (!isset($prodFinalPrice)) {
2122
  $prodFinalPrice = $this->includetaxes ?
2123
+ $this->taxhelper->getPrice($product, $product->getData('price'), true, null, null, null, $this->StoreId) :
2124
+ $product->getData('price');
2125
+ if ($this->_DEBUG) {
2126
+ $this->controller->getResponse()->appendBody("prodFinalPrice: " . $prodFinalPrice . "
2127
+ ");
2128
+ }
2129
  }
2130
+ $res = '[TierPriceTable_' . $gname . ']#$$#' . $this->quantitylabel . '#$#' . $this->pricelabel . '#$#' . $this->savingslabel . "=";
2131
+ $i = 1;
2132
+ foreach ($gprices as $price) {
2133
  $price['price_qty'] = $price['price_qty'] * 1;
2134
  $tierPrice = $this->includetaxes ?
2135
+ $this->taxhelper->getPrice($product, $price['price'], true, null, null, null, $this->StoreId) :
2136
+ $price['price'];
2137
+ if ($tierPrice < $prodFinalPrice) {
2138
+ $tierPrice = $this->_formatPrice("" . $tierPrice);
2139
+ $rightstr .= $price['price_qty'] . '#$#';
2140
+ $rightstr.=$tierPrice . '#$#';
2141
+ if ($i == $count) {
2142
+ $rightstr .= ceil(100 - (( 100 / $prodFinalPrice ) * $tierPrice )) . '%';
2143
+ } else {
2144
+ $rightstr .= ceil(100 - (( 100 / $prodFinalPrice ) * $tierPrice )) . '%#$$#';
2145
+ }
2146
  }
2147
  $i++;
2148
  }
2149
  }
2150
+ if (!empty($rightstr)) {
2151
+ $pairs[] = $res . $rightstr;
2152
  }
2153
  }
2154
+ return count($pairs) > 0 ? implode("|", $pairs) : FALSE;
2155
+ } else
2156
+ return $res . $rightstr;
2157
  }
2158
 
2159
  // Class=CatalogSection
2160
+ public function renderCatalogSection() {
2161
  $categories = Mage::getModel('catalog/category')
2162
+ ->setStoreId($this->StoreId)
2163
+ ->getCollection()
2164
+ ->addAttributeToSelect('name')
2165
+ ->addAttributeToFilter('level', array('eq' => 2))
2166
+ ->addAttributeToFilter('is_active', array('eq' => 1))
2167
+ ->addAttributeToSort('position', 'asc');
2168
+ $i = 1;
2169
+ $count = count($categories);
2170
+ if ($this->_DEBUG) {
2171
+ $this->controller->getResponse()->appendBody("StoreId: " . $this->StoreId . " Top categories: " . $count . "
2172
+ ");
2173
+ }
2174
+ $this->controller->getResponse()->appendBody("sec_Project\tsec_Sequence\tsec_HierarchyPath\tsec_Flag\n");
2175
+ if ($count > 0) {
2176
+ if ($this->ignoretopcategory) {
2177
+ foreach ($categories as $topcategory) {
2178
  $children = $topcategory->getCollection();
2179
+ $children->setStoreId($this->StoreId)
2180
  ->addAttributeToSelect('name')
2181
  ->addAttributeToFilter('is_active', array('eq' => 1))
2182
  ->addAttributeToSort('position', 'asc')
2183
  ->addIdFilter($topcategory->getChildren())
2184
+ ->load();
2185
+ foreach ($children as $category) {
2186
  $name = $category->getName();
2187
  $id = $category->getId();
2188
+ $this->controller->getResponse()->appendBody($this->_drawCategory($category, 1, $name, $i));
2189
  $i++;
2190
  }
2191
  }
2192
+ } else {
2193
+ foreach ($categories as $category) {
2194
  $name = $category->getName();
2195
  $id = $category->getId();
2196
+ $this->controller->getResponse()->appendBody($this->_drawCategory($category, 1, $name, $i));
2197
  $i++;
2198
  }
2199
  }
2200
  }
2201
  $lastId = $i;
2202
+ $this->controller->getResponse()->appendBody("General\t" . $lastId . "\tUncategorized\t
2203
+ ");
2204
+ $this->controller->getResponse()->appendBody("==EOF==");
2205
  }
2206
 
2207
+ private function _drawCategory(&$category, $level = 0, $hpath = '', $i = 1, $j = 1, $path = '') {
2208
  $html = "";
2209
  $children = $category->getCollection();
2210
+ $children->setStoreId($this->StoreId)
2211
  ->addAttributeToSelect('name')
2212
  ->addAttributeToFilter('is_active', array('eq' => 1))
2213
  ->addAttributeToSort('position', 'asc')
2214
  ->addIdFilter($category->getChildren())
2215
+ ->load();
 
2216
  $sec_path = "";
2217
+ if ($level != 1) {
2218
  $path .= '-' . $j;
2219
+ $hpath = $hpath . '#$#' . $category->getName(); //.' '.$i.$path;
2220
+ $sec_path .= str_replace("-", ",", $path);
2221
+ $seq = $i . $sec_path;
2222
+ } else {
2223
  $hpath = $category->getName(); //.' '.$i;
2224
  $seq = $i;
2225
  }
2226
+ $html = "General\t" . $seq . "\t" . $hpath . "\t\n";
2227
  $htmlChildren = "";
2228
+ if (count($children)) {
2229
  $j = 1;
2230
+ foreach ($children as $cat) {
2231
+ $htmlChildren .= $this->_drawCategory($cat, $level + 1, $hpath, $i, $j, $path);
2232
  $j++;
2233
  }
2234
  }
2235
+ unset($children);
2236
  return $html .= $htmlChildren;
2237
  }
2238
 
2239
  // Class=CatalogProject
2240
+ public function renderCatalogProject() {
2241
+ if ($this->splitgroupedproducts) {
2242
  $this->productTypeGroupedModel = Mage::getModel('catalog/product_type_grouped');
2243
  }
2244
  $this->productTypeConfigurableModel = Mage::getModel('catalog/product_type_configurable');
2245
+ $this->storeSorting = Mage::getSingleton('catalog/config')->getProductListDefaultSortBy($this->StoreId);
2246
  $categories = Mage::getModel('catalog/category')
2247
+ ->setStoreId($this->StoreId)
2248
+ ->getCollection()
2249
+ ->addAttributeToSelect('name')
2250
+ ->addAttributeToSelect('default_sort_by')
2251
+ ->addAttributeToFilter('level', array('eq' => 2))
2252
+ ->addAttributeToFilter('is_active', array('eq' => 1))
2253
+ ->addAttributeToSort('position', 'asc');
2254
+ $count = count($categories);
2255
+ if ($this->_DEBUG) {
2256
+ $this->controller->getResponse()->appendBody("StoreId: " . $this->StoreId . " Top categories: " . $count . "
2257
+ ");
2258
+ }
2259
+ if ($count > 0) {
2260
  $hpath = "";
2261
+ if ($this->ignoretopcategory) {
2262
+ foreach ($categories as $topcategory) {
2263
+ if ($this->_DEBUG) {
2264
+ $this->controller->getResponse()->appendBody("Category: " . $topcategory->getName() . "
2265
+ ");
2266
+ $this->controller->getResponse()->appendBody("DefaultSortBy: " . $topcategory->getDefaultSortBy() . "
2267
+ ");
2268
+ }
2269
  $children = $topcategory->getCollection();
2270
+ $children->setStoreId($this->StoreId)
2271
  ->addAttributeToSelect('name')
2272
+ ->addAttributeToSelect('default_sort_by')
2273
  ->addAttributeToFilter('is_active', array('eq' => 1))
2274
  ->addAttributeToSort('position', 'asc')
2275
  ->addIdFilter($topcategory->getChildren())
2276
+ ->load();
2277
+ foreach ($children as $category) {
2278
+ if ($this->_DEBUG) {
2279
+ $this->controller->getResponse()->appendBody("Category: " . $category->getName()
2280
+ . " sortBy: " . $category->_getData('default_sort_by')
2281
+ . " storeSortBy: " . Mage::getSingleton('catalog/config')->getProductListDefaultSortBy($this->StoreId)
2282
+ . " resulting DefaultSortBy: " . $category->getDefaultSortBy()
2283
+ . "
2284
+ ");
2285
+ }
2286
+ $this->catmap[$category->getId()] = $category;
2287
+ $this->_processCategory($category, 1, $hpath);
2288
  }
2289
  }
2290
+ } else {
2291
+ foreach ($categories as $category) {
2292
+ if ($this->_DEBUG) {
2293
+ $this->controller->getResponse()->appendBody("Category: " . $category->getName()
2294
+ . " sortBy: " . $category->_getData('default_sort_by')
2295
+ . " storeSortBy: " . Mage::getSingleton('catalog/config')->getProductListDefaultSortBy($this->StoreId)
2296
+ . " resulting DefaultSortBy: " . $category->getDefaultSortBy()
2297
+ . "
2298
+ ");
2299
+ }
2300
+ $this->catmap[$category->getId()] = $category;
2301
+ $this->_processCategory($category, 1, $hpath);
2302
  }
2303
  }
2304
  }
2305
  $this->unCatPosition = 1;
2306
+ if ($this->start == 0) {
2307
+ $this->controller->getResponse()->appendBody("proj_Key\tproj_ProdName\tproj_Sequence\tproj_Name\tproj_HierarchyPath\tproj_Flag\tproj_ProdLayout
2308
+ ");
2309
+ }
2310
+ $products = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->getCollection();
2311
+ $products->addAttributeToFilter('status', 1); //enabled
2312
+ $products->addAttributeToFilter('visibility', 4); //catalog, search
2313
+ $prodIds = $this->_DEBUG ? $products->getAllIds(1000, 0) : $products->getAllIds();
2314
+ if ($this->_DEBUG) {
2315
+ $this->controller->getResponse()->appendBody("StoreId: " . $this->StoreId . " Products: " . count($prodIds) . "
2316
+ ");
2317
+ }
2318
  $count = 0;
2319
  $index = 0;
2320
  $lastLine = "==EOF==
2321
  ";
2322
+ foreach ($prodIds as $productId) {
2323
+ if ($count == $this->pageSize) {
2324
  $lastLine = "==MORE==
2325
  ";
2326
  break;
2327
  }
2328
+ if ($index < $this->start) {
2329
  $index++;
2330
  continue;
2331
  }
2332
  $index++;
2333
+ $product = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($productId);
2334
+ if ($product->isConfigurable()) {
2335
+ $this->controller->getResponse()->appendBody($this->CatalogProjectStringConfigurable($product));
2336
+ } else if ($product->isGrouped() && $this->splitgroupedproducts) {
2337
+ $this->controller->getResponse()->appendBody($this->CatalogProjectStringGroupedAsSimple($product));
2338
  } else {
2339
+ $this->controller->getResponse()->appendBody($this->CatalogProjectStringGroupedOrSimple($product));
2340
+ }
2341
+ unset($product);
2342
+ if ($this->_DEBUG) {
2343
+ $this->controller->getResponse()->appendBody("#" . $count . ": memory_get_usage " . memory_get_usage() . " / " . memory_get_usage(TRUE) . "
2344
+ ");
2345
  }
 
 
 
2346
  $count++;
2347
  }
2348
+ $this->controller->getResponse()->appendBody($lastLine);
2349
  }
2350
 
2351
+ private function _processCategory(&$category, $level = 0, $hpath = '', $path = '') {
2352
+ $hpath = $level != 1 ? $hpath . '#$#' . $category->getName() : $hpath = $category->getName();
2353
+ $this->catpathmap[$category->getId()] = $hpath;
2354
+ if ($this->_DEBUG) {
2355
+ $this->controller->getResponse()->appendBody("Category: " . $category->getId() . " path=" . $hpath . "
2356
+ ");
2357
+ }
2358
  $children = $category->getCollection();
2359
+ $children->setStoreId($this->StoreId)
2360
  ->addAttributeToSelect('name')
2361
+ ->addAttributeToSelect('default_sort_by')
2362
  ->addAttributeToFilter('is_active', array('eq' => 1))
2363
  ->addAttributeToSort('position', 'asc')
2364
  ->addIdFilter($category->getChildren())
2365
+ ->load();
2366
  $htmlChildren = "";
2367
+ if (count($children)) {
2368
+ foreach ($children as $childcategory) {
2369
+ if ($this->_DEBUG) {
2370
+ $this->controller->getResponse()->appendBody("Category: " . $childcategory->getName()
2371
+ . " sortBy: " . $childcategory->_getData('default_sort_by')
2372
+ . " storeSortBy: " . Mage::getSingleton('catalog/config')->getProductListDefaultSortBy($this->StoreId)
2373
+ . " resulting DefaultSortBy: " . $childcategory->getDefaultSortBy()
2374
+ . "
2375
+ ");
2376
+ }
2377
+ $this->catmap[$childcategory->getId()] = $childcategory;
2378
+ $htmlChildren .= $this->_processCategory($childcategory, $level + 1, $hpath, $path);
2379
+ }
2380
+ }
2381
  }
2382
 
2383
+ private function CatalogProjectStringGroupedOrSimple(&$product) {
2384
  $ProducttoString = "";
2385
  $categoryIds = $product->getCategoryIds();
2386
  $listed = FALSE;
2387
+ if ($categoryIds) {
2388
+ foreach ($categoryIds as $k => $category_id) {
2389
+ if (!isset($this->catmap[$category_id])) {
2390
+ if ($this->_DEBUG) {
2391
+ $this->controller->getResponse()->appendBody("No category: " . $category_id . "
2392
+ ");
2393
+ }
2394
  continue;
2395
  }
2396
+ $category = $this->catmap[$category_id];
2397
+ $hpath = $this->catpathmap[$category_id];
2398
  $position = "";
2399
  $positions = $category->getProductsPosition();
2400
+ if (count($positions) > 0) {
2401
+ $position = $positions[$product->getId()];
2402
+ }
2403
+ $productName = $this->_cleanStr($product->getName());
2404
+ $categorySorting = $category->getDefaultSortBy();
2405
+ $productSortValue = $this->CatalogProjectSortValue($product, $productName, $categorySorting);
2406
+ $ProducttoString .= $product->getId() . '#$#' . $productName //ProductKey
2407
+ . "\t" . $product->getId() . '#$#' . $productName //Product Name
2408
+ . "\t" . $position //Prod Sequence
2409
+ . "\tGeneral" //Proj Name
2410
+ . "\t" . $hpath //Hirarachi Path
2411
+ . "\t" . $categorySorting //Proj Flag
2412
+ . "\t" . $productSortValue//Proj Prod layout
2413
+ . "\n";
2414
+ if ($this->_DEBUG) {
2415
+ $this->controller->getResponse()->appendBody("Product #" . $product->getId() . ": position=" . $position . " price=" . $product->getData('price') . "
2416
+ ");
2417
+ }
2418
  $listed = TRUE;
2419
  }
2420
  }
2421
+ if (!$listed) {
2422
+ $productName = $this->_cleanStr($product->getName());
2423
+ $productSortValue = $this->CatalogProjectSortValue($product, $productName, $this->storeSorting);
2424
+ $ProducttoString .= $product->getId() . '#$#' . $productName //ProductKey
2425
+ . "\t" . $product->getId() . '#$#' . $productName //Product Name
2426
+ . "\t" . $this->unCatPosition //Prod Sequence
2427
+ . "\tGeneral" //Proj Name
2428
+ . "\tUncategorized" //Hirarachi Path
2429
+ . "\t" . $this->storeSorting //Proj Flag
2430
+ . "\t" . $productSortValue//Proj Prod layout
2431
+ . "\n";
2432
  $this->unCatPosition++;
2433
  }
2434
  return $ProducttoString;
2435
  }
2436
 
2437
+ private function CatalogProjectStringGroupedAsSimple(&$product) {
2438
+ $AssociatedProductIds = $this->productTypeGroupedModel->getAssociatedProductIds($product);
2439
+ $AssociatedProducts = array();
2440
+ foreach ($AssociatedProductIds as $UsedProductid) {
2441
+ $UsedProduct = Mage::getModel('catalog/product')->setStoreId($this->StoreId)->load($UsedProductid);
2442
+ if ($UsedProduct->getStatus() == 1) {
2443
+ $AssociatedProducts[] = $UsedProduct;
2444
+ } else {
2445
+ if ($this->_DEBUG) {
2446
+ $this->controller->getResponse()->appendBody("sku=" . $UsedProduct->getSku() . " enabled=" . $UsedProduct->getStatus() . " - bypassed.
2447
+ ");
 
 
 
 
2448
  }
2449
+ unset($UsedProduct);
2450
  }
2451
+ }
2452
+ $ProducttoString = "";
2453
+ if (count($AssociatedProducts) == 0) {
2454
+ return $ProducttoString;
2455
+ }
2456
+ $listed = FALSE;
2457
+ $categoryIds = $product->getCategoryIds();
2458
+ if ($categoryIds) {
2459
+ foreach ($categoryIds as $k => $category_id) {
2460
+ if (!isset($this->catmap[$category_id])) {
2461
+ if ($this->_DEBUG) {
2462
+ $this->controller->getResponse()->appendBody("No category: " . $category_id . "
2463
+ ");
2464
+ }
2465
  continue;
2466
  }
2467
+ $category = $this->catmap[$category_id];
2468
+ $hpath = $this->catpathmap[$category_id];
2469
  $position = "";
2470
  $positions = $category->getProductsPosition();
2471
+ if (count($positions) > 0) {
2472
+ $position = $positions[$product->getId()];
2473
+ }
2474
+ $categorySorting = $category->getDefaultSortBy();
2475
+ foreach ($AssociatedProducts as $UsedProduct) {
2476
+ $productName = $this->_cleanStr($UsedProduct->getName());
2477
+ $productSortValue = $this->CatalogProjectSortValue($UsedProduct, $productName, $categorySorting);
2478
+ $ProducttoString .= $UsedProduct->getId() . '#$#' . $productName //ProductKey
2479
+ . "\t" . $UsedProduct->getId() . '#$#' . $productName //Product Name
2480
+ . "\t" . $position //Prod Sequence
2481
+ . "\tGeneral" //Proj Name
2482
+ . "\t" . $hpath //Hirarachi Path
2483
+ . "\t" . $categorySorting //Proj Flag
2484
+ . "\t" . $productSortValue//Proj Prod layout
2485
+ . "\n";
2486
  $position += 0.001;
2487
  }
2488
  $listed = TRUE;
2489
  }
2490
  }
2491
+ if (!$listed) {
2492
+ foreach ($AssociatedProducts as $UsedProduct) {
2493
+ $productName = $this->_cleanStr($UsedProduct->getName());
2494
+ $productSortValue = $this->CatalogProjectSortValue($UsedProduct, $productName, $this->storeSorting);
2495
+ $ProducttoString .= $UsedProduct->getId() . '#$#' . $productName //ProductKey
2496
+ . "\t" . $UsedProduct->getId() . '#$#' . $productName //Product Name
2497
+ . "\t" . $this->unCatPosition //Prod Sequence
2498
+ . "\tGeneral" //Proj Name
2499
+ . "\tUncategorized" //Hirarachi Path
2500
+ . "\t" . $this->storeSorting //Proj Flag
2501
+ . "\t" . $productSortValue //Proj Prod layout
2502
+ . "\n";
2503
  $this->unCatPosition++;
2504
  }
2505
  }
2506
+ foreach ($AssociatedProducts as $UsedProduct) {
2507
+ unset($UsedProduct);
2508
+ }
2509
  return $ProducttoString;
2510
  }
2511
 
2512
+ private function CatalogProjectStringConfigurable(&$product) {
2513
  $UsedProductIds = $this->productTypeConfigurableModel->getUsedProductIds($product);
2514
+ $countUsedProductIds = count($UsedProductIds);
2515
+ if ($countUsedProductIds > 0) {
2516
  $listed = FALSE;
2517
  $ProducttoString = "";
2518
  $categoryIds = $product->getCategoryIds();
2519
+ if ($categoryIds) {
2520
+ foreach ($categoryIds as $k => $category_id) {
2521
+ if (!isset($this->catmap[$category_id])) {
2522
+ if ($this->_DEBUG) {
2523
+ $this->controller->getResponse()->appendBody("No category: " . $category_id . "
2524
+ ");
2525
+ }
2526
  continue;
2527
  }
2528
+ $category = $this->catmap[$category_id];
2529
+ $hpath = $this->catpathmap[$category_id];
2530
  $position = "";
2531
  $positions = $category->getProductsPosition();
2532
+ if (count($positions) > 0) {
2533
+ $position = $positions[$product->getId()];
2534
+ }
2535
+ $productName = $this->_cleanStr($product->getName());
2536
+ $categorySorting = $category->getDefaultSortBy();
2537
+ $productSortValue = $this->CatalogProjectSortValue($product, $productName, $categorySorting);
2538
+ $ProducttoString .= $product->getId() . '#$#' . $productName //ProductKey
2539
+ . "\t" . $product->getId() . '#$#' . $productName //Product Name
2540
+ . "\t" . $position //Prod Sequence
2541
+ . "\tGeneral" //Proj Name
2542
+ . "\t" . $hpath //Hirarachi Path
2543
+ . "\t" . $categorySorting //Proj Flag
2544
+ . "\t" . $productSortValue//Proj Prod layout
2545
+ . "\n";
2546
+ $listed = TRUE;
2547
+ }
2548
+ }
2549
+ if (!$listed) {
2550
+ $productName = $this->_cleanStr($product->getName());
2551
+ $productSortValue = $this->CatalogProjectSortValue($product, $productName, $this->storeSorting);
2552
+ $ProducttoString .= $product->getId() . '#$#' . $productName //ProductKey
2553
+ . "\t" . $product->getId() . '#$#' . $productName //Product Name
2554
+ . "\t" . $this->unCatPosition //Prod Sequence
2555
  . "\tGeneral" //Proj Name
2556
+ . "\tUncategorized" //Hirarachi Path
2557
+ . "\t" . $this->storeSorting //Proj Flag
2558
+ . "\t" . $productSortValue//Proj Prod layout
2559
  . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
2560
  $this->unCatPosition++;
2561
+ }
2562
+ } else {
2563
  $ProducttoString = "";
2564
+ }
2565
+ unset($UsedProductIds);
2566
  return $ProducttoString;
2567
  }
2568
+
2569
+ private function CatalogProjectSortValue(&$product, &$productName, &$categorySorting) {
2570
+ $productSortValue = false;
2571
+ if ("position" == $categorySorting) {
2572
+ $productSortValue = strtolower(trim($productName));
2573
+ } else if ("name" == $categorySorting) {
2574
+ $productSortValue = strtolower(trim($productName));
2575
+ } else if ("price" == $categorySorting) {
2576
+ $ProdRPrice = $product->getData('price');
2577
+ if (!$ProdRPrice && $product->getTypeId() == "bundle") {
2578
+ $priceModel = $product->getPriceModel();
2579
+ $options = Mage::getSingleton('core/layout')->createBlock('bundle/catalog_product_view_type_bundle')->setProduct($product)->getOptions();
2580
+ $ProdRPrice = 0;
2581
+ foreach ($options as $option) {
2582
+ $selection = $option->getDefaultSelection();
2583
+ $MinSelPrice = 0;
2584
+ if ($selection) {
2585
+ $MinSelPrice = $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
2586
+ } else if (!$selection && $option->_origData["required"] == "1") {
2587
+ foreach ($option->getSelections() as $selection) {
2588
+ $SelPrice = $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
2589
+ if (( $MinSelPrice == 0 && $SelPrice > 0 ) || ( $MinSelPrice > 0 && $SelPrice > 0 && $SelPrice < $MinSelPrice )) {
2590
+ $MinSelPrice = $SelPrice;
2591
+ }
2592
+ }
2593
+ }
2594
+ if ($MinSelPrice <= 0) {
2595
+ continue;
2596
+ }
2597
+ if ($this->_DEBUG) {
2598
+ $this->controller->getResponse()->appendBody("added " . $MinSelPrice . "
2599
+ ");
2600
+ }
2601
+ $ProdRPrice += $MinSelPrice;
2602
+ }
2603
+ if ($this->_DEBUG) {
2604
+ $this->controller->getResponse()->appendBody("Bundle=" . $ProdRPrice . "
2605
+ ");
2606
+ }
2607
+ }
2608
+ if (!$ProdRPrice) {
2609
+ $ProdRPrice = "0.0";
2610
+ }
2611
+ $productSortValue = $ProdRPrice;
2612
+ }
2613
+ return $productSortValue;
2614
+ }
2615
+
2616
+ }
2617
+
2618
+ // Mage_CodiScript_Model_Files
app/code/community/Mage/CodiScript/controllers/IndexController.php CHANGED
@@ -1,365 +1,439 @@
1
  <?php
2
- define("__VERSION__","2015-07-09");
3
- define("__SCRIPTNAME__",basename(__FILE__));
4
 
5
- class Mage_CodiScript_IndexController extends Mage_Core_Controller_Front_Action{
6
- public function indexAction(){
7
- //==============================================================================
8
- $_DEBUG = isset($_REQUEST["_DEBUG"]) ? $_REQUEST["_DEBUG"] : "0";
9
- $_INFO = isset($_REQUEST["_INFO"]) ? $_REQUEST["_INFO"] : "0";
10
- $StoreCode = isset($_REQUEST["Store"]) ? $_REQUEST["Store"] : FALSE;
11
- $Class = isset($_REQUEST["Class"]) ? $_REQUEST["Class"] : "";
12
- $Password = isset($_REQUEST["Password"]) ? $_REQUEST["Password"] : "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  // Headers
14
- $gmdate_mod = gmdate('D, d M Y H:i:s', time()).' GMT';
15
- header('Last-Modified: '.$gmdate_mod);
16
- header('Content-Type: text/plain; charset=UTF-8');
17
- header('Content-Disposition: inline; filename="'.$Class.'.txt"');
18
- header('X-CoDSoftware-Version: '.__VERSION__);
19
  // Enable errors display / list versions
20
- ini_set('display_errors', '1');
21
- ini_set('error_reporting', E_ALL);
22
- ini_set('html_errors', '0');
23
- ini_set('xmlrpc_errors', '0');
24
- ini_set('error_prepend_string', "");
25
- ini_set('error_append_string', "");
26
- function myErrorHandler($errno,$errstr,$errfile,$errline){
27
- echo "WARNING: ".$errstr." (line ".$errline.")
28
- ";
29
- return true;
30
- }
 
 
31
  // Set an error handler for warnings and notices.
32
- set_error_handler('myErrorHandler');
33
- if( $_DEBUG || $_INFO ){
34
- $started_time = time();
35
- echo "PHP version: ".phpversion()."
36
- Magento version: ".Mage::getVersion()."
37
- Script version: ".__VERSION__."
38
  --------------------------------------------------------------------------------
39
- ";
40
- }
41
- if( $_DEBUG ) echo "Class=".$Class."
42
- Password=".$Password."
43
- ";
44
- $codiScriptPassword = Mage::helper('codiscript')->getCodiPassword();
 
45
  // Check if a password is defined
46
- if( $codiScriptPassword == '' )
47
- die('ERROR: A blank password is not allowed. Edit the password at System > Configuration > Catalog-on-Demand Configuration.');
 
 
48
  // Check the password
49
- if( $Password != $codiScriptPassword )
50
- die('ERROR: The specified password is invalid.');
51
- if( $Class=="DataFile" ){
52
- $enablereviews = ( isset($_REQUEST["enablereviews"]) && $_REQUEST["enablereviews"] == "1" );
53
- $ignoretopcategory = ( isset($_REQUEST["ignoretopcategory"]) && $_REQUEST["ignoretopcategory"] == "1" );
54
- $includeshortdescription = ( isset($_REQUEST["includeshortdescription"]) && $_REQUEST["includeshortdescription"] == "1" );
55
- $includelongdescription = ( isset($_REQUEST["includelongdescription"]) ? $_REQUEST["includelongdescription"] == "1" : TRUE );
56
- $getpricefromchild = ( isset($_REQUEST["getpricefromchild"]) ? $_REQUEST["getpricefromchild"] == "1" : TRUE );
57
- $getgroupprices = ( isset($_REQUEST["getgroupprices"]) && $_REQUEST["getgroupprices"] == "1" );
58
- $publishtieredpricing = ( isset($_REQUEST["publishtieredpricing"]) && $_REQUEST["publishtieredpricing"] == "1" );
59
- $quantitylabel = isset($_REQUEST["quantitylabel"]) ? $_REQUEST["quantitylabel"] : "Quantity";
60
- $pricelabel = isset($_REQUEST["pricelabel"]) ? $_REQUEST["pricelabel"] : "Price";
61
- $savingslabel = isset($_REQUEST["savingslabel"]) ? $_REQUEST["savingslabel"] : "Savings";
62
- $includetaxes = ( isset($_REQUEST["includetaxes"]) && $_REQUEST["includetaxes"] == "1" );
63
- $includeinvqty = ( isset($_REQUEST["includeinvqty"]) && $_REQUEST["includeinvqty"] == "1" );
64
- $includespecialprice = ( isset($_REQUEST["includespecialprice"]) && $_REQUEST["includespecialprice"] == "1" );
65
- $includespecialpricedatefrom = ( isset($_REQUEST["includespecialpricedatefrom"]) && $_REQUEST["includespecialpricedatefrom"] == "1" );
66
- $includespecialpricedateto = ( isset($_REQUEST["includespecialpricedateto"]) && $_REQUEST["includespecialpricedateto"] == "1" );
67
- $ignoreexcludedimages = ( isset($_REQUEST["ignoreexcludedimages"]) && $_REQUEST["ignoreexcludedimages"] == "1" );
68
- $ignoreassprodimages = ( isset($_REQUEST["ignoreassprodimages"]) && $_REQUEST["ignoreassprodimages"] == "1" );
69
- $includecustomfields = isset($_REQUEST["includecustomfields"])? trim( $_REQUEST["includecustomfields"] ) : FALSE;
70
- if( empty ( $includecustomfields ) )
71
- $includecustomfields = FALSE;
72
- else{
73
- $arr = explode( ",", $includecustomfields );
74
- $includecustomfields = array();
75
- foreach( $arr as $part ){
76
- $part = trim( $part );
77
- if( !empty( $part ) )
78
- $includecustomfields[ strtolower( $part ) ] = TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  }
80
- }
81
- $importoptionsasattributes = ( isset( $_REQUEST["importoptionsasattributes"] ) && $_REQUEST["importoptionsasattributes"] == "1" );
82
- $importoptionsassku = ( isset($_REQUEST["importoptionsassku"]) && $_REQUEST["importoptionsassku"] == "1" );
83
- $instockonly = isset($_REQUEST["instockonly"])? trim( $_REQUEST["instockonly"] ) : FALSE;
84
- $splitgroupedproducts = isset($_REQUEST["splitgroupedproducts"])? trim( $_REQUEST["splitgroupedproducts"] ) : FALSE;
85
- $start = isset( $_REQUEST["start"] ) ? intval( $_REQUEST["start"] ) : 0;
86
- $pageSize = isset( $_REQUEST["pageSize"] ) ? intval( $_REQUEST["pageSize"] ) : 1000000000;
87
- if( $_DEBUG ) echo "enablereviews=".$enablereviews."
88
- ignoretopcategory=".$ignoretopcategory."
89
- includeshortdescription=".$includeshortdescription."
90
- includelongdescription=".$includelongdescription."
91
- getpricefromchild=".$getpricefromchild."
92
- getgroupprices=".$getgroupprices."
93
- publishtieredpricing=".$publishtieredpricing."
94
- quantitylabel=".$quantitylabel."
95
- pricelabel=".$pricelabel."
96
- savingslabel=".$savingslabel."
97
- includetaxes=".$includetaxes."
98
- includeinvqty=".$includeinvqty."
99
- includespecialprice=".$includespecialprice."
100
- includespecialpricedatefrom=".$includespecialpricedatefrom."
101
- includespecialpricedateto=".$includespecialpricedateto."
102
- ignoreexcludedimages=".$ignoreexcludedimages."
103
- ignoreassprodimages=".$ignoreassprodimages."
104
- includecustomfields=".( $includecustomfields ? implode( ",", array_keys( $includecustomfields ) ) : $includecustomfields )."
105
- importoptionsasattributes=".$importoptionsasattributes."
106
- importoptionsassku=".$importoptionsassku."
107
- instockonly=".$instockonly."
108
- splitgroupedproducts=".$splitgroupedproducts."
109
- start=".$start."
110
- pageSize=".$pageSize."
111
- ";
112
- } else if( $Class=="CatalogSection" ){
113
- $ignoretopcategory = ( isset($_REQUEST["ignoretopcategory"]) && $_REQUEST["ignoretopcategory"] == "1" );
114
- if($_DEBUG) echo "ignoretopcategory=".$ignoretopcategory."
115
- ";
116
- } else if( $Class=="CatalogProject" ){
117
- $ignoretopcategory = ( isset($_REQUEST["ignoretopcategory"]) && $_REQUEST["ignoretopcategory"] == "1" );
118
- $instockonly = isset($_REQUEST["instockonly"])? trim( $_REQUEST["instockonly"] ) : FALSE;
119
- $splitgroupedproducts = isset($_REQUEST["splitgroupedproducts"])? trim( $_REQUEST["splitgroupedproducts"] ) : FALSE;
120
- $start = isset($_REQUEST["start"]) ? intval( $_REQUEST["start"] ) : 0;
121
- $pageSize = isset($_REQUEST["pageSize"]) ? intval( $_REQUEST["pageSize"] ) : 1000000000;
122
- if($_DEBUG) echo "ignoretopcategory=".$ignoretopcategory."
123
- instockonly=".$instockonly."
124
- start=".$start."
125
- pageSize=".$pageSize."
126
- ";
127
- }
128
  // Increase memory limit to 1024M
129
- ini_set('memory_limit','1024M');
130
  // Increase maximum execution time to 6 hours
131
- ini_set('max_execution_time',28800);
132
  // Make sure GC is enabled
133
- if( function_exists( "gc_enable" ) )
134
- gc_enable();
135
- else if($_DEBUG || $_INFO)
136
- echo "gc_enable does not exist.
137
- ";
138
- if($_INFO){
139
- foreach ( Mage::app()->getStores() as $store )
140
- echo "store: ".$store->getId()." code=".$store->getCode()." name=".$store->getName()." isActive=".$store->getIsActive()."
141
- ";
142
- if( function_exists( "gc_enabled" ) ) echo "gc_enabled=".gc_enabled()."
143
- ";
144
- else echo "gc_enabled does not exist.
145
- ";
146
- echo "--------------------------------------------------------------------------------
147
- ";
148
- die();
149
- }
 
 
 
 
 
150
  // Determine / check store
151
- $StoreId = 0;
152
- $Store = FALSE;
153
- $Stores = Mage::app()->getStores( false, true );
154
- if( !empty( $StoreCode ) && !$Stores[ $StoreCode ] )
155
- die( "ERROR: Store \"".$StoreCode."\" not found.");
156
- else if( !empty( $StoreCode ) && !$Stores[ $StoreCode ]->getIsActive() )
157
- die( "ERROR: Store \"".$StoreCode."\" is inactive (disabled).");
158
- else if( !empty( $StoreCode ) ){
159
- $Store = $Stores[ $StoreCode ];
160
- $StoreId = $Store->getId();
161
- }else{
162
- $count = 0;
163
- foreach ( $Stores as $_Store )
164
- if( $_Store->getIsActive() ){
165
- $count++;
166
- $Store = $_Store;
167
  $StoreId = $Store->getId();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
- if( $count > 1 )
170
- die( "ERROR: Store specification is required (there are more than 1 active / enabled stores).");
171
- if( $count < 1 )
172
- die( "ERROR: No active stores.");
173
- }
174
- $cfModel = Mage::getModel('codiscript/files');
175
- if( $Class=="DataFile" ){
176
- $cfModel->enablereviews = $enablereviews;
177
- $cfModel->ignoretopcategory = $ignoretopcategory;
178
- $cfModel->includeshortdescription = $includeshortdescription;
179
- $cfModel->includelongdescription = $includelongdescription;
180
- $cfModel->getpricefromchild = $getpricefromchild;
181
- $cfModel->getgroupprices = $getgroupprices;
182
- $cfModel->publishtieredpricing = $publishtieredpricing;
183
- $cfModel->quantitylabel = $quantitylabel;
184
- $cfModel->pricelabel = $pricelabel;
185
- $cfModel->savingslabel = $savingslabel;
186
- $cfModel->includetaxes = $includetaxes;
187
- $cfModel->includeinvqty = $includeinvqty;
188
- $cfModel->includespecialprice = $includespecialprice;
189
- $cfModel->includespecialpricedatefrom = $includespecialpricedatefrom;
190
- $cfModel->includespecialpricedateto = $includespecialpricedateto;
191
- $cfModel->ignoreexcludedimages = $ignoreexcludedimages;
192
- $cfModel->ignoreassprodimages = $ignoreassprodimages;
193
- $cfModel->includecustomfields = $includecustomfields;
194
- $cfModel->importoptionsasattributes = $importoptionsasattributes;
195
- $cfModel->importoptionsassku = $importoptionsassku;
196
- $cfModel->instockonly = $instockonly;
197
- $cfModel->splitgroupedproducts = $splitgroupedproducts;
198
- $cfModel->start = $start;
199
- $cfModel->pageSize = $pageSize;
200
- if($cfModel->includetaxes)
201
- $cfModel->taxhelper=Mage::helper('tax');
202
- } else if( $Class=="CatalogSection" ){
203
- $cfModel->ignoretopcategory = $ignoretopcategory;
204
- } else if( $Class=="CatalogProject" ){
205
- $cfModel->ignoretopcategory = $ignoretopcategory;
206
- $cfModel->instockonly = $instockonly;
207
- $cfModel->splitgroupedproducts = $splitgroupedproducts;
208
- $cfModel->start = $start;
209
- $cfModel->pageSize = $pageSize;
210
- }
211
- $cfModel->_DEBUG = $_DEBUG;
212
- $cfModel->StoreId = $StoreId;
213
- $cfModel->Store = $Store;
214
- if( $Class=="DataFile" ) $cfModel->renderDataFile();
215
- else if( $Class=="CatalogSection" ) $cfModel->renderCatalogSection();
216
- else if( $Class=="CatalogProject" ) $cfModel->renderCatalogProject();
217
- else if( $_DEBUG ){
218
- foreach ( Mage::app()->getStores() as $store ){
219
- echo "store: ".$store->getId()." code=".$store->getCode()." name=".$store->getName()." isActive=".$store->getIsActive()."
220
- website=".$store->getWebsite()."
221
- base currency=".$store->getBaseCurrency()."
222
- ";
223
- }
224
- echo "max_execution_time=".ini_get("max_execution_time")."
225
- memory_limit=".ini_get("memory_limit")."
226
- ";
227
- if( function_exists( "gc_enabled" ) ) echo "gc_enabled=".gc_enabled()."
228
- ";
229
- else echo "gc_enabled does not exist.
230
- ";
231
- echo "--------------------------------------------------------------------------------
232
- ";
233
- phpinfo(INFO_GENERAL);
234
- phpinfo(INFO_CONFIGURATION);
235
- echo "--------------------------------------------------------------------------------";
236
- } else {
237
- echo "==EOF==";
238
- }
239
- if( $_DEBUG ) echo "
240
- executed in ".( time() - $started_time )." sec.
241
- ";
242
- die();
243
- /* RELEASE NOTES
244
- * 2015-07-09
245
- * Improved rendering of image URLs
246
- *
247
- * 2015-05-11
248
- * Improved rendering of prices with store-dependent taxes
249
- *
250
- * 2015-05-08
251
- * Added rendering of products associated with grouped prodict as separate products
252
- *
253
- * 2015-04-27
254
- * Added rendering of group tier prices in case of "Get group prices" and "Publish tiered pricing" both checked
255
- *
256
- * 2015-04-23
257
- * Minor fixes
258
- *
259
- * 2015-04-14
260
- * Added import of custom simple product options into items, if the option contains a SKU number
261
- *
262
- * 2015-03-30
263
- * Added retrieval of custom product options in case of importoptionsasattributes=true
264
- *
265
- * 2015-03-02
266
- * Filtering out disabled products improved for associated products of configurable products
267
- *
268
- * 2015-02-17
269
- * Fixed call-time pass-by-reference bug
270
- *
271
- * 2015-01-29
272
- * Restored / reimplemented getpricefromchild
273
- * - now forces getting individual associated product prices as item prices
274
- *
275
- * 2015-01-08
276
- * 1. Optimized configurable product items ordering
277
- *
278
- * 2014-12-16
279
- * 1. Fixed configurable attributes processing bug
280
- *
281
- * 2014-11-10
282
- * 1. Added instockonly option and implemented import of only items that are in stock
283
- *
284
- * 2014-10-17
285
- * 1. Improved configurable product item attribute export
286
- *
287
- * 2014-10-12
288
- * 1. Improved price formatting (added proper "rounding half up")
289
- *
290
- * 2014-08-22
291
- * 1. publishtieredpricing causes retrieval of tier prices for individual products within a group product
292
- *
293
- * 2014-08-06
294
- * 1. Added importoptionsasattributes option / processing
295
- *
296
- * 2014-04-01
297
- * 1. Group prices retrieval implemented (Magento 1.7+)
298
- * 2. Obsoleted getpricefromchild option
299
- *
300
- * 2014-02-24
301
- * 1. includecustomfields parameter added / implemented
302
- * 2. Improved langiage-specific section rendering
303
- *
304
- * 2014-02-04
305
- * 1. "MagentoBase" role introduced for base product images.
306
- * 2. Improved product attributes import: excluded attributes of "select" / "muitiselect" type having no selection
307
- *
308
- * * 2014-01-18
309
- * 1. Configurable products - pricing updates / fixes
310
- * 2. Configurable products - items ordering updates
311
- * 3. Bundled products -pricing updates
312
- *
313
- * 2014-01-16
314
- * 1. Fixed sequencing issue for grouped products
315
- *
316
- * 2013-10-30
317
- * 1. Added includespecialprice / includespecialpricedatefrom / includespecialpricedateto request parameter / processing
318
- * (population of item attributes with special price / dates)
319
- * 2. Added incremental CatalogSection / CatalogProject file retrieval
320
- *
321
- * 2013-10-15
322
- * 1. Added includeinvqty request parameter / processing
323
- *
324
- * 2013-07-19
325
- * 1. Added incremental data file retrieval
326
- *
327
- * 2013-06-05
328
- * 1. "Ignore associated product images" feature expanded to configurable products
329
- *
330
- * 2013-05-31
331
- * 1. Added "Ignore associated product images" feature
332
- *
333
- * 2013-02-04
334
- * 1. Added includelongdescription request parameter / processing
335
- *
336
- * 2012-12-07
337
- * 1. Improved error / warning / notice reporting
338
- * 2. Fixed configurable attributes import error
339
- *
340
- * 2012-12-04
341
- * 1. Updated tier prices import
342
- *
343
- * 2012-11-05
344
- * 1. Updated multiple images import
345
- * 2. Added "Ignore excluded images" option support
346
- *
347
- * 2012-11-01
348
- * 1. Updated debugging outout
349
- *
350
- * 2012-10-30
351
- * 1. Added "Include taxes" option support
352
- * 2. Updated images import: all product images are imported, not only the base one
353
- *
354
- * 2012-10-22
355
- * 1. Added "Ignore top category" option support
356
- *
357
- * 2012-07-26
358
- * 1. Added store spefification
359
- * 2. Minor performance improvements
360
- *
361
- * 2012-07-25
362
- * Minor performance improvements
363
- *///==============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  }
 
365
  }
1
  <?php
 
 
2
 
3
+ define("__VERSION__", "2016-10-03");
4
+ define("__SCRIPTNAME__", basename(__FILE__));
5
+
6
+ class Mage_CodiScript_IndexController extends Mage_Core_Controller_Front_Action {
7
+
8
+ public function indexAction() {
9
+ //================== common code start ==================
10
+ //class Mage_CodiScript_Model_Files extends Mage_Core_Model_Abstract {
11
+ // public function renderDataFile(){
12
+ // private function ProducttoStringGrouped( &$product ){
13
+ // private function ProducttoStringConfigurable( &$product ){
14
+ // private function ProducttoStringSimple( &$product ){
15
+ // private function _fillConfigProdItems
16
+ // private function _cleanStr( &$str ){
17
+ // private function _correctProdUrlStr( &$str ){
18
+ // private function _getReviews( $productid ){
19
+ // private function _formatPrice( $Price ){
20
+ // private function _formatQty( $qty ){
21
+ // private function _formatImageURL( $str ){
22
+ // private function _getTierPrices( &$product ){
23
+ // public function renderCatalogSection(){
24
+ // private function _drawCategory( &$category, $level=0, $hpath='', $i=1, $j=1, $path='' ){
25
+ // public function renderCatalogProject(){
26
+ // private function _processCategory( &$category, $level=0, $hpath='', $path='' ){
27
+ // private function CatalogProjectStringGroupedOrSimple(&$product) {
28
+ // private function CatalogProjectStringSimple( &$product ){
29
+ // private function CatalogProjectStringConfigurable( &$product ){
30
+ // private function CatalogProjectSortValue(&$product, &$productName, &$categorySorting) {$_DEBUG = $this->getRequest()->getParam("_DEBUG"]) ? $this->getRequest()->getParam("_DEBUG"] : "0";
31
+ $_DEBUG = $this->getRequest()->getParam("_DEBUG") ? $this->getRequest()->getParam("_DEBUG") : "0";
32
+ $_INFO = $this->getRequest()->getParam("_INFO") ? $this->getRequest()->getParam("_INFO") : "0";
33
+ $StoreCode = $this->getRequest()->getParam("Store") ? $this->getRequest()->getParam("Store") : FALSE;
34
+ $Class = $this->getRequest()->getParam("Class") ? $this->getRequest()->getParam("Class") : "";
35
+ $Password = $this->getRequest()->getParam("Password") ? $this->getRequest()->getParam("Password") : "";
36
  // Headers
37
+ $gmdate_mod = gmdate('D, d M Y H:i:s', time()) . ' GMT';
38
+ $this->getResponse()->setHeader('Last-Modified: ' . $gmdate_mod);
39
+ $this->getResponse()->setHeader('Content-Type: text/plain; charset=UTF-8');
40
+ $this->getResponse()->setHeader('Content-Disposition: inline; filename="' . $Class . '.txt"');
41
+ $this->getResponse()->setHeader('X-CoDSoftware-Version: ' . __VERSION__);
42
  // Enable errors display / list versions
43
+ ini_set('display_errors', '1');
44
+ ini_set('error_reporting', E_ALL);
45
+ ini_set('html_errors', '0');
46
+ ini_set('xmlrpc_errors', '0');
47
+ ini_set('error_prepend_string', "");
48
+ ini_set('error_append_string', "");
49
+
50
+ function myErrorHandler($errno, $errstr, $errfile, $errline) {
51
+ // $this->getResponse()->appendBody("WARNING: " . $errstr . " (line " . $errline . ")
52
+ //");
53
+ return true;
54
+ }
55
+
56
  // Set an error handler for warnings and notices.
57
+ set_error_handler('myErrorHandler');
58
+ if ($_DEBUG || $_INFO) {
59
+ $started_time = time();
60
+ $this->getResponse()->appendBody("PHP version: " . phpversion() . "
61
+ Magento version: " . Mage::getVersion() . "
62
+ Script version: " . __VERSION__ . "
63
  --------------------------------------------------------------------------------
64
+ ");
65
+ }
66
+ if ($_DEBUG)
67
+ $this->getResponse()->appendBody("Class=" . $Class . "
68
+ Password=" . $Password . "
69
+ ");
70
+ $codiScriptPassword = Mage::helper('codiscript')->getCodiPassword();
71
  // Check if a password is defined
72
+ if ($codiScriptPassword == '') {
73
+ $this->getResponse()->appendBody('ERROR: A blank password is not allowed. Edit the password at System > Configuration > Catalog-on-Demand Configuration.');
74
+ return;
75
+ }
76
  // Check the password
77
+ if ($Password != $codiScriptPassword) {
78
+ $this->getResponse()->appendBody('ERROR: The specified password is invalid.');
79
+ return;
80
+ }
81
+ if ($Class == "Configuration") {
82
+ // nothing special
83
+ } else if ($Class == "DataFile") {
84
+ $enablereviews = ( $this->getRequest()->getParam("enablereviews") && $this->getRequest()->getParam("enablereviews") == "1" );
85
+ $ignoretopcategory = ( $this->getRequest()->getParam("ignoretopcategory") && $this->getRequest()->getParam("ignoretopcategory") == "1" );
86
+ $includeshortdescription = ( $this->getRequest()->getParam("includeshortdescription") && $this->getRequest()->getParam("includeshortdescription") == "1" );
87
+ $includelongdescription = ( $this->getRequest()->getParam("includelongdescription") ? $this->getRequest()->getParam("includelongdescription") == "1" : TRUE );
88
+ $getpricefromchild = ( $this->getRequest()->getParam("getpricefromchild") ? $this->getRequest()->getParam("getpricefromchild") == "1" : TRUE );
89
+ $getgroupprices = ( $this->getRequest()->getParam("getgroupprices") && $this->getRequest()->getParam("getgroupprices") == "1" );
90
+ $publishtieredpricing = ( $this->getRequest()->getParam("publishtieredpricing") && $this->getRequest()->getParam("publishtieredpricing") == "1" );
91
+ $quantitylabel = $this->getRequest()->getParam("quantitylabel") ? $this->getRequest()->getParam("quantitylabel") : "Quantity";
92
+ $pricelabel = $this->getRequest()->getParam("pricelabel") ? $this->getRequest()->getParam("pricelabel") : "Price";
93
+ $savingslabel = $this->getRequest()->getParam("savingslabel") ? $this->getRequest()->getParam("savingslabel") : "Savings";
94
+ $includetaxes = ( $this->getRequest()->getParam("includetaxes") && $this->getRequest()->getParam("includetaxes") == "1" );
95
+ $includeinvqty = ( $this->getRequest()->getParam("includeinvqty") && $this->getRequest()->getParam("includeinvqty") == "1" );
96
+ $includespecialprice = ( $this->getRequest()->getParam("includespecialprice") && $this->getRequest()->getParam("includespecialprice") == "1" );
97
+ $includespecialpricedatefrom = ( $this->getRequest()->getParam("includespecialpricedatefrom") && $this->getRequest()->getParam("includespecialpricedatefrom") == "1" );
98
+ $includespecialpricedateto = ( $this->getRequest()->getParam("includespecialpricedateto") && $this->getRequest()->getParam("includespecialpricedateto") == "1" );
99
+ $ignoreexcludedimages = ( $this->getRequest()->getParam("ignoreexcludedimages") && $this->getRequest()->getParam("ignoreexcludedimages") == "1" );
100
+ $ignoreassprodimages = ( $this->getRequest()->getParam("ignoreassprodimages") && $this->getRequest()->getParam("ignoreassprodimages") == "1" );
101
+ $includecustomfields = $this->getRequest()->getParam("includecustomfields") ? trim($this->getRequest()->getParam("includecustomfields")) : FALSE;
102
+ if (empty($includecustomfields)) {
103
+ $includecustomfields = FALSE;
104
+ } else {
105
+ $arr = explode(",", $includecustomfields);
106
+ $includecustomfields = array();
107
+ foreach ($arr as $part) {
108
+ $part = trim($part);
109
+ if (!empty($part)) {
110
+ $includecustomfields[strtolower($part)] = TRUE;
111
+ }
112
+ }
113
+ }
114
+ $importoptionsasattributes = ( $this->getRequest()->getParam("importoptionsasattributes") && $this->getRequest()->getParam("importoptionsasattributes") == "1" );
115
+ $importoptionsassku = ( $this->getRequest()->getParam("importoptionsassku") && $this->getRequest()->getParam("importoptionsassku") == "1" );
116
+ $instockonly = ( $this->getRequest()->getParam("instockonly") && $this->getRequest()->getParam("instockonly") == "1" );
117
+ $splitgroupedproducts = ( $this->getRequest()->getParam("splitgroupedproducts") && $this->getRequest()->getParam("splitgroupedproducts") == "1");
118
+ $start = $this->getRequest()->getParam("start") ? intval($this->getRequest()->getParam("start")) : 0;
119
+ $pageSize = $this->getRequest()->getParam("pageSize") ? intval($this->getRequest()->getParam("pageSize")) : 1000000000;
120
+ if ($_DEBUG) {
121
+ $this->getResponse()->appendBody("enablereviews=" . $enablereviews . "
122
+ ignoretopcategory=" . $ignoretopcategory . "
123
+ includeshortdescription=" . $includeshortdescription . "
124
+ includelongdescription=" . $includelongdescription . "
125
+ getpricefromchild=" . $getpricefromchild . "
126
+ getgroupprices=" . $getgroupprices . "
127
+ publishtieredpricing=" . $publishtieredpricing . "
128
+ quantitylabel=" . $quantitylabel . "
129
+ pricelabel=" . $pricelabel . "
130
+ savingslabel=" . $savingslabel . "
131
+ includetaxes=" . $includetaxes . "
132
+ includeinvqty=" . $includeinvqty . "
133
+ includespecialprice=" . $includespecialprice . "
134
+ includespecialpricedatefrom=" . $includespecialpricedatefrom . "
135
+ includespecialpricedateto=" . $includespecialpricedateto . "
136
+ ignoreexcludedimages=" . $ignoreexcludedimages . "
137
+ ignoreassprodimages=" . $ignoreassprodimages . "
138
+ includecustomfields=" . ( $includecustomfields ? implode(",", array_keys($includecustomfields)) : $includecustomfields ) . "
139
+ importoptionsasattributes=" . $importoptionsasattributes . "
140
+ importoptionsassku=" . $importoptionsassku . "
141
+ instockonly=" . $instockonly . "
142
+ splitgroupedproducts=" . $splitgroupedproducts . "
143
+ start=" . $start . "
144
+ pageSize=" . $pageSize . "
145
+ ");
146
+ }
147
+ } else if ($Class == "CatalogSection") {
148
+ $ignoretopcategory = ( $this->getRequest()->getParam("ignoretopcategory") && $this->getRequest()->getParam("ignoretopcategory") == "1" );
149
+ if ($_DEBUG) {
150
+ $this->getResponse()->appendBody("ignoretopcategory=" . $ignoretopcategory . "
151
+ ");
152
+ }
153
+ } else if ($Class == "CatalogProject") {
154
+ $ignoretopcategory = ( $this->getRequest()->getParam("ignoretopcategory") && $this->getRequest()->getParam("ignoretopcategory") == "1" );
155
+ $instockonly = ( $this->getRequest()->getParam("instockonly") && $this->getRequest()->getParam("instockonly") == "1" );
156
+ $splitgroupedproducts = ( $this->getRequest()->getParam("splitgroupedproducts") && $this->getRequest()->getParam("splitgroupedproducts") == "1");
157
+ $start = $this->getRequest()->getParam("start") ? intval($this->getRequest()->getParam("start")) : 0;
158
+ $pageSize = $this->getRequest()->getParam("pageSize") ? intval($this->getRequest()->getParam("pageSize")) : 1000000000;
159
+ if ($_DEBUG) {
160
+ $this->getResponse()->appendBody("ignoretopcategory=" . $ignoretopcategory . "
161
+ instockonly=" . $instockonly . "
162
+ splitgroupedproducts=" . $splitgroupedproducts . "
163
+ start=" . $start . "
164
+ pageSize=" . $pageSize . "
165
+ ");
166
+ }
167
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  // Increase memory limit to 1024M
169
+ ini_set('memory_limit', '1024M');
170
  // Increase maximum execution time to 6 hours
171
+ ini_set('max_execution_time', 28800);
172
  // Make sure GC is enabled
173
+ if (function_exists("gc_enable")) {
174
+ gc_enable();
175
+ } else if ($_DEBUG || $_INFO) {
176
+ $this->getResponse()->appendBody("gc_enable does not exist.
177
+ ");
178
+ }
179
+ if ($_INFO) {
180
+ foreach (Mage::app()->getStores() as $store) {
181
+ $this->getResponse()->appendBody("store: " . $store->getId() . " code=" . $store->getCode() . " name=" . $store->getName() . " isActive=" . $store->getIsActive() . "
182
+ ");
183
+ }
184
+ if (function_exists("gc_enabled")) {
185
+ $this->getResponse()->appendBody("gc_enabled=" . gc_enabled() . "
186
+ ");
187
+ } else {
188
+ $this->getResponse()->appendBody("gc_enabled does not exist.
189
+ ");
190
+ }
191
+ $this->getResponse()->appendBody("=========================================================================================================
192
+ ");
193
+ return;
194
+ }
195
  // Determine / check store
196
+ $StoreId = 0;
197
+ $Store = FALSE;
198
+ $Stores = Mage::app()->getStores(false, true);
199
+ if (!empty($StoreCode) && !$Stores[$StoreCode]) {
200
+ $this->getResponse()->appendBody("ERROR: Store \"" . $StoreCode . "\" not found.");
201
+ return;
202
+ } else if (!empty($StoreCode) && !$Stores[$StoreCode]->getIsActive()) {
203
+ $this->getResponse()->appendBody("ERROR: Store \"" . $StoreCode . "\" is inactive (disabled).");
204
+ return;
205
+ } else if (!empty($StoreCode)) {
206
+ $Store = $Stores[$StoreCode];
 
 
 
 
 
207
  $StoreId = $Store->getId();
208
+ } else {
209
+ $count = 0;
210
+ foreach ($Stores as $_Store) {
211
+ if ($_Store->getIsActive()) {
212
+ $count++;
213
+ $Store = $_Store;
214
+ $StoreId = $Store->getId();
215
+ }
216
+ }
217
+ if ($count > 1) {
218
+ $this->getResponse()->appendBody("ERROR: Store specification is required (there are more than 1 active / enabled stores).");
219
+ return;
220
+ }
221
+ if ($count < 1) {
222
+ $this->getResponse()->appendBody("ERROR: No active stores.");
223
+ return;
224
+ }
225
  }
226
+
227
+ //================== common code end ==================
228
+ $cfModel = Mage::getModel('codiscript/files');
229
+ $cfModel->controller = $this;
230
+ //================== common code start ==================
231
+ if ($Class == "Configuration") {
232
+ // nothing special
233
+ } else if ($Class == "DataFile") {
234
+ $cfModel->enablereviews = $enablereviews;
235
+ $cfModel->ignoretopcategory = $ignoretopcategory;
236
+ $cfModel->includeshortdescription = $includeshortdescription;
237
+ $cfModel->includelongdescription = $includelongdescription;
238
+ $cfModel->getpricefromchild = $getpricefromchild;
239
+ $cfModel->getgroupprices = $getgroupprices;
240
+ $cfModel->publishtieredpricing = $publishtieredpricing;
241
+ $cfModel->quantitylabel = $quantitylabel;
242
+ $cfModel->pricelabel = $pricelabel;
243
+ $cfModel->savingslabel = $savingslabel;
244
+ $cfModel->includetaxes = $includetaxes;
245
+ $cfModel->includeinvqty = $includeinvqty;
246
+ $cfModel->includespecialprice = $includespecialprice;
247
+ $cfModel->includespecialpricedatefrom = $includespecialpricedatefrom;
248
+ $cfModel->includespecialpricedateto = $includespecialpricedateto;
249
+ $cfModel->ignoreexcludedimages = $ignoreexcludedimages;
250
+ $cfModel->ignoreassprodimages = $ignoreassprodimages;
251
+ $cfModel->includecustomfields = $includecustomfields;
252
+ $cfModel->importoptionsasattributes = $importoptionsasattributes;
253
+ $cfModel->importoptionsassku = $importoptionsassku;
254
+ $cfModel->instockonly = $instockonly;
255
+ $cfModel->splitgroupedproducts = $splitgroupedproducts;
256
+ $cfModel->start = $start;
257
+ $cfModel->pageSize = $pageSize;
258
+ if ($cfModel->includetaxes) {
259
+ $cfModel->taxhelper = Mage::helper('tax');
260
+ }
261
+ } else if ($Class == "CatalogSection") {
262
+ $cfModel->ignoretopcategory = $ignoretopcategory;
263
+ } else if ($Class == "CatalogProject") {
264
+ $cfModel->ignoretopcategory = $ignoretopcategory;
265
+ $cfModel->instockonly = $instockonly;
266
+ $cfModel->splitgroupedproducts = $splitgroupedproducts;
267
+ $cfModel->start = $start;
268
+ $cfModel->pageSize = $pageSize;
269
+ }
270
+ $cfModel->_DEBUG = $_DEBUG;
271
+ $cfModel->StoreId = $StoreId;
272
+ $cfModel->Store = $Store;
273
+ if ($Class == "Configuration") {
274
+ $cfModel->renderConfiguration();
275
+ } else if ($Class == "DataFile") {
276
+ $cfModel->renderDataFile();
277
+ } else if ($Class == "CatalogSection") {
278
+ $cfModel->renderCatalogSection();
279
+ } else if ($Class == "CatalogProject") {
280
+ $cfModel->renderCatalogProject();
281
+ } else if ($_DEBUG) {
282
+ foreach (Mage::app()->getStores() as $store) {
283
+ $this->getResponse()->appendBody("store: " . $store->getId() . " code=" . $store->getCode() . " name=" . $store->getName() . " isActive=" . $store->getIsActive() . "
284
+ website=" . $store->getWebsite() . "
285
+ base currency=" . $store->getBaseCurrency() . "
286
+ ");
287
+ }
288
+ $this->getResponse()->appendBody("max_execution_time=" . ini_get("max_execution_time") . "
289
+ memory_limit=" . ini_get("memory_limit") . "
290
+ ");
291
+ if (function_exists("gc_enabled")) {
292
+ $this->getResponse()->appendBody("gc_enabled=" . gc_enabled() . "
293
+ ");
294
+ } else {
295
+ $this->getResponse()->appendBody("gc_enabled does not exist.
296
+ ");
297
+ }
298
+ $this->getResponse()->appendBody("--------------------------------------------------------------------------------
299
+ ");
300
+ phpinfo(INFO_GENERAL);
301
+ phpinfo(INFO_CONFIGURATION);
302
+ $this->getResponse()->appendBody("--------------------------------------------------------------------------------
303
+ ");
304
+ } else {
305
+ $this->getResponse()->appendBody("==EOF==");
306
+ }
307
+ if ($_DEBUG) {
308
+ $this->getResponse()->appendBody("
309
+ executed in " . ( time() - $started_time ) . " sec.
310
+ ");
311
+ }
312
+ return;
313
+ /* RELEASE NOTES
314
+ * 2016-05-30
315
+ * Added product sort options
316
+ *
317
+ * 2015-07-09
318
+ * Improved rendering of image URLs
319
+ *
320
+ * 2015-05-11
321
+ * Improved rendering of prices with store-dependent taxes
322
+ *
323
+ * 2015-05-08
324
+ * Added rendering of products associated with grouped prodict as separate products
325
+ *
326
+ * 2015-04-27
327
+ * Added rendering of group tier prices in case of "Get group prices" and "Publish tiered pricing" both checked
328
+ *
329
+ * 2015-04-23
330
+ * Minor fixes
331
+ *
332
+ * 2015-04-14
333
+ * Added import of custom simple product options into items, if the option contains a SKU number
334
+ *
335
+ * 2015-03-30
336
+ * Added retrieval of custom product options in case of importoptionsasattributes=true
337
+ *
338
+ * 2015-03-02
339
+ * Filtering out disabled products improved for associated products of configurable products
340
+ *
341
+ * 2015-02-17
342
+ * Fixed call-time pass-by-reference bug
343
+ *
344
+ * 2015-01-29
345
+ * Restored / reimplemented getpricefromchild
346
+ * - now forces getting individual associated product prices as item prices
347
+ *
348
+ * 2015-01-08
349
+ * 1. Optimized configurable product items ordering
350
+ *
351
+ * 2014-12-16
352
+ * 1. Fixed configurable attributes processing bug
353
+ *
354
+ * 2014-11-10
355
+ * 1. Added instockonly option and implemented import of only items that are in stock
356
+ *
357
+ * 2014-10-17
358
+ * 1. Improved configurable product item attribute export
359
+ *
360
+ * 2014-10-12
361
+ * 1. Improved price formatting (added proper "rounding half up")
362
+ *
363
+ * 2014-08-22
364
+ * 1. publishtieredpricing causes retrieval of tier prices for individual products within a group product
365
+ *
366
+ * 2014-08-06
367
+ * 1. Added importoptionsasattributes option / processing
368
+ *
369
+ * 2014-04-01
370
+ * 1. Group prices retrieval implemented (Magento 1.7+)
371
+ * 2. Obsoleted getpricefromchild option
372
+ *
373
+ * 2014-02-24
374
+ * 1. includecustomfields parameter added / implemented
375
+ * 2. Improved langiage-specific section rendering
376
+ *
377
+ * 2014-02-04
378
+ * 1. "MagentoBase" role introduced for base product images.
379
+ * 2. Improved product attributes import: excluded attributes of "select" / "muitiselect" type having no selection
380
+ *
381
+ * * 2014-01-18
382
+ * 1. Configurable products - pricing updates / fixes
383
+ * 2. Configurable products - items ordering updates
384
+ * 3. Bundled products -pricing updates
385
+ *
386
+ * 2014-01-16
387
+ * 1. Fixed sequencing issue for grouped products
388
+ *
389
+ * 2013-10-30
390
+ * 1. Added includespecialprice / includespecialpricedatefrom / includespecialpricedateto request parameter / processing
391
+ * (population of item attributes with special price / dates)
392
+ * 2. Added incremental CatalogSection / CatalogProject file retrieval
393
+ *
394
+ * 2013-10-15
395
+ * 1. Added includeinvqty request parameter / processing
396
+ *
397
+ * 2013-07-19
398
+ * 1. Added incremental data file retrieval
399
+ *
400
+ * 2013-06-05
401
+ * 1. "Ignore associated product images" feature expanded to configurable products
402
+ *
403
+ * 2013-05-31
404
+ * 1. Added "Ignore associated product images" feature
405
+ *
406
+ * 2013-02-04
407
+ * 1. Added includelongdescription request parameter / processing
408
+ *
409
+ * 2012-12-07
410
+ * 1. Improved error / warning / notice reporting
411
+ * 2. Fixed configurable attributes import error
412
+ *
413
+ * 2012-12-04
414
+ * 1. Updated tier prices import
415
+ *
416
+ * 2012-11-05
417
+ * 1. Updated multiple images import
418
+ * 2. Added "Ignore excluded images" option support
419
+ *
420
+ * 2012-11-01
421
+ * 1. Updated debugging outout
422
+ *
423
+ * 2012-10-30
424
+ * 1. Added "Include taxes" option support
425
+ * 2. Updated images import: all product images are imported, not only the base one
426
+ *
427
+ * 2012-10-22
428
+ * 1. Added "Ignore top category" option support
429
+ *
430
+ * 2012-07-26
431
+ * 1. Added store spefification
432
+ * 2. Minor performance improvements
433
+ *
434
+ * 2012-07-25
435
+ * Minor performance improvements
436
+ *///==============================================================================
437
  }
438
+
439
  }
app/locale/en_US/Mage_CodiScript.csv DELETED
@@ -1 +0,0 @@
1
- "Use Valide Symbols","Allowed Characters A-Z a-z 0-9 <br/>Special Chars: ` ~ @ # % ^ & * ( ) – _ = + [ ] { } \ | ; : ' "" , . < > / ?"
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Codi</name>
4
- <version>4.2.8</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>
@@ -9,10 +9,10 @@
9
  <summary>Catalog-on-Demand</summary>
10
  <description>Extension to connect to the Catalog-on-Demand service for making print catalogs, brochures, and flyers.</description>
11
  <notes>Please contact our support desk if you have any problems.</notes>
12
- <authors><author><name>catalogondemand</name><user>auto-converted</user><email>timh@catalog-on-demand.com</email></author></authors>
13
- <date>2015-07-10</date>
14
- <time>01:06:16</time>
15
- <contents><target name="magecommunity"><dir name="Mage"><dir name="CodiScript"><dir name="Helper"><file name="Data.php" hash="3f99660cb06a9dc09f024b9993d43a3f"/></dir><dir name="Model"><file name="Files.php" hash="72f0abaefcac569121e8c973cc9fb8ef"/></dir><dir name="controllers"><file name="IndexController.php" hash="5528c3ca039e3d4b1fd43f660f3d9cc6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="40ab0bd86928c5ba175988926a9f6aee"/><file name="config.xml" hash="b960e9bd106f0c94559baa2bc5761e18"/><file name="system.xml" hash="1b5e5b18bfdce6b85e304fb4ef877274"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_CodiScript.xml" hash="f0502cac7918fc798b3b02d3d4b7e7fd"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="codiscript.xml" hash="066f99333a6054e11943a75413f65ff0"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="codi"><file name="password_validation.js" hash="7223aeed118bb5774c73f951460ae0b0"/></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Mage_CodiScript.csv" hash="183fc591065ced83f878a4c3e23f854c"/></dir></target></contents>
16
  <compatible/>
17
- <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Codi</name>
4
+ <version>4.3.0</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>
9
  <summary>Catalog-on-Demand</summary>
10
  <description>Extension to connect to the Catalog-on-Demand service for making print catalogs, brochures, and flyers.</description>
11
  <notes>Please contact our support desk if you have any problems.</notes>
12
+ <authors><author><name>catalogondemand</name><user>catalogondemand</user><email>timh@catalog-on-demand.com</email></author></authors>
13
+ <date>2016-10-11</date>
14
+ <time>00:43:11</time>
15
+ <contents><target name="magecommunity"><dir name="Mage"><dir name="CodiScript"><dir name="Helper"><file name="Data.php" hash="3f99660cb06a9dc09f024b9993d43a3f"/></dir><dir name="Model"><file name="Files.php" hash="b5d35239376f3672365faabe80120098"/></dir><dir name="controllers"><file name="IndexController.php" hash="69fd58379b9a1d5d9b6af5bea899e489"/></dir><dir name="etc"><file name="adminhtml.xml" hash="40ab0bd86928c5ba175988926a9f6aee"/><file name="config.xml" hash="b960e9bd106f0c94559baa2bc5761e18"/><file name="system.xml" hash="1b5e5b18bfdce6b85e304fb4ef877274"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mage_CodiScript.xml" hash="f0502cac7918fc798b3b02d3d4b7e7fd"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="codiscript.xml" hash="066f99333a6054e11943a75413f65ff0"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="codi"><file name="password_validation.js" hash="7223aeed118bb5774c73f951460ae0b0"/></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Mage_CodiScript.csv" hash=""/></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>