IcecatLive - Version 1.5.0

Version Notes

- Added mapping by EAN/UPC codes

- Added support of Multilanguage stores

- Added new setting Description Priority

- Added new setting Short Description Priority

- Added new setting Product Name Priority

- Added new setting Product Images Priority

- Added new setting Product Priority - display or hide products not from icecat

- Added display additional attributes by groups on product's page

- Added loading products description from DB when icecat info is missing and config setting product descr source is set to icecat

- Added saving icecat images to server and display from there

- Added saving product title to db from file and display it on list page

- Added cron process lock - only one icecat cron process can be running at a time

- LOAD LOCAL replaced with insert queries

- Removed logo images from product images gallery

- Fixed problems with Icecat names

- Fixed problems with images on product listing/shopping cart.

- Fixed problems with correct displaying attributes on product detail page

- Fixed problems with description on product detail page

- Fixed product info in breadcrumbs

- Fixed problems with loading icecat data for each product on product listing page
- Fixed problems with product images and gallery

Download this release

Release Info

Developer IceShop
Extension IcecatLive
Version 1.5.0
Comparing to
See all releases


Code changes from version 1.3.0 to 1.5.0

app/code/local/Bintime/Icecatimport/Block/Attributes.php CHANGED
@@ -1,72 +1,92 @@
1
  <?php
2
 
3
- class Bintime_Icecatimport_Block_Attributes extends Mage_Catalog_Block_Product_View_Attributes
4
- {
 
 
 
 
 
 
 
 
5
  public function getAdditionalData(array $excludeAttr = array())
6
  {
7
- $data = $this->getAttributesArray();
8
- $data2 = array();
9
- foreach($data as $_data)
10
- {
11
- if( $_data['label'] != '' && $_data['value'] != '' && $_data['code'] == 'descript'){
12
- $data2[] = array(
13
- 'label'=>$_data['label'],
14
- 'value'=>$_data['value'],
15
- 'code'=>''
16
- );}
17
-
18
- if( $_data['label'] == '' && $_data['value'] != '' && $_data['code'] == 'header')
19
- {
20
- $data2[] = array(
21
  'label'=>$_data['label'],
22
  'value'=>$_data['value'],
23
  'code'=>''
24
- );}
25
- //
26
- }
27
- return $data2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
  public function formatValue($value) {
31
  if($value == "Y"){
32
- return '<img border="0" alt="" src="http://prf.icecat.biz/imgs/yes.gif"/>';
 
33
  }
34
  else if ($value == "N"){
35
- return '<img border="0" alt="" src="http://prf.icecat.biz/imgs/no.gif"/>';
 
36
  }
37
-
38
- return
39
- str_replace("\\n", "<br>",
40
- htmlspecialchars($value)
41
- );
42
  }
43
 
44
  public function getAttributesArray() {
45
  $iceModel = Mage::getSingleton('icecatimport/import');
46
  $descriptionsListArray = $iceModel->getProductDescriptionList();
47
- foreach($descriptionsListArray as $ma)
48
- {
 
 
49
  foreach($ma as $key=>$value)
50
- {
51
  $arr[$key] = $value;
 
52
  }
53
  }
54
-
55
  $data = array();
56
  foreach ($arr as $key => $value) {
57
  //$attributes = Mage::getModel('catalog/product')->getAttributesFromIcecat($this->getProduct()->getEntityId(), $value);
58
  // @todo @someday @maybe make headers
59
- $data[] = array(
60
- 'label'=>'',
61
- 'value'=>'<h1>'.$key.'</h1>',
62
- 'code'=>'header'
 
63
  );
64
  $attributes = $value;
65
  foreach ($attributes as $attributeLabel => $attributeValue) {
66
  $data[] = array(
67
- 'label'=>$attributeLabel,
68
- 'value'=>$this->formatValue($attributeValue),
69
- 'code'=>'descript'
 
70
  );
71
  }
72
  }
1
  <?php
2
 
3
+ class Bintime_Icecatimport_Block_Attributes extends Mage_Core_Block_Template
4
+ {
5
+ public function getProduct()
6
+ {
7
+ if (!$this->_product) {
8
+ $this->_product = Mage::registry('product');
9
+ }
10
+ return $this->_product;
11
+ }
12
+
13
  public function getAdditionalData(array $excludeAttr = array())
14
  {
15
+ $data = $this->getAttributesArray();
16
+
17
+ $data2 = array();
18
+ foreach($data as $_data) {
19
+ if ($_data['label'] != '' && $_data['value'] != '' && $_data['label'] != 'id') {
20
+ $value = $_data['value'];
21
+ /* $data2[] = array(
 
 
 
 
 
 
 
22
  'label'=>$_data['label'],
23
  'value'=>$_data['value'],
24
  'code'=>''
25
+ );*/
26
+ $group = 0;
27
+ if ($tmp = $_data["id"]) {
28
+ $group = $tmp;
29
+ }
30
+
31
+ $data2[$group]['items'][$_data['label']] = array(
32
+ 'label' => $_data['label'],
33
+ 'value' => $value,
34
+ 'code' => $_data['label']
35
+ );
36
+
37
+ $data2[$group]['attrid'] = $_data["id"];
38
+
39
+ } else if (!empty($_data['code']) && $_data['code'] == 'header') {
40
+ $data2[$_data['id']]["title"] = $_data['value'];
41
+ }
42
+ }
43
+
44
+ return $data2;
45
  }
46
 
47
  public function formatValue($value) {
48
  if($value == "Y"){
49
+ //return "Yes";
50
+ return '<img border="0" alt="" src="http://prf.icecat.biz/imgs/yes.gif"/>';
51
  }
52
  else if ($value == "N"){
53
+ // return "No";
54
+ return '<img border="0" alt="" src="http://prf.icecat.biz/imgs/no.gif"/>';
55
  }
56
+ return str_replace("\\n", "<br>",htmlspecialchars($value));
 
 
 
 
57
  }
58
 
59
  public function getAttributesArray() {
60
  $iceModel = Mage::getSingleton('icecatimport/import');
61
  $descriptionsListArray = $iceModel->getProductDescriptionList();
62
+ $id = '';
63
+ $arr = array();
64
+ foreach($descriptionsListArray as $key=>$ma)
65
+ { $id = $key;
66
  foreach($ma as $key=>$value)
67
+ {
68
  $arr[$key] = $value;
69
+ $arr[$key]["id"] = $id;
70
  }
71
  }
72
+
73
  $data = array();
74
  foreach ($arr as $key => $value) {
75
  //$attributes = Mage::getModel('catalog/product')->getAttributesFromIcecat($this->getProduct()->getEntityId(), $value);
76
  // @todo @someday @maybe make headers
77
+ $data[] = array(
78
+ 'label' => '',
79
+ 'value' => $key,
80
+ 'code' => 'header',
81
+ 'id' => $value["id"]
82
  );
83
  $attributes = $value;
84
  foreach ($attributes as $attributeLabel => $attributeValue) {
85
  $data[] = array(
86
+ 'label' => $attributeLabel,
87
+ 'value' => $this->formatValue($attributeValue),
88
+ 'code' => 'descript',
89
+ 'id' => $value["id"]
90
  );
91
  }
92
  }
app/code/local/Bintime/Icecatimport/Block/Media.php CHANGED
@@ -5,27 +5,24 @@ class Bintime_Icecatimport_Block_Media extends Mage_Catalog_Block_Product_View_M
5
  protected $_isGalleryDisabled;
6
 
7
  public function getGalleryImages()
8
- {
9
  if ($this->_isGalleryDisabled) {
10
  return array();
11
  }
12
- $iceCatModel = Mage::getSingleton('icecatimport/import');
13
- $icePhotos = $iceCatModel->getGalleryPhotos();
14
-
15
  $collection = $this->getProduct()->getMediaGalleryImages();
16
  $items = $collection->getItems();
17
- if(!empty($icePhotos)){
18
- return Mage::getSingleton('Bintime_Icecatimport_Model_Imagescollection',array(
19
- 'product' => $this->getProduct()
20
- ));
 
21
  } else if (count($items) == 1) {
22
-
23
- return array();
24
-
25
- } else{
26
-
27
  return $collection;
28
-
29
  }
30
  }
31
 
@@ -37,7 +34,9 @@ class Bintime_Icecatimport_Block_Media extends Mage_Catalog_Block_Product_View_M
37
  $icePhotos = $iceCatModel->getGalleryPhotos();
38
  $collection = $this->getProduct()->getMediaGalleryImages();
39
  $items = $collection->getItems();
40
- if (!empty($icePhotos)) {
 
 
41
  $product_id = $this->getProduct()->getEntityId();
42
  $image_saved = $iceCatModel->saveImg($product_id,$image['file'],'thumb');
43
  return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$image_saved;
5
  protected $_isGalleryDisabled;
6
 
7
  public function getGalleryImages()
8
+ {
9
  if ($this->_isGalleryDisabled) {
10
  return array();
11
  }
12
+ $iceCatModel = Mage::getSingleton('icecatimport/import');
13
+ $icePhotos = $iceCatModel->getGalleryPhotos();
14
+
15
  $collection = $this->getProduct()->getMediaGalleryImages();
16
  $items = $collection->getItems();
17
+ $Imagepriority = Mage::getStoreConfig('icecat_root/icecat/image_priority');
18
+ if (!empty($icePhotos) && $Imagepriority != 'Db'){
19
+ return Mage::getSingleton('Bintime_Icecatimport_Model_Imagescollection',array(
20
+ 'product' => $this->getProduct()
21
+ ));
22
  } else if (count($items) == 1) {
23
+ return array();
24
+ } else{
 
 
 
25
  return $collection;
 
26
  }
27
  }
28
 
34
  $icePhotos = $iceCatModel->getGalleryPhotos();
35
  $collection = $this->getProduct()->getMediaGalleryImages();
36
  $items = $collection->getItems();
37
+ $Imagepriority = Mage::getStoreConfig('icecat_root/icecat/image_priority');
38
+
39
+ if (!empty($icePhotos) && $Imagepriority != 'Db') {
40
  $product_id = $this->getProduct()->getEntityId();
41
  $image_saved = $iceCatModel->saveImg($product_id,$image['file'],'thumb');
42
  return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$image_saved;
app/code/local/Bintime/Icecatimport/Block/Product/List/Toolbar.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Bintime_Icecatimport_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
4
+ {
5
+ public static $_productCollection = null;
6
+ public static $_totalRecords = null;
7
+
8
+ public function getCollection()
9
+ {
10
+ $ProductPriority = Mage::getStoreConfig('icecat_root/icecat/product_priority');
11
+ $_productCollection = parent::getCollection();
12
+
13
+ if (!$_productCollection->count() || $ProductPriority == 'Show') {
14
+ return $_productCollection;
15
+ } else {
16
+ foreach ($_productCollection as $_product) {
17
+ $icecat_prod = $this->CheckIcecatData($_product);
18
+ if ($icecat_prod === false) {
19
+ $_productCollection->removeItemByKey($_product->getId());
20
+ }
21
+ }
22
+
23
+ self::$_productCollection = $_productCollection;
24
+
25
+ return $_productCollection;
26
+ }
27
+ }
28
+ public function getTotalNum() {
29
+ if (self::$_productCollection === null) {
30
+ return parent::getTotalNum();
31
+ }
32
+ self::$_totalRecords = count(self::$_productCollection->getItems());
33
+ return intval(self::$_totalRecords);
34
+ }
35
+
36
+ public function CheckIcecatData($_product) {
37
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
38
+ $mpn = Mage::getModel('catalog/product')->load($_product->getId())->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
39
+ $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data').'_products';
40
+ $selectCondition = $connection->select()
41
+ ->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_title'))
42
+ ->where('connector.prod_id = ? ', $mpn);
43
+ $icecatName = $connection->fetchOne($selectCondition);
44
+ if (!empty($icecatName)) {
45
+ return true;
46
+ } else {
47
+ $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
48
+ $mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
49
+ $ean = Mage::getModel('catalog/product')->load($_product->getId())->getData(Mage::getStoreConfig('icecat_root/icecat/ean_code'));
50
+ $manufacturer = Mage::getModel('catalog/product')->load($_product->getId())->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
51
+ if (isset($manufacturer) && !empty($manufacturer)) {
52
+ $selectCondition = $connection->select()
53
+ ->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_img'))
54
+ ->joinInner(array('supplier' => $mappingTable), "connector.supplier_id = supplier.supplier_id AND supplier.supplier_symbol = {$connection->quote($manufacturer)}")
55
+ ->where('connector.prod_id = ?', $mpn);
56
+ $imageURL = $connection->fetchOne($selectCondition);
57
+ }
58
+ if (empty($imageURL) && !empty($ean)) {
59
+ $selectCondition = $connection->select()
60
+ ->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_img'))
61
+ ->joinLeft(array('products' => $tableName.'_products'), "connector.prod_id = products.prod_id")
62
+ ->where('products.prod_ean = ?', trim($ean));
63
+ $imageURL = $connection->fetchOne($selectCondition);
64
+ }
65
+ $icecat_prod = !empty($imageURL) ? true : false;
66
+ return $icecat_prod;
67
+ }
68
+ }
69
+ }
70
+ ?>
app/code/local/Bintime/Icecatimport/CatalogSearch/Block/Result.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_CatalogSearch_Block_Result extends Mage_CatalogSearch_Block_Result {
3
+
4
+ /**
5
+ * Retrieve search result count
6
+ *
7
+ * @return string
8
+ */
9
+ public function getResultCount()
10
+ {
11
+ $ProductPriority = Mage::getStoreConfig('icecat_root/icecat/product_priority');
12
+
13
+ if ($ProductPriority == 'Show') {
14
+ return parent::getResultCount();
15
+ }
16
+
17
+ $products = $this->_getProductCollection();
18
+ $toolbar = new Bintime_Icecatimport_Block_Product_List_Toolbar();
19
+ foreach ($products as $_product) {
20
+ $icecat_prod = $toolbar->CheckIcecatData($_product);
21
+ if ($icecat_prod === false) {
22
+ $products->removeItemByKey($_product->getId());
23
+ }
24
+ }
25
+ $size = count($products->getItems());
26
+ $this->_getQuery()->setNumResults($size);
27
+ $this->setResultCount($size);
28
+ return $this->getData('result_count');
29
+ }
30
+
31
+ }
32
+ ?>
app/code/local/Bintime/Icecatimport/Helper/Catalog/Image.php CHANGED
@@ -14,7 +14,16 @@ class Bintime_Icecatimport_Helper_Catalog_Image extends Mage_Catalog_Helper_Imag
14
  * @param $imageFile string
15
  */
16
  public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
17
- { $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath().'/';
 
 
 
 
 
 
 
 
 
18
  if ($attributeName == 'image' && $imageFile == null ) {
19
  $imageFile = mage::getsingleton('icecatimport/import')->getLowPicUrl();
20
  } else if ($attributeName == 'thumbnail' && $imageFile == null ) {
@@ -26,7 +35,7 @@ class Bintime_Icecatimport_Helper_Catalog_Image extends Mage_Catalog_Helper_Imag
26
  $imageFile = $iceImport->getImg($product->getId());
27
  }
28
  } else if (!empty($imageFile)) {
29
- $iceCatModel = Mage::getSingleton('icecatimport/import');
30
  if (!strpos($imageFile,'ttp')) {
31
  $imageFile = $iceCatModel->saveImg($product->getEntityId(),Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$imageFile,$attributeName);
32
  } else {
14
  * @param $imageFile string
15
  */
16
  public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
17
+ {
18
+ $current_page = Mage::app()->getFrontController()->getRequest()->getControllerName();
19
+ $url = Mage::helper('core/url')->getCurrentUrl();
20
+ $is_gallery = (int) strpos($url,'catalog/product/gallery');
21
+ $Imagepriority = Mage::getStoreConfig('icecat_root/icecat/image_priority');
22
+ if ($Imagepriority == 'Db' || (($attributeName == 'thumbnail' && !empty($imageFile)
23
+ && $current_page == 'product' ) || ($is_gallery > 0)) ) {
24
+ return parent::init($product, $attributeName, $imageFile);
25
+ }
26
+
27
  if ($attributeName == 'image' && $imageFile == null ) {
28
  $imageFile = mage::getsingleton('icecatimport/import')->getLowPicUrl();
29
  } else if ($attributeName == 'thumbnail' && $imageFile == null ) {
35
  $imageFile = $iceImport->getImg($product->getId());
36
  }
37
  } else if (!empty($imageFile)) {
38
+ $iceCatModel = Mage::getSingleton('icecatimport/import');
39
  if (!strpos($imageFile,'ttp')) {
40
  $imageFile = $iceCatModel->saveImg($product->getEntityId(),Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$imageFile,$attributeName);
41
  } else {
app/code/local/Bintime/Icecatimport/Helper/Getdata.php CHANGED
@@ -183,8 +183,8 @@ class Bintime_Icecatimport_Helper_Getdata extends Mage_Core_Helper_Abstract
183
  }
184
  array_push($relatedProductsList['a'], $relatedProductInfo);
185
  }
186
- return $relatedProductsList;
187
  }
 
188
  }
189
  }
190
  ?>
183
  }
184
  array_push($relatedProductsList['a'], $relatedProductInfo);
185
  }
 
186
  }
187
+ return $relatedProductsList;
188
  }
189
  }
190
  ?>
app/code/local/Bintime/Icecatimport/Helper/Output.php CHANGED
@@ -29,47 +29,65 @@ class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
29
  // return parent::productAttribute($product, $attributeHtml, $attributeName);
30
  }
31
 
32
- if ($attributeName == 'image') {
33
- return parent::productAttribute($product, $attributeHtml, $attributeName);
34
- }
35
 
36
  $productDescriptionPriority = Mage::getStoreConfig('icecat_root/icecat/descript_priority');
37
- $dbDescriptionPriority = false;
 
 
 
 
 
 
38
  $current_page = Mage::app()->getFrontController()->getRequest()->getControllerName();
39
- if ($productDescriptionPriority == 'Db' &&
40
- ( $attributeName == 'description' || $attributeName == 'short_description')) {
41
  $dbDescriptionPriority = true;
42
- }
43
-
 
 
 
44
  if ($current_page == 'product') {
45
  $bin_prod = new Bintime_Icecatimport_Model_Catalog_Product();
46
  if ($attributeName == 'description' || $attributeName == 'short_description') {
47
- $descr = $bin_prod->checkIcecatProdDescription($productId,$attributeName);
48
  }
49
  }
50
  $prod_source = Bintime_Icecatimport_Model_Catalog_Product::$_product_source;
51
-
52
  if( $prod_source == 'DB' && empty($descr) ) {
53
  $dbDescriptionPriority = true;
 
54
  }
55
 
56
- if ($dbDescriptionPriority || ($current_page != 'product'
57
- && $prod_source != 'DB' && $attributeName != 'name') ) {
58
- $attributeHtml = $product->getData('short_description');
59
- return parent::productAttribute($product, $attributeHtml, $attributeName);
 
 
 
 
 
 
60
  }
 
61
  $this->iceCatModel = Mage::getSingleton('icecatimport/import');
 
62
  if ($this->isFirstTime){
63
  $helper = Mage::helper('icecatimport/getdata');
64
  $helper->getProductDescription($product);
65
 
66
- if ($helper->hasError() && !$dbDescriptionPriority) {
67
  $this->error = true;
68
  }
69
  $this->isFirstTime = false;
70
  }
71
-
72
  if ($this->error){
 
73
  if ($attributeName != 'description' && $attributeName != 'short_description') {
74
  return parent::productAttribute($product, $attributeHtml, $attributeName);
75
  } else {
@@ -77,8 +95,10 @@ class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
77
  }
78
 
79
  }
 
80
  $id = $product->getData('entity_id');
81
- if ($attributeName == 'name'){
 
82
  //if we on product page then mage::registry('product') exist
83
  if ($product->getId() == $this->iceCatModel->entityId && $name = $this->iceCatModel->getProductName()) {
84
  return $name;
@@ -95,7 +115,8 @@ class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
95
  return $product->getName();
96
  }
97
 
98
- if ($attributeName == 'short_description') {
 
99
  $icecat_descr = $this->iceCatModel->getShortProductDescription();
100
  if (!empty($descr)) {
101
  return $descr;
@@ -106,7 +127,9 @@ class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
106
  return parent::productAttribute($product, $attributeHtml, $attributeName);
107
  }
108
  }
109
- if ($attributeName == 'description') {
 
 
110
  $icecat_full_descr = $this->iceCatModel->getFullProductDescription();
111
  if (!empty($icecat_full_descr)) {
112
  return str_replace("\\n", "<br>",$icecat_full_descr);
29
  // return parent::productAttribute($product, $attributeHtml, $attributeName);
30
  }
31
 
32
+ if ($attributeName == 'image') {
33
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
34
+ }
35
 
36
  $productDescriptionPriority = Mage::getStoreConfig('icecat_root/icecat/descript_priority');
37
+ $productShortDescrPriority = Mage::getStoreConfig('icecat_root/icecat/shortdescr_priority');
38
+ $productNamePriority = Mage::getStoreConfig('icecat_root/icecat/name_priority');
39
+
40
+
41
+
42
+ $dbDescriptionPriority = false;
43
+ $dbShortDescriptionPriority = false;
44
  $current_page = Mage::app()->getFrontController()->getRequest()->getControllerName();
45
+ if ($productDescriptionPriority == 'Db' && $attributeName == 'description') {
 
46
  $dbDescriptionPriority = true;
47
+ }
48
+ if ($productShortDescrPriority == 'Db' && $attributeName == 'short_description') {
49
+ $dbShortDescriptionPriority = true;
50
+ }
51
+
52
  if ($current_page == 'product') {
53
  $bin_prod = new Bintime_Icecatimport_Model_Catalog_Product();
54
  if ($attributeName == 'description' || $attributeName == 'short_description') {
55
+ $descr = $bin_prod->checkIcecatProdDescription($productId,$attributeName);
56
  }
57
  }
58
  $prod_source = Bintime_Icecatimport_Model_Catalog_Product::$_product_source;
59
+
60
  if( $prod_source == 'DB' && empty($descr) ) {
61
  $dbDescriptionPriority = true;
62
+ $dbShortDescriptionPriority = true;
63
  }
64
 
65
+ if ($dbShortDescriptionPriority || ($current_page != 'product'
66
+ && $prod_source != 'DB' ) && $attributeName != 'name') {
67
+ if ($attributeName == 'short_description') {
68
+ $attributeHtml = $product->getData('short_description');
69
+ }
70
+
71
+ if ($attributeName == 'description' && $attributeHtml == 1) {
72
+ $attributeHtml = $product->getData('description');
73
+ }
74
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
75
  }
76
+
77
  $this->iceCatModel = Mage::getSingleton('icecatimport/import');
78
+
79
  if ($this->isFirstTime){
80
  $helper = Mage::helper('icecatimport/getdata');
81
  $helper->getProductDescription($product);
82
 
83
+ if ($helper->hasError() && $attributeName != 'name') {
84
  $this->error = true;
85
  }
86
  $this->isFirstTime = false;
87
  }
88
+
89
  if ($this->error){
90
+
91
  if ($attributeName != 'description' && $attributeName != 'short_description') {
92
  return parent::productAttribute($product, $attributeHtml, $attributeName);
93
  } else {
95
  }
96
 
97
  }
98
+
99
  $id = $product->getData('entity_id');
100
+
101
+ if ($attributeName == 'name' && $productNamePriority != 'Db'){
102
  //if we on product page then mage::registry('product') exist
103
  if ($product->getId() == $this->iceCatModel->entityId && $name = $this->iceCatModel->getProductName()) {
104
  return $name;
115
  return $product->getName();
116
  }
117
 
118
+ if ($attributeName == 'short_description' && !$dbShortDescriptionPriority ) {
119
+
120
  $icecat_descr = $this->iceCatModel->getShortProductDescription();
121
  if (!empty($descr)) {
122
  return $descr;
127
  return parent::productAttribute($product, $attributeHtml, $attributeName);
128
  }
129
  }
130
+
131
+ if ($attributeName == 'description' && !$dbDescriptionPriority) {
132
+
133
  $icecat_full_descr = $this->iceCatModel->getFullProductDescription();
134
  if (!empty($icecat_full_descr)) {
135
  return str_replace("\\n", "<br>",$icecat_full_descr);
app/code/local/Bintime/Icecatimport/Model/Catalog/Product.php CHANGED
@@ -7,11 +7,19 @@
7
  class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Product
8
  {
9
 
10
- public function getName(){
 
 
 
 
 
 
11
  try {
 
12
  $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
13
  $manufacturerId = $this->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
14
  $mpn = $this->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
 
15
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
16
  ->setCodeFilter(Mage::getStoreConfig('icecat_root/icecat/manufacturer'))
17
  ->setEntityTypeFilter($this->getResource()->getTypeId())
@@ -31,11 +39,12 @@ class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Prod
31
  ->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_title'))
32
  ->where('connector.prod_id = ? ', $mpn);
33
  $icecatName = $connection->fetchOne($selectCondition);
 
34
  } catch (Exception $e) {
35
  Mage::log('Icecat getName error'.$e);
36
  }
37
 
38
- $product_name = $icecatName ? str_replace("|"," ",$icecatName) : $this->getData('name');
39
  return $product_name;
40
  }
41
 
@@ -64,7 +73,7 @@ class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Prod
64
  }
65
 
66
  public function getDescription() {
67
-
68
  if( !isset(self::$_product_source) ) {
69
  $this->checkIcecatProdDescription();
70
  }
@@ -106,8 +115,9 @@ class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Prod
106
  $descr[1] = false;
107
 
108
  $descr[0] = $iceImport->getProductDescription($mpn, $manufacturer, $locale, $userLogin, $userPass, $entityId, $ean_code);
109
-
110
  if (!empty($iceImport->simpleDoc)){
 
111
  $productTag = $iceImport->simpleDoc->Product;
112
  $descr[1] = (string) $productTag->ProductDescription['ShortDesc'];
113
  } else if(!empty($descr[0]) && $attributeName == 'short_description') {
@@ -118,11 +128,14 @@ class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Prod
118
  if($descr[0] == false and $descr[1] == false) {
119
  self::$_product_source = 'DB';
120
  } else if ($attributeName == 'short_description') {
121
- self::$_product_source = '';
122
- return $descr[1];
123
  } else if ($attributeName == 'name') {
124
- return $iceImport->getProductName();
125
- }
 
 
 
126
  }
127
 
128
 
7
  class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Product
8
  {
9
 
10
+ public function getName(){
11
+
12
+ $productNamePriority = Mage::getStoreConfig('icecat_root/icecat/name_priority');
13
+ if ($productNamePriority=='Db') {
14
+ return parent::getName();
15
+ }
16
+
17
  try {
18
+ self::$_product_source = '';
19
  $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
20
  $manufacturerId = $this->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
21
  $mpn = $this->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
22
+
23
  $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
24
  ->setCodeFilter(Mage::getStoreConfig('icecat_root/icecat/manufacturer'))
25
  ->setEntityTypeFilter($this->getResource()->getTypeId())
39
  ->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_title'))
40
  ->where('connector.prod_id = ? ', $mpn);
41
  $icecatName = $connection->fetchOne($selectCondition);
42
+
43
  } catch (Exception $e) {
44
  Mage::log('Icecat getName error'.$e);
45
  }
46
 
47
+ $product_name = !empty($icecatName) ? str_replace("|"," ",$icecatName) : $this->getData('name');
48
  return $product_name;
49
  }
50
 
73
  }
74
 
75
  public function getDescription() {
76
+
77
  if( !isset(self::$_product_source) ) {
78
  $this->checkIcecatProdDescription();
79
  }
115
  $descr[1] = false;
116
 
117
  $descr[0] = $iceImport->getProductDescription($mpn, $manufacturer, $locale, $userLogin, $userPass, $entityId, $ean_code);
118
+
119
  if (!empty($iceImport->simpleDoc)){
120
+
121
  $productTag = $iceImport->simpleDoc->Product;
122
  $descr[1] = (string) $productTag->ProductDescription['ShortDesc'];
123
  } else if(!empty($descr[0]) && $attributeName == 'short_description') {
128
  if($descr[0] == false and $descr[1] == false) {
129
  self::$_product_source = 'DB';
130
  } else if ($attributeName == 'short_description') {
131
+ self::$_product_source = '';
132
+ return $descr[1];
133
  } else if ($attributeName == 'name') {
134
+ self::$_product_source = '';
135
+ return $iceImport->getProductName();
136
+ } else {
137
+ self::$_product_source = '';
138
+ }
139
  }
140
 
141
 
app/code/local/Bintime/Icecatimport/Model/Import.php CHANGED
@@ -76,7 +76,7 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
76
  "vendor" => $vendorName,
77
  "output" => 'productxml'
78
  ));
79
-
80
  if ($this->parseXml($resultString)) {
81
  if (!$this->checkIcecatResponse()) {
82
  $successRespondByMPNVendorFlag = true;
@@ -92,7 +92,8 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
92
  'lang' => $locale,
93
  'output' => 'productxml'
94
  ));
95
-
 
96
  if (!$this->parseXml($resultString)) {
97
  $error = true;
98
  $this->simpleDoc = null;
@@ -134,6 +135,7 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
134
 
135
  private function _getIceCatData($userName, $userPass, $dataUrl, $productAttributes){
136
  try{
 
137
  $webClient = new Zend_Http_Client();
138
  $webClient->setUri($dataUrl);
139
  $webClient->setMethod(Zend_Http_Client::GET);
@@ -196,19 +198,22 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
196
  if (!count($galleryPhotos)){
197
  return false;
198
  }
199
- foreach($galleryPhotos as $photo){
200
- if ($photo["Size"] > 0){
201
- $picHeight = (int)$photo["PicHeight"];
202
- $picWidth = (int)$photo["PicWidth"];
203
- $thumbUrl = (string)$photo["ThumbPic"];
204
- $picUrl = (string)$photo["Pic"];
205
-
206
- array_push($this->galleryPhotos, array(
207
- 'height' => $picHeight,
208
- 'width' => $picWidth,
209
- 'thumb' => $thumbUrl,
210
- 'pic' => $picUrl
211
- ));
 
 
 
212
  }
213
  }
214
  }
@@ -356,7 +361,9 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
356
  $this->_manualPdfUrl = (string)$productTag->ProductDescription['ManualPDFURL'];
357
  $this->_pdfUrl = (string)$productTag->ProductDescription['PDFURL'];
358
  $this->_multimedia = $productTag->ProductMultimediaObject->MultimediaObject;
359
- $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath().'/';
 
 
360
  if (!empty($productTag["HighPic"])) {
361
  $this->highPicUrl = $this->saveImg($this->entityId,(string)$productTag["HighPic"]);
362
  } else if (!empty($productTag["LowPic"])) {
@@ -364,7 +371,7 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
364
  } else {
365
  $this->thumb = $this->saveImg($this->entityId,(string)$productTag["ThumbPic"],'thumb');
366
  }
367
-
368
  $this->productName = (string)$productTag["Title"];
369
  $this->productId = (string)$productTag['Prod_id'];
370
  $this->vendor = (string)$productTag->Supplier['Name'];
@@ -412,38 +419,78 @@ class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
412
  * @param string $img_type
413
  */
414
  public function saveImg($productId,$img_url,$imgtype = '') {
415
- $test_loader = Mage::getBaseDir('var') . $this->_connectorDir . 'test_img.txt';
416
-
417
  $pathinfo = pathinfo($img_url);
418
  $img_type= $pathinfo["extension"];
419
- $img_name = md5($img_url);
420
- //$img_name = $pathinfo["filename"];
 
 
 
 
 
 
 
 
 
421
  $img = $img_name.".".$img_type;
422
  $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath().'/';
423
  $local_img = strstr($img_url,Mage::getStoreConfig('web/unsecure/base_url'));
424
 
425
  if (!file_exists($baseDir.$img) && !$local_img) {
426
- file_put_contents($test_loader,' here 424 prod - '.$productId.' img '.$baseDir.$img.' ',FILE_APPEND);
427
  $client = new Zend_Http_Client($img_url);
428
  $content=$client->request();
429
  if ($content->isError()) {
430
- file_put_contents($test_loader,' here 428 '.$productId.' ',FILE_APPEND);
431
  return $img_url;
432
  }
433
  $file = file_put_contents($baseDir.$img,$content->getBody());
434
  if ($file) {
435
  $this->addProductImageQuery($productId,$img,$imgtype);
436
- file_put_contents($test_loader,' here 434 '.$productId.' ',FILE_APPEND);
437
  return $img;
438
  } else {
439
- file_put_contents($test_loader,' here 437 '.$productId.' ',FILE_APPEND);
440
  return $img_url;
441
  }
442
  } else if($local_img) {
443
- file_put_contents($test_loader,' here 441 '.$productId.' ',FILE_APPEND);
444
  return $img_url;
445
  } else {
446
- file_put_contents($test_loader,' here 443 '.$productId.' ',FILE_APPEND);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  return $img;
448
  }
449
  }
@@ -499,6 +546,9 @@ file_put_contents($test_loader,' here 424 prod - '.$productId.' img '.$baseDir.$
499
  ':entity_id' => $productId,
500
  ':img' => $img));
501
  }
 
 
 
502
  $db->query(" INSERT INTO `" .$tablePrefix . "catalog_product_entity_media_gallery` (attribute_id,entity_id,value)
503
  VALUES(@gallery,:entity_id,:img )",array(
504
  ':entity_id' => $productId,
@@ -508,6 +558,14 @@ file_put_contents($test_loader,' here 424 prod - '.$productId.' img '.$baseDir.$
508
  (value_id,store_id,label,position,disabled)
509
  VALUES(LAST_INSERT_ID(),:store_id,'',1,0 )",array(
510
  ':store_id' => $DefaultStoreId));
 
 
 
 
 
 
 
 
511
  }
512
 
513
  }
76
  "vendor" => $vendorName,
77
  "output" => 'productxml'
78
  ));
79
+
80
  if ($this->parseXml($resultString)) {
81
  if (!$this->checkIcecatResponse()) {
82
  $successRespondByMPNVendorFlag = true;
92
  'lang' => $locale,
93
  'output' => 'productxml'
94
  ));
95
+
96
+
97
  if (!$this->parseXml($resultString)) {
98
  $error = true;
99
  $this->simpleDoc = null;
135
 
136
  private function _getIceCatData($userName, $userPass, $dataUrl, $productAttributes){
137
  try{
138
+
139
  $webClient = new Zend_Http_Client();
140
  $webClient->setUri($dataUrl);
141
  $webClient->setMethod(Zend_Http_Client::GET);
198
  if (!count($galleryPhotos)){
199
  return false;
200
  }
201
+ foreach($galleryPhotos as $photo) {
202
+ if ($photo["Size"] > 0) {
203
+ $picUrl = (string)$photo["Pic"];
204
+ if (!empty($picUrl) && strpos($picUrl,'feature_logo') <= 0) {
205
+ $picHeight = (int)$photo["PicHeight"];
206
+ $picWidth = (int)$photo["PicWidth"];
207
+ $thumbUrl = (string)$photo["ThumbPic"];
208
+
209
+
210
+ array_push($this->galleryPhotos, array(
211
+ 'height' => $picHeight,
212
+ 'width' => $picWidth,
213
+ 'thumb' => $thumbUrl,
214
+ 'pic' => $picUrl
215
+ ));
216
+ }
217
  }
218
  }
219
  }
361
  $this->_manualPdfUrl = (string)$productTag->ProductDescription['ManualPDFURL'];
362
  $this->_pdfUrl = (string)$productTag->ProductDescription['PDFURL'];
363
  $this->_multimedia = $productTag->ProductMultimediaObject->MultimediaObject;
364
+
365
+ $Imagepriority = Mage::getStoreConfig('icecat_root/icecat/image_priority');
366
+ if ($Imagepriority != 'Db') {
367
  if (!empty($productTag["HighPic"])) {
368
  $this->highPicUrl = $this->saveImg($this->entityId,(string)$productTag["HighPic"]);
369
  } else if (!empty($productTag["LowPic"])) {
371
  } else {
372
  $this->thumb = $this->saveImg($this->entityId,(string)$productTag["ThumbPic"],'thumb');
373
  }
374
+ }
375
  $this->productName = (string)$productTag["Title"];
376
  $this->productId = (string)$productTag['Prod_id'];
377
  $this->vendor = (string)$productTag->Supplier['Name'];
419
  * @param string $img_type
420
  */
421
  public function saveImg($productId,$img_url,$imgtype = '') {
422
+
 
423
  $pathinfo = pathinfo($img_url);
424
  $img_type= $pathinfo["extension"];
425
+
426
+ if (strpos($img_url,'high') > 0) {
427
+ $img_name = str_replace("http://images.icecat.biz/img/norm/high/","",$img_url);
428
+ $img_name = md5($img_name);
429
+ } else if (strpos($img_url,'low') > 0) {
430
+ $img_name = str_replace("http://images.icecat.biz/img/norm/low/","",$img_url);
431
+ $img_name = md5($img_name);
432
+ } else {
433
+ $img_name = md5($img_url);
434
+ }
435
+
436
  $img = $img_name.".".$img_type;
437
  $baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath().'/';
438
  $local_img = strstr($img_url,Mage::getStoreConfig('web/unsecure/base_url'));
439
 
440
  if (!file_exists($baseDir.$img) && !$local_img) {
 
441
  $client = new Zend_Http_Client($img_url);
442
  $content=$client->request();
443
  if ($content->isError()) {
 
444
  return $img_url;
445
  }
446
  $file = file_put_contents($baseDir.$img,$content->getBody());
447
  if ($file) {
448
  $this->addProductImageQuery($productId,$img,$imgtype);
 
449
  return $img;
450
  } else {
 
451
  return $img_url;
452
  }
453
  } else if($local_img) {
 
454
  return $img_url;
455
  } else {
456
+
457
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
458
+ $tablePrefix = (array)Mage::getConfig()->getTablePrefix();
459
+ if (!empty($tablePrefix[0])) {
460
+ $tablePrefix = $tablePrefix[0];
461
+ } else {
462
+ $tablePrefix = '';
463
+ }
464
+ $attr_query = "SELECT @product_entity_type_id := `entity_type_id` FROM `" .$tablePrefix . "eav_entity_type` WHERE
465
+ entity_type_code = 'catalog_product';
466
+ SELECT @attribute_set_id := `entity_type_id` FROM `" . $tablePrefix . "eav_entity_type` WHERE
467
+ entity_type_code = 'catalog_product';
468
+ SELECT @gallery := `attribute_id` FROM `" . $tablePrefix . "eav_attribute` WHERE
469
+ `attribute_code` = 'media_gallery' AND entity_type_id = @product_entity_type_id;
470
+ SELECT @base := `attribute_id` FROM `" . $tablePrefix . "eav_attribute` WHERE `attribute_code` = 'image' AND entity_type_id = @product_entity_type_id;
471
+ SELECT @small := `attribute_id` FROM `" . $tablePrefix . "eav_attribute` WHERE
472
+ `attribute_code` = 'small_image' AND entity_type_id = @product_entity_type_id;
473
+ SELECT @thumb := `attribute_id` FROM `" . $tablePrefix . "eav_attribute` WHERE
474
+ `attribute_code` = 'thumbnail' AND entity_type_id = @product_entity_type_id;";
475
+
476
+ $attr_set = Mage::getModel('catalog/product')->getResource()->getEntityType()->getDefaultAttributeSetId();
477
+
478
+ $db->query($attr_query, array(':attribute_set' => $attr_set));
479
+
480
+ $img_check = $db->fetchAll("SELECT COUNT(*) FROM `" .$tablePrefix . "catalog_product_entity_varchar`
481
+ WHERE attribute_id IN (@base ,@small,@thumb)
482
+ AND entity_id =:entity_id AND value =:img ",array(
483
+ ':entity_id' => $productId,
484
+ ':img' => $img));
485
+
486
+ $gal_check = $db->fetchAll("SELECT COUNT(*) FROM `" .$tablePrefix . "catalog_product_entity_media_gallery`
487
+ WHERE attribute_id = @gallery AND entity_id =:entity_id AND value =:img ",array(
488
+ ':entity_id' => $productId,
489
+ ':img' => $img));
490
+ if ((isset($img_check[0]["COUNT(*)"]) && isset($gal_check[0]["COUNT(*)"]))
491
+ && ($img_check[0]["COUNT(*)"] == 0 && $gal_check[0]["COUNT(*)"] == 0)) {
492
+ $this->addProductImageQuery($productId,$img,$imgtype);
493
+ }
494
  return $img;
495
  }
496
  }
546
  ':entity_id' => $productId,
547
  ':img' => $img));
548
  }
549
+
550
+
551
+
552
  $db->query(" INSERT INTO `" .$tablePrefix . "catalog_product_entity_media_gallery` (attribute_id,entity_id,value)
553
  VALUES(@gallery,:entity_id,:img )",array(
554
  ':entity_id' => $productId,
558
  (value_id,store_id,label,position,disabled)
559
  VALUES(LAST_INSERT_ID(),:store_id,'',1,0 )",array(
560
  ':store_id' => $DefaultStoreId));
561
+
562
+ /*$rows = $db->fetchAll("SELECT value_id FROM `" .$tablePrefix . "catalog_product_entity_media_gallery`
563
+ WHERE attribute_id = @gallery AND entity_id =:entity_id ",array(
564
+ ':entity_id' => $productId));
565
+ if (count($rows > 0)) {
566
+ echo '<pre>'; var_dump($rows); echo " ============ ";
567
+ }*/
568
+
569
  }
570
 
571
  }
app/code/local/Bintime/Icecatimport/Model/Observer.php CHANGED
@@ -6,10 +6,17 @@
6
  *
7
  */
8
  class Bintime_Icecatimport_Model_Observer
9
- {
 
 
 
 
 
 
 
10
  private $errorMessage;
11
  private $connection;
12
-
13
  private $freeExportURLs = 'http://data.icecat.biz/export/freeurls/export_urls_rich.txt.gz';
14
  private $fullExportURLs = 'http://data.icecat.biz/export/export_urls_rich.txt.gz';
15
  private $productinfoUrL = 'http://data.icecat.biz/prodid/prodid_d.txt.gz';
@@ -26,11 +33,20 @@ class Bintime_Icecatimport_Model_Observer
26
  * root method for uploading images to DB
27
  */
28
  public function load(){
29
- $testfile = Mage::getBaseDir('var') . $this->_connectorDir . 'newt.txt';
30
- file_put_contents($testfile, 'here obs',FILE_APPEND);
31
  $loadUrl = $this->getLoadURL();
32
  ini_set('max_execution_time', 0);
33
  try {
 
 
 
 
 
 
 
 
 
34
  $this->_productFile = $this->_prepareFile(basename($loadUrl));
35
  $this->_supplierFile = $this->_prepareFile(basename($this->_supplierMappingUrl));
36
  echo "Data file downloading started <br>";
@@ -59,6 +75,7 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
59
  $this->loadFileToDb();
60
 
61
  echo " Product Data File Processed Succesfully<br>";
 
62
  } catch( Exception $e) {
63
  echo $e->getMessage();
64
  Mage::log($e->getMessage());
@@ -152,8 +169,8 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
152
  * @param string $productManufacturer
153
  */
154
  public function getImageURL($productSku, $productManufacturer, $productId = ''){
 
155
  $connection = $this->getDbConnection();
156
- $testfile = Mage::getBaseDir('var') . $this->_connectorDir . 'test_img2.txt';
157
  try {
158
 
159
  $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
@@ -187,7 +204,7 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
187
  }
188
 
189
  if (empty($imageURL)){
190
- $imageURL = Mage::getStoreConfig('web/unsecure/base_url').'/skin/frontend/base/default/images/catalog/product/placeholder/image.jpg';
191
  return $imageURL;
192
  }
193
  return $imageURL;
@@ -197,6 +214,26 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
197
  }
198
  }
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  /**
201
  * Singletong for DB connection
202
  */
@@ -205,68 +242,82 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
205
  return $this->connection;
206
  }
207
  $this->connection = Mage::getSingleton('core/resource')->getConnection('core_read');
 
208
  return $this->connection;
209
  }
210
 
211
- /**
212
  * Upload Data file to DP
213
  */
214
  private function loadFileToDb(){
215
- $connection = $this->getDbConnection();
216
  $testfile = Mage::getBaseDir('var') . $this->_connectorDir . 'newt.txt';
217
  $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
218
  $is_info_file = strpos($this->_productFile,'prodid_d.txt');
 
219
  try {
220
- $connection->beginTransaction();
221
  $fileHandler = fopen($this->XMLfile, "r");
222
  if ($fileHandler) {
223
  if (!$is_info_file) {
224
- $connection->query("DROP TABLE IF EXISTS `".$tableName."_temp`");
225
- $connection->query("
226
- CREATE TABLE `".$tableName."_temp` (
227
- `prod_id` varchar(255) NOT NULL,
228
- `supplier_id` int(11) DEFAULT NULL,
229
- `prod_name` varchar(255) DEFAULT NULL,
230
- `prod_img` varchar(255) DEFAULT NULL,
231
- KEY `PRODUCT_MPN` (`prod_id`),
232
- KEY `supplier_id` (`supplier_id`)
233
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
234
- ");
235
  } else {
236
- $connection->query("DROP TABLE IF EXISTS `".$tableName."_products`");
237
- $connection->query("
238
- CREATE TABLE `".$tableName."_products` (
239
- `prod_id` varchar(255) NOT NULL,
240
- `prod_title` varchar(255) DEFAULT NULL,
241
- `prod_ean` varchar(255) NOT NULL,
242
- KEY `prod_id` (`prod_id`),
243
- KEY `PRODUCT_EAN` (`prod_ean`)
244
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
245
- ");
246
  }
247
  if (!$is_info_file) {
248
- $csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp.csv';
249
  } else {
250
- $csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp_prod.csv';
251
  }
252
 
253
- $csvFile = str_replace("\\", "\\\\", $csvFile);
254
  $csvFileRes = fopen($csvFile, "w+");
255
-
 
 
 
256
  while (!feof($fileHandler)) {
257
  $row = fgets($fileHandler);
258
  $oneLine = explode("\t", $row);
259
 
260
  if ($oneLine[0]!= 'product_id' && $oneLine[0]!= '' && !$is_info_file) {
 
261
  try{
262
 
263
- $prod_id = (!empty($oneLine[1])) ? $oneLine[1] : '';
264
- $prod_img = (!empty($oneLine[6])) ? $oneLine[6] : $oneLine[5];
265
- $prod_name = (!empty($oneLine[12])) ? $oneLine[12] : '';
266
- $supplier_id = (!empty($oneLine[4])) ? $oneLine[4] : '';
267
- $line = "$prod_id\t$supplier_id\t$prod_name\t$prod_img\n";
268
 
269
- fwrite($csvFileRes, $line);
 
 
 
 
 
 
 
 
 
270
  }catch(Exception $e){
271
  Mage::log("connector issue: {$e->getMessage()}");
272
  }
@@ -283,51 +334,42 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
283
  $prod_ean = !empty($eans[0]) ? $eans[0] : '';
284
  }
285
  }
286
- $prod_id = (!empty($oneLine[0])) ? str_replace("\t",'',$oneLine[0]) : '';
287
- $brand = (!empty($oneLine3)) ? str_replace("\t",'',$oneLine[3]. '|') : '';
288
- $model = (!empty($oneLine12)) ? str_replace("\t",'',$oneLine[12].'|') : '';
289
- $family = (!empty($oneLine21)) ? preg_replace("/\s+/", "",$oneLine[21].'|') : '';
290
- $line = "$prod_id\t$brand$family$model\t$prod_ean\n";
291
- fwrite($csvFileRes, $line);
 
 
 
 
 
 
 
 
292
  }catch(Exception $e){
293
  Mage::log("connector issue: {$e->getMessage()}");
294
  }
295
  }
 
296
  }
297
-
298
- $connection->commit();
299
- $config = Mage::getConfig()->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
300
- $sql_file = Mage::getBaseDir('var') . $this->_connectorDir . 'test.sql';
 
 
 
 
 
 
 
 
301
 
302
- $hostname = $config->host;
303
- $user = $config->username;
304
- $password = $config->password;
305
- $dbname = $config->dbname;
306
-
307
- // write csv file into temp table
308
- if (!$is_info_file) {
309
- $sql = 'LOAD DATA LOCAL INFILE "'.$csvFile.'" INTO TABLE '.$tableName.'_temp ( prod_id, supplier_id, prod_name, prod_img );';
310
- file_put_contents($sql_file,$sql);
311
- $res = system("mysql -u$user -p$password -h$hostname $dbname < \"$sql_file\" ");
312
- file_put_contents($testfile, "mysql -u$user -p$password -h$hostname $dbname < $sql_file",FILE_APPEND);
313
- //$connection->query('LOAD DATA LOCAL INFILE "'.$csvFile.'" INTO TABLE '.$tableName.'_temp ( prod_id, supplier_id, prod_name, prod_img )');
314
- $connection->query("DROP TABLE IF EXISTS `".$tableName."_old`");
315
- $connection->query("rename table `".$tableName."` to `".$tableName."_old`, `".$tableName."_temp` to ".$tableName);
316
- $connection->commit();
317
- fclose($fileHandler);
318
- unlink($csvFile);
319
- } else {
320
- $sql = 'LOAD DATA LOCAL INFILE "'.$csvFile.'" INTO TABLE '.$tableName.'_products ( prod_id, prod_title,prod_ean );';
321
- file_put_contents($sql_file,$sql);
322
- $res = system("mysql -u$user -p$password -h$hostname $dbname < \"$sql_file\" ");
323
- file_put_contents($testfile, "mysql -u$user -p$password -h$hostname $dbname < $sql_file", FILE_APPEND);
324
- $connection->commit();
325
- fclose($fileHandler);
326
- unlink($csvFile);
327
- }
328
  }
329
  } catch (Exception $e) {
330
- $connection->rollBack();
331
  throw new Exception("Icecat Import Terminated: {$e->getMessage()}");
332
  }
333
  }
@@ -373,7 +415,9 @@ file_put_contents($testfile, 'here obs',FILE_APPEND);
373
  $webClient->setAuth($userName, $userPass, Zend_Http_CLient::AUTH_BASIC);
374
  $response = $webClient->request('GET');
375
  if ($response->isError()){
376
- throw new Exception('<br>ERROR Occured.<br>Response Status: '.$response->getStatus()."<br>Response Message: ".$response->getMessage());
 
 
377
  }
378
  }
379
  catch (Exception $e) {
6
  *
7
  */
8
  class Bintime_Icecatimport_Model_Observer
9
+ {
10
+ /**
11
+ * Our process ID.
12
+ */
13
+ private $process_id = 'bintime_icecat';
14
+ private $indexProcess;
15
+
16
+
17
  private $errorMessage;
18
  private $connection;
19
+ private $test_connection;
20
  private $freeExportURLs = 'http://data.icecat.biz/export/freeurls/export_urls_rich.txt.gz';
21
  private $fullExportURLs = 'http://data.icecat.biz/export/export_urls_rich.txt.gz';
22
  private $productinfoUrL = 'http://data.icecat.biz/prodid/prodid_d.txt.gz';
33
  * root method for uploading images to DB
34
  */
35
  public function load(){
36
+
37
+
38
  $loadUrl = $this->getLoadURL();
39
  ini_set('max_execution_time', 0);
40
  try {
41
+ $this->indexProcess = new Mage_Index_Model_Process();
42
+ $this->indexProcess->setId($this->process_id);
43
+
44
+ if ($this->indexProcess->isLocked()) {
45
+ throw new Exception('Error! Another icecat module cron process is running!');
46
+ }
47
+
48
+ $this->indexProcess->lockAndBlock();
49
+
50
  $this->_productFile = $this->_prepareFile(basename($loadUrl));
51
  $this->_supplierFile = $this->_prepareFile(basename($this->_supplierMappingUrl));
52
  echo "Data file downloading started <br>";
75
  $this->loadFileToDb();
76
 
77
  echo " Product Data File Processed Succesfully<br>";
78
+ $this->indexProcess->unlock();
79
  } catch( Exception $e) {
80
  echo $e->getMessage();
81
  Mage::log($e->getMessage());
169
  * @param string $productManufacturer
170
  */
171
  public function getImageURL($productSku, $productManufacturer, $productId = ''){
172
+
173
  $connection = $this->getDbConnection();
 
174
  try {
175
 
176
  $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
204
  }
205
 
206
  if (empty($imageURL)){
207
+ $this->errorMessage = "Given product id is not present in database";
208
  return $imageURL;
209
  }
210
  return $imageURL;
214
  }
215
  }
216
 
217
+ /**
218
+ * Singletong for TestDB connection
219
+ */
220
+ private function getTestDbConnection(){
221
+ if ($this->test_connection){
222
+ return $this->test_connection;
223
+ }
224
+ //$this->connection = Mage::getSingleton('core/resource')->getConnection('core_read');
225
+ $config = Mage::getConfig()->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
226
+ $hostname = $config->host;
227
+ $user = $config->username;
228
+ $password = $config->password;
229
+ $dbname = $config->dbname;
230
+
231
+ $this->test_connection = @mysql_connect($hostname, $user, $password, true, 128);
232
+ mysql_select_db($dbname,$this->test_connection);
233
+
234
+ return $this->test_connection;
235
+ }
236
+
237
  /**
238
  * Singletong for DB connection
239
  */
242
  return $this->connection;
243
  }
244
  $this->connection = Mage::getSingleton('core/resource')->getConnection('core_read');
245
+
246
  return $this->connection;
247
  }
248
 
249
+ /**
250
  * Upload Data file to DP
251
  */
252
  private function loadFileToDb(){
253
+ $connection = $this->getTestDbConnection();
254
  $testfile = Mage::getBaseDir('var') . $this->_connectorDir . 'newt.txt';
255
  $tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
256
  $is_info_file = strpos($this->_productFile,'prodid_d.txt');
257
+ $max_counter = 8000;
258
  try {
259
+ mysql_query("START TRANSACTION",$connection);
260
  $fileHandler = fopen($this->XMLfile, "r");
261
  if ($fileHandler) {
262
  if (!$is_info_file) {
263
+ mysql_query("DROP TABLE IF EXISTS `".$tableName."_temp`",$connection);
264
+ mysql_query("CREATE TABLE `".$tableName."_temp` (
265
+ `prod_id` varchar(255) NOT NULL,
266
+ `supplier_id` int(11) DEFAULT NULL,
267
+ `prod_name` varchar(255) DEFAULT NULL,
268
+ `prod_img` varchar(255) DEFAULT NULL,
269
+ KEY `PRODUCT_MPN` (`prod_id`),
270
+ KEY `supplier_id` (`supplier_id`)
271
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
272
+ ",$connection);
273
+
274
  } else {
275
+
276
+ mysql_query("DROP TABLE IF EXISTS `".$tableName."_products`",$connection);
277
+ mysql_query("CREATE TABLE `".$tableName."_products` (
278
+ `prod_id` varchar(255) NOT NULL,
279
+ `prod_title` varchar(255) DEFAULT NULL,
280
+ `prod_ean` varchar(255) NOT NULL,
281
+ KEY `prod_id` (`prod_id`),
282
+ KEY `PRODUCT_EAN` (`prod_ean`)
283
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
284
+ ",$connection);
285
  }
286
  if (!$is_info_file) {
287
+ $csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp.csv';
288
  } else {
289
+ $csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp_prod.csv';
290
  }
291
 
292
+ $csvFile = str_replace("\\", "\\\\", $csvFile);
293
  $csvFileRes = fopen($csvFile, "w+");
294
+ $counter = 0;
295
+ $sql = "";
296
+ $test_sql = "";
297
+
298
  while (!feof($fileHandler)) {
299
  $row = fgets($fileHandler);
300
  $oneLine = explode("\t", $row);
301
 
302
  if ($oneLine[0]!= 'product_id' && $oneLine[0]!= '' && !$is_info_file) {
303
+
304
  try{
305
 
306
+ $prod_id = (!empty($oneLine[1])) ? addslashes($oneLine[1]) : '';
307
+ $prod_img = (!empty($oneLine[6])) ? addslashes($oneLine[6]) : addslashes($oneLine[5]);
308
+ $prod_name = (!empty($oneLine[12])) ? addslashes($oneLine[12]) : '';
309
+ $supplier_id = (!empty($oneLine[4])) ? addslashes($oneLine[4]) : '';
 
310
 
311
+ if ($counter == 1 ) {
312
+ $sql = " INSERT INTO ".$tableName."_temp ( prod_id, supplier_id, prod_name, prod_img ) VALUES(\"$prod_id\",\"$supplier_id\",\"$prod_name\",\"$prod_img\") ";
313
+ } else if ($counter % $max_counter == 0) {
314
+
315
+ mysql_query($sql,$connection);
316
+ $sql = " INSERT INTO ".$tableName."_temp ( prod_id, supplier_id, prod_name, prod_img ) VALUES(\"$prod_id\",\"$supplier_id\",\"$prod_name\",\"$prod_img\") ";
317
+ } else {
318
+ $sql .= " , (\"$prod_id\",\"$supplier_id\",\"$prod_name\",\"$prod_img\") ";
319
+ }
320
+
321
  }catch(Exception $e){
322
  Mage::log("connector issue: {$e->getMessage()}");
323
  }
334
  $prod_ean = !empty($eans[0]) ? $eans[0] : '';
335
  }
336
  }
337
+ $prod_id = (!empty($oneLine[0])) ? addslashes(str_replace("\t",'',$oneLine[0])) : '';
338
+ $brand = (!empty($oneLine3)) ? addslashes(str_replace("\t",'',$oneLine[3]. '|')) : '';
339
+ $model = (!empty($oneLine12)) ? addslashes(str_replace("\t",'',$oneLine[12].'|')) : '';
340
+ $family = (!empty($oneLine21)) ? addslashes(preg_replace("/\s+/", "",$oneLine[21].'|')) : '';
341
+
342
+ if ($counter == 1) {
343
+ $sql = " INSERT INTO ".$tableName."_products ( prod_id, prod_title,prod_ean ) VALUES(\"$prod_id\",\"$brand$family$model\",\"$prod_ean\") ";
344
+ } else if ($counter % $max_counter == 0) {
345
+
346
+ mysql_query($sql,$connection);
347
+ $sql = " INSERT INTO ".$tableName."_products ( prod_id, prod_title,prod_ean ) VALUES(\"$prod_id\",\"$brand$family$model\",\"$prod_ean\") ";
348
+ } else {
349
+ $sql .= " , (\"$prod_id\",\"$brand$family$model\",\"$prod_ean\") ";
350
+ }
351
  }catch(Exception $e){
352
  Mage::log("connector issue: {$e->getMessage()}");
353
  }
354
  }
355
+ $counter++;
356
  }
357
+ if (!$is_info_file) {
358
+ mysql_query($sql,$connection);
359
+ mysql_query("DROP TABLE IF EXISTS `".$tableName."_old`",$connection);
360
+ mysql_query("rename table `".$tableName."` to `".$tableName."_old`, `".$tableName."_temp` to ".$tableName,$connection);
361
+ mysql_query("COMMIT",$connection);
362
+ } else{
363
+ mysql_query($sql,$connection);
364
+ mysql_query("COMMIT",$connection);
365
+ }
366
+
367
+ fclose($fileHandler);
368
+
369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  }
371
  } catch (Exception $e) {
372
+ mysql_query("ROLLBACK",$connection);
373
  throw new Exception("Icecat Import Terminated: {$e->getMessage()}");
374
  }
375
  }
415
  $webClient->setAuth($userName, $userPass, Zend_Http_CLient::AUTH_BASIC);
416
  $response = $webClient->request('GET');
417
  if ($response->isError()){
418
+ throw new Exception('<br>ERROR Occured.<br>Response Status: '.$response->getStatus()."<br>Response Message: ".$response->getMessage().
419
+ "<br>Please, make sure that you added correct icecat username and password to <strong>Icecat Live!</strong> configuration <br>
420
+ and you have your webshop's correct IP in <strong>Allowed IP addresses</strong> field in your icecat account.");
421
  }
422
  }
423
  catch (Exception $e) {
app/code/local/Bintime/Icecatimport/Model/Output.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
3
+ {
4
+
5
+ private $iceCatModel;
6
+ private $error = false;
7
+ private $systemError;
8
+
9
+ /**
10
+ * @var isFirstTime spike for getProductDescription that is called many times from template
11
+ */
12
+ private $isFirstTime = true;
13
+
14
+ /**
15
+ * Prepare product attribute html output
16
+ *
17
+ * @param Mage_Catalog_Model_Product $product
18
+ * @param string $attributeHtml
19
+ * @param string $attributeName
20
+ * @return string
21
+ */
22
+ public function productAttribute($product, $attributeHtml, $attributeName){
23
+
24
+ $productId = $product->getId();
25
+
26
+ if (!mage::registry('product')) {
27
+ Mage::register('product', $product);
28
+ Mage::register('current_product', $product);
29
+ // return parent::productAttribute($product, $attributeHtml, $attributeName);
30
+ }
31
+
32
+ if ($attributeName == 'image') {
33
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
34
+ }
35
+
36
+ $productDescriptionPriority = Mage::getStoreConfig('icecat_root/icecat/descript_priority');
37
+ $productShortDescrPriority = Mage::getStoreConfig('icecat_root/icecat/shortdescr_priority');
38
+ $productNamePriority = Mage::getStoreConfig('icecat_root/icecat/name_priority');
39
+
40
+
41
+
42
+ $dbDescriptionPriority = false;
43
+ $dbShortDescriptionPriority = false;
44
+ $current_page = Mage::app()->getFrontController()->getRequest()->getControllerName();
45
+ if ($productDescriptionPriority == 'Db' && $attributeName == 'description') {
46
+ $dbDescriptionPriority = true;
47
+ }
48
+ if ($productShortDescrPriority == 'Db' && $attributeName == 'short_description') {
49
+ $dbShortDescriptionPriority = true;
50
+ }
51
+
52
+ if ($current_page == 'product') {
53
+ $bin_prod = new Bintime_Icecatimport_Model_Catalog_Product();
54
+ if ($attributeName == 'description' || $attributeName == 'short_description') {
55
+ $descr = $bin_prod->checkIcecatProdDescription($productId,$attributeName);
56
+ }
57
+ }
58
+ $prod_source = Bintime_Icecatimport_Model_Catalog_Product::$_product_source;
59
+
60
+ if( $prod_source == 'DB' && empty($descr) ) {
61
+ $dbDescriptionPriority = true;
62
+ $dbShortDescriptionPriority = true;
63
+ }
64
+
65
+ if ($dbShortDescriptionPriority || ($current_page != 'product'
66
+ && $prod_source != 'DB' ) && $attributeName != 'name') {
67
+ if ($attributeName == 'short_description') {
68
+ $attributeHtml = $product->getData('short_description');
69
+ }
70
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
71
+ }
72
+ $this->iceCatModel = Mage::getSingleton('icecatimport/import');
73
+
74
+ if ($this->isFirstTime){
75
+ $helper = Mage::helper('icecatimport/getdata');
76
+ $helper->getProductDescription($product);
77
+
78
+ if ($helper->hasError() && $attributeName != 'name') {
79
+ $this->error = true;
80
+ }
81
+ $this->isFirstTime = false;
82
+ }
83
+
84
+ if ($this->error){
85
+ if ($attributeName != 'description' && $attributeName != 'short_description') {
86
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
87
+ } else {
88
+ return '';
89
+ }
90
+
91
+ }
92
+
93
+ $id = $product->getData('entity_id');
94
+
95
+ if ($attributeName == 'name' && $productNamePriority != 'Db'){
96
+ //if we on product page then mage::registry('product') exist
97
+ if ($product->getId() == $this->iceCatModel->entityId && $name = $this->iceCatModel->getProductName()) {
98
+ return $name;
99
+ } else if(!empty($descr)) {
100
+ return $descr;
101
+ }
102
+ $manufacturerId = Mage::getStoreConfig('icecat_root/icecat/manufacturer');
103
+ $mpn = Mage::getStoreConfig('icecat_root/icecat/sku_field');
104
+ $collection = Mage::getResourceModel('catalog/product_collection');
105
+ $collection->addAttributeToSelect($manufacturerId)->addAttributeToSelect($mpn)
106
+ ->addAttributeToSelect('name')
107
+ ->addAttributeToFilter('entity_id', array('eq' => $id));
108
+ $product = $collection->getFirstItem() ;
109
+ return $product->getName();
110
+ }
111
+
112
+ if ($attributeName == 'short_description' && !$dbShortDescriptionPriority ) {
113
+ $icecat_descr = $this->iceCatModel->getShortProductDescription();
114
+ if (!empty($descr)) {
115
+ return $descr;
116
+ } else if(!empty($icecat_descr)) {
117
+ return $icecat_descr;
118
+ } else {
119
+ $attributeHtml = $product->getData('short_description');
120
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
121
+ }
122
+ }
123
+ if ($attributeName == 'description' && !$dbDescriptionPriority) {
124
+ $icecat_full_descr = $this->iceCatModel->getFullProductDescription();
125
+ if (!empty($icecat_full_descr)) {
126
+ return str_replace("\\n", "<br>",$icecat_full_descr);
127
+ } else {
128
+ $attributeHtml = $product->getData('description');
129
+ }
130
+ }
131
+ return parent::productAttribute($product, $attributeHtml, $attributeName);
132
+ }
133
+
134
+
135
+ public function getWarrantyInfo(){
136
+ return $this->iceCatModel->getWarrantyInfo();
137
+ }
138
+
139
+ public function getShortSummaryDescription(){
140
+ return $this->iceCatModel->getShortSummaryDescription();
141
+ }
142
+
143
+ public function getLongSummaryDescription(){
144
+ return $this->iceCatModel->getLongSummaryDescription();
145
+ }
146
+
147
+ public function getManualPDF(){
148
+ return $this->iceCatModel->getManualPDF();
149
+ }
150
+
151
+ public function getPDF(){
152
+ return $this->iceCatModel->getPDF();
153
+ }
154
+
155
+ public function getIceCatMedia(){
156
+ $media = (array)$this->iceCatModel->getIceCatMedia();
157
+ return (array_key_exists('@attributes', $media)) ? $media['@attributes'] : array();
158
+ }
159
+ }
160
+ ?>
app/code/local/Bintime/Icecatimport/Model/System/Config/Imagepriority.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_Model_System_Config_Imagepriority
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'Icecat' => 'From Icecat',
8
+ 'Db' => 'From Database'
9
+ );
10
+
11
+ }
12
+ }
13
+ ?>
app/code/local/Bintime/Icecatimport/Model/System/Config/Namepriority.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_Model_System_Config_Namepriority
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'Icecat' => 'From Icecat',
8
+ 'Db' => 'From Database'
9
+ );
10
+
11
+ }
12
+ }
13
+ ?>
app/code/local/Bintime/Icecatimport/Model/System/Config/Productpriority.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_Model_System_Config_Productpriority
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'Show' => 'Show all products',
8
+ 'Hide' => 'Hide products not from Icecat'
9
+ );
10
+
11
+ }
12
+ }
13
+ ?>
app/code/local/Bintime/Icecatimport/Model/System/Config/Shortdescrpriority.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Bintime_Icecatimport_Model_System_Config_Shortdescrpriority
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'Icecat' => 'From Icecat',
8
+ 'Db' => 'From Database'
9
+ );
10
+
11
+ }
12
+ }
13
+ ?>
app/code/local/Bintime/Icecatimport/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Bintime_Icecatimport>
5
- <version>0.1.1</version>
6
  </Bintime_Icecatimport>
7
  </modules>
8
  <global>
@@ -18,15 +18,22 @@
18
  </catalog>
19
  </helpers>
20
  <blocks>
 
 
 
21
  <catalog>
22
  <rewrite>
23
- <product_view_attributes>Bintime_Icecatimport_Block_Attributes</product_view_attributes>
24
  <product_view_media>Bintime_Icecatimport_Block_Media</product_view_media>
25
  <product_list_related>Bintime_Icecatimport_Block_Related</product_list_related>
26
  <product_list_upsell>Bintime_Icecatimport_Block_Upsell</product_list_upsell>
27
- </rewrite>
28
- </catalog>
29
-
 
 
 
 
 
30
  </blocks>
31
  <models>
32
  <icecatimport>
@@ -89,9 +96,9 @@
89
  </routers>
90
  <layout>
91
  <updates>
92
- <icecatimport>
93
- <file>icecatimport.xml</file>
94
- </icecatimport>
95
  </updates>
96
  </layout>
97
  <translate>
@@ -139,7 +146,7 @@
139
  <crontab>
140
  <jobs>
141
  <icecatimport>
142
- <schedule><cron_expr>19 15 * * *</cron_expr></schedule>
143
  <run><model>icecatimport/observer::load</model></run>
144
  </icecatimport>
145
  </jobs>
2
  <config>
3
  <modules>
4
  <Bintime_Icecatimport>
5
+ <version>1.5.0</version>
6
  </Bintime_Icecatimport>
7
  </modules>
8
  <global>
18
  </catalog>
19
  </helpers>
20
  <blocks>
21
+ <Bintime_Icecatimport>
22
+ <class>Bintime_Icecatimport_Block</class>
23
+ </Bintime_Icecatimport>
24
  <catalog>
25
  <rewrite>
 
26
  <product_view_media>Bintime_Icecatimport_Block_Media</product_view_media>
27
  <product_list_related>Bintime_Icecatimport_Block_Related</product_list_related>
28
  <product_list_upsell>Bintime_Icecatimport_Block_Upsell</product_list_upsell>
29
+ <product_list_toolbar>Bintime_Icecatimport_Block_Product_List_Toolbar</product_list_toolbar>
30
+ </rewrite>
31
+ </catalog>
32
+ <catalogsearch>
33
+ <rewrite>
34
+ <result>Bintime_Icecatimport_CatalogSearch_Block_Result</result>
35
+ </rewrite>
36
+ </catalogsearch>
37
  </blocks>
38
  <models>
39
  <icecatimport>
96
  </routers>
97
  <layout>
98
  <updates>
99
+ <IcecatGroupAttributes>
100
+ <file>IcecatGroupAttributes.xml</file>
101
+ </IcecatGroupAttributes>
102
  </updates>
103
  </layout>
104
  <translate>
146
  <crontab>
147
  <jobs>
148
  <icecatimport>
149
+ <schedule><cron_expr>0 0 * * 1</cron_expr></schedule>
150
  <run><model>icecatimport/observer::load</model></run>
151
  </icecatimport>
152
  </jobs>
app/code/local/Bintime/Icecatimport/etc/system.xml CHANGED
@@ -89,6 +89,42 @@
89
  <show_in_website>1</show_in_website>
90
  <show_in_store>1</show_in_store>
91
  </descript_priority>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  </fields>
93
  </icecat>
94
  </groups>
89
  <show_in_website>1</show_in_website>
90
  <show_in_store>1</show_in_store>
91
  </descript_priority>
92
+ <shortdescr_priority translate="label">
93
+ <label>Use Short description from </label>
94
+ <frontend_type>select</frontend_type>
95
+ <source_model>icecatimport/system_config_shortdescrpriority</source_model>
96
+ <sort_order>70</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ </shortdescr_priority>
101
+ <name_priority translate="label">
102
+ <label>Use Product Name from </label>
103
+ <frontend_type>select</frontend_type>
104
+ <source_model>icecatimport/system_config_namepriority</source_model>
105
+ <sort_order>70</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ </name_priority>
110
+ <image_priority translate="label">
111
+ <label>Use Product Image from </label>
112
+ <frontend_type>select</frontend_type>
113
+ <source_model>icecatimport/system_config_imagepriority</source_model>
114
+ <sort_order>70</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ </image_priority>
119
+ <product_priority translate="label">
120
+ <label>Show/Hide products not presented at icecat</label>
121
+ <frontend_type>select</frontend_type>
122
+ <source_model>icecatimport/system_config_productpriority</source_model>
123
+ <sort_order>70</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ </product_priority>
128
  </fields>
129
  </icecat>
130
  </groups>
app/design/frontend/base/default/layout/IcecatGroupAttributes.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <layout version="0.1.0">
2
+
3
+ <catalog_product_view>
4
+
5
+ <reference name="content">
6
+ <block name="product.info" >
7
+
8
+ <block type="Bintime_Icecatimport/Attributes" name="product.attributes" as="additional" template="icecatlive/attributesasgroup/groupview.phtml">
9
+ <action method="addToParentGroup"><group>detailed_info</group></action>
10
+ </block>
11
+
12
+ </block>
13
+ </reference>
14
+
15
+ </catalog_product_view>
16
+
17
+ </layout>
app/design/frontend/base/default/template/icecatlive/attributesasgroup/groupview.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_helper = $this->helper('catalog/output');
3
+ $_product = $this->getProduct()
4
+ ?>
5
+ <?php if($_additionalgroup = $this->getAdditionalData()): ?>
6
+ <div class="box-collateral box-additional">
7
+ <h2><?php echo $this->__('Additional Information') ?></h2>
8
+
9
+ <?php $i=0; foreach ($_additionalgroup as $_additional): $i++; ?>
10
+ <h3><?php echo $this->__( $_additional['title'] )?></h3>
11
+ <table class="data-table" id="product-attribute-specs-table-<?php echo $i?>">
12
+ <col width="25%" />
13
+ <col />
14
+ <tbody>
15
+ <?php foreach ($_additional['items'] as $_data): ?>
16
+ <tr>
17
+ <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
18
+ <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
19
+ </tr>
20
+ <?php endforeach; ?>
21
+ </tbody>
22
+ </table>
23
+ <script type="text/javascript">decorateTable('product-attribute-specs-table-<?php echo $i?>')</script>
24
+ <?php endforeach; ?>
25
+
26
+ </div>
27
+ <?php endif;?>
package.xml CHANGED
@@ -1,30 +1,38 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IcecatLive</name>
4
- <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>ICEcat to Magento Open Source Connector</summary>
10
  <description>ICEcat to Magento Open Source Connector - rich content in your magento shop</description>
11
- <notes> - Added mapping by EAN/UPC codes&#xD;
12
- - Added support of Multilanguage stores&#xD;
13
- - Added new setting Description&#xD;
14
- - Added loading products description from DB when icecat info is missing and config setting product descr source is set to icecat &#xD;
15
- - Added saving icecat images to server and display from there &#xD;
16
- - Added saving product title to db from file and display it on list page &#xD;
17
- - Fixed problems with Icecat names&#xD;
18
- - Fixed problems with images on product listing/shopping cart.&#xD;
19
- - Fixed problems with correct displaying attributes on product detail page&#xD;
20
- - Fixed problems with description on product detail page &#xD;
21
- - Fixed product info in breadcrumbs &#xD;
22
- - Fixed problems with loading icecat data for each product on product listing page &#xD;
23
- </notes>
 
 
 
 
 
 
 
 
24
  <authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
25
- <date>2013-07-01</date>
26
- <time>10:45:01</time>
27
- <contents><target name="magelocal"><dir name="Bintime"><dir name="Icecatimport"><dir name="Block"><file name="Attributes.php" hash="ae93e0a964e8880e5b65fb5d08f1edf9"/><file name="Media.php" hash="a71e447a139b851da50937bccaf8bd37"/><file name="Related.php" hash="7ca2ad6520f2644ad1302c02d1cd6853"/><file name="Upsell.php" hash="f7a79cee4cb7ecb679f65e7ec7a487c4"/></dir><dir name="controllers"><file name="ImageController.php" hash="cdf4984c268346088729831b7abdf026"/></dir><dir name="etc"><file name="config.xml" hash="13d5b3c94451f13119c90a8added2374"/><file name="system.xml" hash="42faa23748e785e3b99c17f15d32f67e"/></dir><dir name="Helper"><dir name="Catalog"><file name="Image.php" hash="4952fd82b7fb4cb68498ec7655a990ee"/></dir><file name="Getdata.php" hash="6e582c84a4f65071fbc6daf6b4e03de5"/><file name="Image.php" hash="62a1ab4c2b773f6aafc877a0f43689bd"/><file name="Output.php" hash="66a35fb37504ff30a2188b34941d991e"/></dir><dir name="Model"><dir name="Catalog"><file name="Category.php" hash="21abeb7a7c2c85db8ce4d2f4ed203f50"/><file name="Product.php" hash="e94919ad720fccd16c061e31ac26d05d"/><file name="Search.php" hash="99c7eb706e67e01ea8167ebe88fe72d9"/></dir><dir name="System"><dir name="Config"><file name="Attributes.php" hash="23284e0d38677b4544fc87642a6bc8b5"/><file name="LanguageList.xml" hash="391ef56fab212879709780df5a7710e7"/><file name="Locales.php" hash="b8c699fa2a6f657b6d52d86e656872cc"/><file name="Subscription.php" hash="62168986f7a4eb3f10d38ac627aa6510"/><file name="Descriptionpriority.php" hash="e32f7b5893ded762a45c742d4e6944fd"/></dir></dir><file name="Imagescollection.php" hash="718b575ef9472f85c323fa40f80bbd05"/><file name="Import.php" hash="8043d30eebe86ea03c917ef8f38e2a65"/><file name="Observer.php" hash="99795f94b4dd8c1f9dd1bb5df8ad0337"/><file name="Relatedcollection.php" hash="2ddf62c43a66c3fd70bf651d0078dbc1"/></dir><dir name="sql"><dir name="icecatimport_setup"><file name="mysql4-install-0.1.0.php" hash="08f5875b240c2f229b95194b6335f9a6"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="c0581c5b00420492714bd7e3cc66cb6d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Icecatimport.xml" hash="daf681aae3e710568d210313816a9d5f"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
30
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>IcecatLive</name>
4
+ <version>1.5.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v.3</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>ICEcat to Magento Open Source Connector</summary>
10
  <description>ICEcat to Magento Open Source Connector - rich content in your magento shop</description>
11
+ <notes>- Added mapping by EAN/UPC codes&amp;#xD;&#xD;
12
+ - Added support of Multilanguage stores&amp;#xD;&#xD;
13
+ - Added new setting Description Priority&amp;#xD;&#xD;
14
+ - Added new setting Short Description Priority&amp;#xD;&#xD;
15
+ - Added new setting Product Name Priority&amp;#xD;&#xD;
16
+ - Added new setting Product Images Priority&amp;#xD;&#xD;
17
+ - Added new setting Product Priority - display or hide products not from icecat &amp;#xD;&#xD;
18
+ - Added display additional attributes by groups on product's page &amp;#xD;&#xD;
19
+ - Added loading products description from DB when icecat info is missing and config setting product descr source is set to icecat &amp;#xD; &#xD;
20
+ - Added saving icecat images to server and display from there &amp;#xD; &#xD;
21
+ - Added saving product title to db from file and display it on list page &amp;#xD; &#xD;
22
+ - Added cron process lock - only one icecat cron process can be running at a time &amp;#xD; &#xD;
23
+ - LOAD LOCAL replaced with insert queries &amp;#xD;&#xD;
24
+ - Removed logo images from product images gallery &amp;#xD;&#xD;
25
+ - Fixed problems with Icecat names&amp;#xD;&#xD;
26
+ - Fixed problems with images on product listing/shopping cart.&amp;#xD;&#xD;
27
+ - Fixed problems with correct displaying attributes on product detail page&amp;#xD;&#xD;
28
+ - Fixed problems with description on product detail page &amp;#xD;&#xD;
29
+ - Fixed product info in breadcrumbs &amp;#xD;&#xD;
30
+ - Fixed problems with loading icecat data for each product on product listing page &amp;#xD;
31
+ - Fixed problems with product images and gallery&amp;#xD;</notes>
32
  <authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
33
+ <date>2013-07-18</date>
34
+ <time>16:03:03</time>
35
+ <contents><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="IcecatGroupAttributes.xml" hash="61719bd9a27b0ef670e22919b755f65d"/></dir><dir name="template"><dir name="icecatlive"><dir name="attributesasgroup"><file name="groupview.phtml" hash="6c37ec003f0dded289adc8b778918cc3"/></dir></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Bintime"><dir name="Icecatimport"><dir name="CatalogSearch"><dir name="Block"><file name="Result.php" hash="ae81e0a964e8990e5b65fb1d08f1edf9"/></dir></dir><dir name="Block"><dir name="Product"><dir name="List"><file name="Toolbar.php" hash="ae82e0a964e8990e5b35fb1d08f1edf9"/></dir></dir><file name="Attributes.php" hash="ae93e0a964e8880e5b65fb5d08f1edf9"/><file name="Media.php" hash="1ada42f85cff27882bb181995ffc5579"/><file name="Related.php" hash="7ca2ad6520f2644ad1302c02d1cd6853"/><file name="Upsell.php" hash="f7a79cee4cb7ecb679f65e7ec7a487c4"/></dir><dir name="Helper"><dir name="Catalog"><file name="Image.php" hash="93e3d8339089349f1d7d0f2589e5399f"/></dir><file name="Getdata.php" hash="0bb4c9c6d89f7d233aea87e4e2cb0d2a"/><file name="Image.php" hash="b55ed2b8ea0b05f07f208370a285300e"/><file name="Output.php" hash="e75ca556697178724135a33b7e58a8c9"/></dir><dir name="Model"><dir name="Catalog"><file name="Category.php" hash="21abeb7a7c2c85db8ce4d2f4ed203f50"/><file name="Product.php" hash="5ebed9c1318ae03acd671e6147de878c"/><file name="Search.php" hash="99c7eb706e67e01ea8167ebe88fe72d9"/></dir><file name="Imagescollection.php" hash="718b575ef9472f85c323fa40f80bbd05"/><file name="Import.php" hash="30f17bd2d367f3a1104a1e6092753ddf"/><file name="Observer.php" hash="bf8f785e791e94dd870f6d309701110a"/><file name="Relatedcollection.php" hash="2ddf62c43a66c3fd70bf651d0078dbc1"/><dir name="System"><dir name="Config"><file name="Attributes.php" hash="23284e0d38677b4544fc87642a6bc8b5"/><file name="Descriptionpriority.php" hash="e32f7b5893ded762a45c742d4e6944fd"/><file name="Imagepriority.php" hash="d3e623e8c1523f1edd555bea43f9950d"/><file name="LanguageList.xml" hash="391ef56fab212879709780df5a7710e7"/><file name="Locales.php" hash="b8c699fa2a6f657b6d52d86e656872cc"/><file name="Namepriority.php" hash="8c24c8dffd826e7b8259546d61f33ea7"/><file name="Productpriority.php" hash="8c24c2dffd826e7b8259557d61f33ea7"/><file name="Shortdescrpriority.php" hash="4afecd1d5046e0e7813364c26ad5e857"/><file name="Subscription.php" hash="62168986f7a4eb3f10d38ac627aa6510"/></dir></dir></dir><dir name="controllers"><file name="ImageController.php" hash="cdf4984c268346088729831b7abdf026"/></dir><dir name="etc"><file name="config.xml" hash="13d5b3c94451f13119c90a8added2374"/><file name="system.xml" hash="ecc6cbc5084c070ed537c524c89e63f0"/></dir><dir name="sql"><dir name="icecatimport_setup"><file name="mysql4-install-0.1.0.php" hash="08f5875b240c2f229b95194b6335f9a6"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="c0581c5b00420492714bd7e3cc66cb6d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bintime_Icecatimport.xml" hash="daf681aae3e710568d210313816a9d5f"/></dir></target></contents>
36
  <compatible/>
37
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
38
  </package>