Version Notes
- Added mapping by EAN/UPC codes
- Added support of Multilanguage stores
- Added new setting Description
- 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
Download this release
Release Info
Developer | IceShop |
Extension | IcecatLive |
Version | 1.2.0 |
Comparing to | |
See all releases |
Code changes from version 1.1.0 to 1.2.0
- app/code/local/Bintime/Icecatimport/Block/Upsell.php +1 -1
- app/code/local/Bintime/Icecatimport/Helper/Catalog/Image.php +0 -1
- app/code/local/Bintime/Icecatimport/Helper/Getdata.php +148 -185
- app/code/local/Bintime/Icecatimport/Helper/Image.php +35 -43
- app/code/local/Bintime/Icecatimport/Helper/Output.php +102 -94
- app/code/local/Bintime/Icecatimport/Model/Catalog/Product.php +119 -149
- app/code/local/Bintime/Icecatimport/Model/Import.php +341 -317
- app/code/local/Bintime/Icecatimport/Model/Observer.php +273 -295
- app/code/local/Bintime/Icecatimport/Model/System/Config/Descriptionpriority.php +13 -0
- app/code/local/Bintime/Icecatimport/etc/system.xml +94 -76
- app/code/local/Bintime/Icecatimport/sql/icecatimport_setup/mysql4-install-0.1.0.php +1 -0
- package.xml +11 -10
app/code/local/Bintime/Icecatimport/Block/Upsell.php
CHANGED
@@ -38,7 +38,7 @@ class Bintime_Icecatimport_Block_Upsell extends Mage_Catalog_Block_Product_List_
|
|
38 |
'collection' => $this->_itemCollection,
|
39 |
'limit' => $this->getItemLimit()
|
40 |
));
|
41 |
-
|
42 |
foreach ($this->_itemCollection as $product) {
|
43 |
$product->setDoNotUseCategoryId(true);
|
44 |
}
|
38 |
'collection' => $this->_itemCollection,
|
39 |
'limit' => $this->getItemLimit()
|
40 |
));
|
41 |
+
|
42 |
foreach ($this->_itemCollection as $product) {
|
43 |
$product->setDoNotUseCategoryId(true);
|
44 |
}
|
app/code/local/Bintime/Icecatimport/Helper/Catalog/Image.php
CHANGED
@@ -21,7 +21,6 @@ class Bintime_Icecatimport_Helper_Catalog_Image extends Mage_Catalog_Helper_Imag
|
|
21 |
$imageFile = mage::getsingleton('icecatimport/import')->getLowPicUrl();
|
22 |
}
|
23 |
if ($attributeName == 'thumbnail' && $imageFile == null ) {
|
24 |
-
// $imageFile = $product->getData($attributeName);
|
25 |
$imageFile = Mage::helper('icecatimport/image')->getImage($product);
|
26 |
}
|
27 |
|
21 |
$imageFile = mage::getsingleton('icecatimport/import')->getLowPicUrl();
|
22 |
}
|
23 |
if ($attributeName == 'thumbnail' && $imageFile == null ) {
|
|
|
24 |
$imageFile = Mage::helper('icecatimport/image')->getImage($product);
|
25 |
}
|
26 |
|
app/code/local/Bintime/Icecatimport/Helper/Getdata.php
CHANGED
@@ -17,208 +17,171 @@ class Bintime_Icecatimport_Helper_Getdata extends Mage_Core_Helper_Abstract
|
|
17 |
* @return Bintime_Icecatimport_Helper_Getdata
|
18 |
*/
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
$entity_type_id = $this->getEntityTypeId();
|
32 |
-
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
33 |
-
|
34 |
-
|
35 |
-
/* $mpnCode = Mage::getStoreConfig('icecat_root/icecat/sku_field');
|
36 |
-
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
|
37 |
-
->setCodeFilter($mpnCode)
|
38 |
-
->setEntityTypeFilter($entity_type_id)
|
39 |
-
->getFirstItem();
|
40 |
-
|
41 |
-
switch ($attributeInfo->getData('backend_type')) {
|
42 |
-
case 'static':
|
43 |
-
$query = $connection->select()->from('catalog_product_entity', $mpnCode)->where('entity_id = ?', $entityId);
|
44 |
-
break;
|
45 |
-
|
46 |
-
case 'int':
|
47 |
-
//echo "int";
|
48 |
-
break;
|
49 |
-
|
50 |
-
case 'varchar':
|
51 |
-
$query = $connection->select()->from('catalog_product_entity_varchar','value')->where('entity_id = ?', $entityId)->where('attribute_id = ?', $attributeInfo['attribute_id']);
|
52 |
-
break;
|
53 |
-
|
54 |
-
}
|
55 |
-
$mpn = $connection->fetchOne($query);
|
56 |
-
*/
|
57 |
-
|
58 |
-
$mpn = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
}
|
74 |
-
|
75 |
-
$locale = Mage::getStoreConfig('icecat_root/icecat/language');
|
76 |
-
|
77 |
-
if ($locale == '0'){
|
78 |
-
$systemLocale = explode("_", Mage::app()->getLocale()->getLocaleCode());
|
79 |
-
$locale = $systemLocale[0];
|
80 |
-
}
|
81 |
-
$userLogin = Mage::getStoreConfig('icecat_root/icecat/login');
|
82 |
-
$userPass = Mage::getStoreConfig('icecat_root/icecat/password');
|
83 |
-
|
84 |
-
$this->iceCatModel = Mage::getSingleton('icecatimport/import');
|
85 |
-
|
86 |
-
if (!$this->iceCatModel->getProductDescription($mpn, $manufacturer, $locale, $userLogin, $userPass, $entityId)){
|
87 |
-
|
88 |
-
$this->error = $this->iceCatModel->getErrorMessage();
|
89 |
-
$this->systemError = $this->iceCatModel->getSystemError();
|
90 |
-
//echo $this->systemError;
|
91 |
-
return $this;
|
92 |
-
}
|
93 |
-
} catch (Exception $e) {
|
94 |
-
Mage::log('Icecat getProductDescription error'.$e);
|
95 |
-
}
|
96 |
return $this;
|
|
|
|
|
|
|
97 |
}
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
106 |
}
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
//show icecat error on product page return $this->error;
|
113 |
-
}
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
}
|
122 |
-
return false;
|
123 |
}
|
|
|
|
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
160 |
}
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
$
|
167 |
-
if (empty($
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
$relatedProductInfo['url'] = preg_replace( '/\/\d+\/$/',"/".$categoryId."/",$product->getProductUrl());;
|
198 |
-
if (!array_key_exists($categoryId, $relatedProductsList)){
|
199 |
-
$relatedProductsList[$categoryId]= array();
|
200 |
-
}
|
201 |
-
|
202 |
-
array_push($relatedProductsList[$categoryId], $relatedProductInfo);
|
203 |
-
}
|
204 |
-
}
|
205 |
-
else {
|
206 |
-
if (!array_key_exists($product->getData($sku), $relatedProducts)){
|
207 |
-
continue;
|
208 |
-
}
|
209 |
-
$relatedProductInfo = $relatedProducts[$product->getData($sku)];
|
210 |
-
$relatedProductInfo['mpn'] = $product->getData($sku);
|
211 |
-
$relatedProductInfo['url'] = preg_replace( '/category\/\d+\/$/','',$product->getProductUrl());;
|
212 |
-
if (!array_key_exists('a', $relatedProductsList)){
|
213 |
-
$relatedProductsList['a']= array();
|
214 |
-
}
|
215 |
-
|
216 |
-
array_push($relatedProductsList['a'], $relatedProductInfo);
|
217 |
-
}
|
218 |
}
|
219 |
return $relatedProductsList;
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
}
|
224 |
?>
|
17 |
* @return Bintime_Icecatimport_Helper_Getdata
|
18 |
*/
|
19 |
|
20 |
+
public function getEntityTypeId() {
|
21 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
22 |
+
$query = $connection->select()
|
23 |
+
->from(Mage::getSingleton('core/resource')
|
24 |
+
->getTableName('eav_entity_type'),'entity_type_id')
|
25 |
+
->where('entity_type_code = ?', 'catalog_product')
|
26 |
+
->limit(1);
|
27 |
+
$this->entityTypeId = $connection->fetchOne($query);
|
28 |
+
return $this->entityTypeId;
|
29 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
public function getProductDescription($_product) {
|
32 |
+
try {
|
33 |
+
$entityId = $_product->getEntityId();
|
34 |
+
$entity_type_id = $this->getEntityTypeId();
|
35 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
36 |
+
$mpn = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
|
37 |
+
$ean_code = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/ean_code'));
|
38 |
+
$manufacturerId = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
|
39 |
+
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
|
40 |
+
->setCodeFilter(Mage::getStoreConfig('icecat_root/icecat/manufacturer'))
|
41 |
+
->setEntityTypeFilter($entity_type_id)
|
42 |
+
->getFirstItem();
|
43 |
+
if ($attributeInfo->getData('backend_type') == 'int' ||
|
44 |
+
($attributeInfo->getData('frontend_input') == 'select' && $attributeInfo->getData('backend_type') == 'static' )) {
|
45 |
+
$attribute = $attributeInfo->setEntity($_product->getResource());
|
46 |
+
$manufacturer = $attribute->getSource()->getOptionText($manufacturerId);
|
47 |
+
} else {
|
48 |
+
$manufacturer = $manufacturerId;
|
49 |
+
}
|
50 |
|
51 |
+
$locale = Mage::getStoreConfig('icecat_root/icecat/language');
|
52 |
+
if ($locale == '0'){
|
53 |
+
$systemLocale = explode("_", Mage::app()->getLocale()->getLocaleCode());
|
54 |
+
$locale = $systemLocale[0];
|
55 |
+
}
|
56 |
+
$userLogin = Mage::getStoreConfig('icecat_root/icecat/login');
|
57 |
+
$userPass = Mage::getStoreConfig('icecat_root/icecat/password');
|
58 |
+
$this->iceCatModel = Mage::getSingleton('icecatimport/import');
|
59 |
+
if (!$this->iceCatModel->getProductDescription($mpn, $manufacturer, $locale, $userLogin, $userPass, $entityId, $ean_code)){
|
60 |
+
$this->error = $this->iceCatModel->getErrorMessage();
|
61 |
+
$this->systemError = $this->iceCatModel->getSystemError();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
return $this;
|
63 |
+
}
|
64 |
+
} catch (Exception $e) {
|
65 |
+
Mage::log('Icecat getProductDescription error'.$e);
|
66 |
}
|
67 |
+
return $this;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* returns true if error during data fetch occured else false
|
72 |
+
*/
|
73 |
+
public function hasError(){
|
74 |
+
if ($this->error || $this->systemError){
|
75 |
+
return true;
|
76 |
}
|
77 |
+
return false;
|
78 |
+
}
|
79 |
|
80 |
+
/**
|
81 |
+
* return error message
|
82 |
+
*/
|
83 |
+
public function getError(){}
|
|
|
|
|
84 |
|
85 |
+
/**
|
86 |
+
* return system error
|
87 |
+
*/
|
88 |
+
public function hasSystemError(){
|
89 |
+
if ($this->systemError){
|
90 |
+
return $this->systemError;
|
|
|
|
|
91 |
}
|
92 |
+
return false;
|
93 |
+
}
|
94 |
|
95 |
+
public function getProductDescriptionList(){
|
96 |
+
return $this->iceCatModel->getProductDescriptionList();
|
97 |
+
}
|
98 |
|
99 |
+
public function getShortProductDescription(){
|
100 |
+
return $this->iceCatModel->getShortProductDescription();
|
101 |
+
}
|
102 |
|
103 |
+
public function getLowPicUrl(){
|
104 |
+
return $this->iceCatModel->getLowPicUrl();
|
105 |
+
}
|
106 |
+
public function getThumbPicture(){
|
107 |
+
return $this->iceCatModel->getThumbPicture();
|
108 |
+
}
|
109 |
|
110 |
+
public function getGalleryPhotos(){
|
111 |
+
return $this->iceCatModel->getGalleryPhotos();
|
112 |
+
}
|
113 |
|
114 |
+
public function getProductName(){
|
115 |
+
return $this->iceCatModel->getProductName();
|
116 |
+
}
|
117 |
+
public function getVendor(){
|
118 |
+
return $this->iceCatModel->getVendor();
|
119 |
+
}
|
120 |
|
121 |
+
public function getFullProductDescription(){
|
122 |
+
return $this->iceCatModel->getFullProductDescription();
|
123 |
+
}
|
124 |
|
125 |
+
public function getMPN(){
|
126 |
+
return $this->iceCatModel->getMPN();
|
127 |
+
}
|
128 |
+
public function getEAN(){
|
129 |
+
return $this->iceCatModel->getEAN();
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Form related products list according to store products
|
134 |
+
*/
|
135 |
+
public function getRelatedProducts(){
|
136 |
+
$relatedProducts =$this->iceCatModel->getRelatedProducts();
|
137 |
+
if (empty($relatedProducts)){
|
138 |
+
return array();
|
139 |
}
|
140 |
+
$sku = Mage::getStoreConfig('icecat_root/icecat/sku_field');
|
141 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
142 |
+
$filterArray = array();
|
143 |
+
foreach($relatedProducts as $mpn => $valueArray){
|
144 |
+
array_push($filterArray, array('attribute'=>$sku,'eq'=>$mpn));
|
145 |
}
|
146 |
+
$collection->addFieldToFilter($filterArray);
|
147 |
+
$collection->addAttributeToSelect($sku);
|
148 |
+
$collection->addAttributeToSelect('category_ids');
|
149 |
+
$relatedProductsList = array();
|
150 |
+
foreach ($collection as $product) {
|
151 |
+
$categoryIds = $product->getCategoryIds();
|
152 |
+
if (!empty($categoryIds)){
|
153 |
+
if (is_array($categoryIds)){
|
154 |
+
$catogoriesArray = $categoryIds;
|
155 |
+
}
|
156 |
+
if (is_string($categoryIds)){
|
157 |
+
$catogoriesArray = explode(",",$product->getCategoryIds());
|
158 |
+
}
|
159 |
+
foreach($catogoriesArray as $categoryId){
|
160 |
+
if (!array_key_exists($product->getData($sku), $relatedProducts)){
|
161 |
+
continue;
|
162 |
+
}
|
163 |
+
$relatedProductInfo = $relatedProducts[$product->getData($sku)];
|
164 |
+
$relatedProductInfo['mpn'] = $product->getData($sku);
|
165 |
+
$relatedProductInfo['url'] = preg_replace( '/\/\d+\/$/',"/".$categoryId."/",$product->getProductUrl());;
|
166 |
+
if (!array_key_exists($categoryId, $relatedProductsList)){
|
167 |
+
$relatedProductsList[$categoryId]= array();
|
168 |
+
}
|
169 |
+
array_push($relatedProductsList[$categoryId], $relatedProductInfo);
|
170 |
+
}
|
171 |
+
} else {
|
172 |
+
if (!array_key_exists($product->getData($sku), $relatedProducts)){
|
173 |
+
continue;
|
174 |
+
}
|
175 |
+
$relatedProductInfo = $relatedProducts[$product->getData($sku)];
|
176 |
+
$relatedProductInfo['mpn'] = $product->getData($sku);
|
177 |
+
$relatedProductInfo['url'] = preg_replace( '/category\/\d+\/$/','',$product->getProductUrl());;
|
178 |
+
if (!array_key_exists('a', $relatedProductsList)){
|
179 |
+
$relatedProductsList['a']= array();
|
180 |
+
}
|
181 |
+
array_push($relatedProductsList['a'], $relatedProductInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
return $relatedProductsList;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
|
|
187 |
?>
|
app/code/local/Bintime/Icecatimport/Helper/Image.php
CHANGED
@@ -6,48 +6,40 @@
|
|
6 |
*/
|
7 |
class Bintime_Icecatimport_Helper_Image extends Mage_Core_Helper_Abstract
|
8 |
{
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
break;
|
37 |
-
|
38 |
-
default:
|
39 |
-
$manufacturer = $manufacturerId;
|
40 |
-
break;
|
41 |
-
}
|
42 |
-
|
43 |
-
$this->observer = Mage::getSingleton('icecatimport/observer');
|
44 |
-
$url = $this->observer->getImageURL($sku, $manufacturer);
|
45 |
-
return $url;
|
46 |
}
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
}
|
6 |
*/
|
7 |
class Bintime_Icecatimport_Helper_Image extends Mage_Core_Helper_Abstract
|
8 |
{
|
9 |
+
/**
|
10 |
+
* Fetch Image URL from DB
|
11 |
+
* @param Mage_Catalog_Model_Product $_product
|
12 |
+
* @return string image URL
|
13 |
+
*/
|
14 |
+
public function getImage($_product) {
|
15 |
+
$_product = $_product->load($_product->getId());
|
16 |
+
$sku = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
|
17 |
+
$manufacturerId = $_product->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
|
18 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
19 |
+
$query = $connection->select()
|
20 |
+
->from(Mage::getSingleton('core/resource')->getTableName('eav_entity_type'),'entity_type_id')
|
21 |
+
->where('entity_type_code = ?', 'catalog_product')
|
22 |
+
->limit(1);
|
23 |
+
$entityTypeId = $connection->fetchOne($query);
|
24 |
+
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
|
25 |
+
->setCodeFilter(Mage::getStoreConfig('icecat_root/icecat/manufacturer'))
|
26 |
+
->setEntityTypeFilter($_product->getResource()->getTypeId())
|
27 |
+
->getFirstItem();
|
28 |
+
switch ($attributeInfo->getData('backend_type')) {
|
29 |
+
case 'int':
|
30 |
+
$attribute = $attributeInfo->setEntity($_product->getResource());
|
31 |
+
$manufacturer = $attribute->getSource()->getOptionText($manufacturerId);
|
32 |
+
break;
|
33 |
+
default:
|
34 |
+
$manufacturer = $manufacturerId;
|
35 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
+
$this->observer = Mage::getSingleton('icecatimport/observer');
|
38 |
+
$url = $this->observer->getImageURL($sku, $manufacturer);
|
39 |
+
return $url;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function getGallery() {
|
43 |
+
return Mage::getSingleton('icecatimport/import')->getGalleryPhotos();
|
44 |
+
}
|
45 |
}
|
app/code/local/Bintime/Icecatimport/Helper/Output.php
CHANGED
@@ -1,101 +1,109 @@
|
|
1 |
<?php
|
2 |
class Bintime_Icecatimport_Helper_Output extends Mage_Catalog_Helper_Output
|
3 |
{
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return parent::productAttribute($product, $attributeHtml, $attributeName);
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
public function getIceCatMedia(){
|
97 |
-
$media = (array)$this->iceCatModel->getIceCatMedia();
|
98 |
-
return (array_key_exists('@attributes', $media)) ? $media['@attributes'] : array();
|
99 |
-
}
|
100 |
}
|
101 |
?>
|
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 |
+
if (!mage::registry('product')) {
|
25 |
+
return parent::productAttribute($product, $attributeHtml, $attributeName);
|
26 |
+
}
|
27 |
+
|
28 |
+
$productDescriptionPriority = Mage::getStoreConfig('icecat_root/icecat/descript_priority');
|
29 |
+
$dbDescriptionPriority = false;
|
30 |
+
if ($productDescriptionPriority == 'Db' &&
|
31 |
+
( $attributeName == 'description' || $attributeName == 'short_description')) {
|
32 |
+
$dbDescriptionPriority = true;
|
33 |
+
}
|
34 |
+
|
35 |
+
if ($dbDescriptionPriority) {
|
36 |
+
return parent::productAttribute($product, $attributeHtml, $attributeName);
|
37 |
+
}
|
38 |
+
|
39 |
+
$this->iceCatModel = Mage::getSingleton('icecatimport/import');
|
40 |
+
if ($this->isFirstTime){
|
41 |
+
$helper = Mage::helper('icecatimport/getdata');
|
42 |
+
$helper->getProductDescription($product);
|
43 |
+
|
44 |
+
if ($helper->hasError() && !$dbDescriptionPriority) {
|
45 |
+
$this->error = true;
|
46 |
+
}
|
47 |
+
$this->isFirstTime = false;
|
48 |
+
}
|
49 |
+
|
50 |
+
if ($this->error){
|
51 |
+
if ($attributeName != 'description' && $attributeName != 'short_description') {
|
52 |
return parent::productAttribute($product, $attributeHtml, $attributeName);
|
53 |
+
} else {
|
54 |
+
return '';
|
55 |
+
}
|
56 |
+
|
57 |
}
|
58 |
+
$id = $product->getData('entity_id');
|
59 |
+
if ($attributeName == 'name'){
|
60 |
+
//if we on product page then mage::registry('product') exist
|
61 |
+
if ($product->getId() == $this->iceCatModel->entityId && $name = $product->getData('brand_name') . ' ' . $this->iceCatModel->getProductName()) {
|
62 |
+
return $name;
|
63 |
+
}
|
64 |
+
$manufacturerId = Mage::getStoreConfig('icecat_root/icecat/manufacturer');
|
65 |
+
$mpn = Mage::getStoreConfig('icecat_root/icecat/sku_field');
|
66 |
+
$collection = Mage::getResourceModel('catalog/product_collection');
|
67 |
+
$collection->addAttributeToSelect($manufacturerId)->addAttributeToSelect($mpn)
|
68 |
+
->addAttributeToSelect('name')
|
69 |
+
->addAttributeToFilter('entity_id', array('eq' => $id));
|
70 |
+
$product = $collection->getFirstItem() ;
|
71 |
+
return $product->getName();
|
72 |
+
}
|
73 |
+
|
74 |
+
if ($attributeName == 'short_description') {
|
75 |
+
return $this->iceCatModel->getShortProductDescription();
|
76 |
+
}
|
77 |
+
if ($attributeName == 'description') {
|
78 |
+
return str_replace("\\n", "<br>",$this->iceCatModel->getFullProductDescription());
|
79 |
+
}
|
80 |
+
return parent::productAttribute($product, $attributeHtml, $attributeName);
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
public function getWarrantyInfo(){
|
85 |
+
return $this->iceCatModel->getWarrantyInfo();
|
86 |
+
}
|
87 |
+
|
88 |
+
public function getShortSummaryDescription(){
|
89 |
+
return $this->iceCatModel->getShortSummaryDescription();
|
90 |
+
}
|
91 |
+
|
92 |
+
public function getLongSummaryDescription(){
|
93 |
+
return $this->iceCatModel->getLongSummaryDescription();
|
94 |
+
}
|
95 |
+
|
96 |
+
public function getManualPDF(){
|
97 |
+
return $this->iceCatModel->getManualPDF();
|
98 |
+
}
|
99 |
+
|
100 |
+
public function getPDF(){
|
101 |
+
return $this->iceCatModel->getPDF();
|
102 |
+
}
|
103 |
+
|
104 |
+
public function getIceCatMedia(){
|
105 |
+
$media = (array)$this->iceCatModel->getIceCatMedia();
|
106 |
+
return (array_key_exists('@attributes', $media)) ? $media['@attributes'] : array();
|
107 |
+
}
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
?>
|
app/code/local/Bintime/Icecatimport/Model/Catalog/Product.php
CHANGED
@@ -7,158 +7,128 @@
|
|
7 |
class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Product
|
8 |
{
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
*/
|
40 |
-
|
41 |
-
$tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
|
42 |
-
$mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
|
43 |
-
$selectCondition = $connection->select()->
|
44 |
-
from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_name'))
|
45 |
-
->joinInner(array('supplier' => $mappingTable), "connector.supplier_id = supplier.supplier_id AND supplier.supplier_symbol = {$connection->quote($manufacturer)}")
|
46 |
-
->where('connector.prod_id = ? ', $mpn);
|
47 |
-
|
48 |
-
$icecatName = $connection->fetchOne($selectCondition);
|
49 |
-
} catch (Exception $e) {
|
50 |
-
Mage::log('Icecat getName error'.$e);
|
51 |
-
}
|
52 |
-
|
53 |
-
return $icecatName ? $icecatName : $this->getData('name');
|
54 |
}
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
*/
|
74 |
-
const ENTITY = 'catalog_product';
|
75 |
-
|
76 |
-
const CACHE_TAG = 'catalog_product';
|
77 |
-
protected $_cacheTag = 'catalog_product';
|
78 |
-
protected $_eventPrefix = 'catalog_product';
|
79 |
-
protected $_eventObject = 'product';
|
80 |
-
protected $_canAffectOptions = false;
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Product type instance
|
84 |
-
*
|
85 |
-
* @var Mage_Catalog_Model_Product_Type_Abstract
|
86 |
-
*/
|
87 |
-
protected $_typeInstance = null;
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Product type instance as singleton
|
91 |
-
*/
|
92 |
-
protected $_typeInstanceSingleton = null;
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Product link instance
|
96 |
-
*
|
97 |
-
* @var Mage_Catalog_Model_Product_Link
|
98 |
-
*/
|
99 |
-
protected $_linkInstance;
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Product object customization (not stored in DB)
|
103 |
-
*
|
104 |
-
* @var array
|
105 |
-
*/
|
106 |
-
protected $_customOptions = array();
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Product Url Instance
|
110 |
-
*
|
111 |
-
* @var Mage_Catalog_Model_Product_Url
|
112 |
-
*/
|
113 |
-
protected $_urlModel = null;
|
114 |
-
|
115 |
-
protected static $_url;
|
116 |
-
protected static $_urlRewrite;
|
117 |
-
|
118 |
-
protected $_errors = array();
|
119 |
-
|
120 |
-
protected $_optionInstance;
|
121 |
-
|
122 |
-
protected $_options = array();
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Product reserved attribute codes
|
126 |
-
*/
|
127 |
-
protected $_reservedAttributes;
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Flag for available duplicate function
|
131 |
-
*
|
132 |
-
* @var boolean
|
133 |
-
*/
|
134 |
-
protected $_isDuplicable = true;
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
/**
|
139 |
-
* Initialize resources
|
140 |
-
*/
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Get product name
|
144 |
-
*
|
145 |
-
* @return string
|
146 |
-
*/
|
147 |
-
/*
|
148 |
-
public function getName()
|
149 |
-
{
|
150 |
-
return $this->_getData('name');
|
151 |
-
//return parent::getName();
|
152 |
-
//return 'overriden name!!!';
|
153 |
}
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
}
|
164 |
?>
|
7 |
class Bintime_Icecatimport_Model_Catalog_Product extends Mage_Catalog_Model_Product
|
8 |
{
|
9 |
|
10 |
+
public function getName(){
|
11 |
+
|
12 |
+
try {
|
13 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
14 |
+
$manufacturerId = $this->getData(Mage::getStoreConfig('icecat_root/icecat/manufacturer'));
|
15 |
+
$mpn = $this->getData(Mage::getStoreConfig('icecat_root/icecat/sku_field'));
|
16 |
+
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
|
17 |
+
->setCodeFilter(Mage::getStoreConfig('icecat_root/icecat/manufacturer'))
|
18 |
+
->setEntityTypeFilter($this->getResource()->getTypeId())
|
19 |
+
->getFirstItem();
|
20 |
+
switch ($attributeInfo->getData('backend_type')) {
|
21 |
+
case 'int':
|
22 |
+
$attribute = $attributeInfo->setEntity($this->getResource());
|
23 |
+
$manufacturer = $attribute->getSource()->getOptionText($manufacturerId);
|
24 |
+
break;
|
25 |
+
default:
|
26 |
+
$manufacturer = $manufacturerId;
|
27 |
+
break;
|
28 |
+
}
|
29 |
+
|
30 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
|
31 |
+
$mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
|
32 |
+
$selectCondition = $connection->select()
|
33 |
+
->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_name'))
|
34 |
+
->joinInner(array('supplier' => $mappingTable), "connector.supplier_id = supplier.supplier_id AND supplier.supplier_symbol = {$connection->quote($manufacturer)}")
|
35 |
+
->where('connector.prod_id = ? ', $mpn);
|
36 |
+
$icecatName = $connection->fetchOne($selectCondition);
|
37 |
+
} catch (Exception $e) {
|
38 |
+
Mage::log('Icecat getName error'.$e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
+
|
41 |
+
$product_name = $icecatName ? $icecatName : $this->getData('name');
|
42 |
+
return $this->getData('brand_name') . ' ' . $product_name;
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
public function getImage(){
|
47 |
+
if(!parent::getImage()||parent::getImage() == 'no_selection'){
|
48 |
+
return "true";
|
49 |
+
}else {
|
50 |
+
return parent::getImage();
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
public function getShortDescription() {
|
55 |
+
if ('Icecat' == Mage::getStoreConfig('icecat_root/icecat/descript_priority')) {
|
56 |
+
return true;
|
57 |
+
} else {
|
58 |
+
return parent::getShortDescription();
|
59 |
}
|
60 |
+
}
|
61 |
+
|
62 |
+
public function getDescription() {
|
63 |
+
if ('Icecat' == Mage::getStoreConfig('icecat_root/icecat/descript_priority')) {
|
64 |
+
return true;
|
65 |
+
} else {
|
66 |
+
return parent::getDescription();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Entity code.
|
73 |
+
* Can be used as part of method name for entity processing
|
74 |
+
*/
|
75 |
+
const ENTITY = 'catalog_product';
|
76 |
+
|
77 |
+
const CACHE_TAG = 'catalog_product';
|
78 |
+
protected $_cacheTag = 'catalog_product';
|
79 |
+
protected $_eventPrefix = 'catalog_product';
|
80 |
+
protected $_eventObject = 'product';
|
81 |
+
protected $_canAffectOptions = false;
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Product type instance
|
85 |
+
*
|
86 |
+
* @var Mage_Catalog_Model_Product_Type_Abstract
|
87 |
+
*/
|
88 |
+
protected $_typeInstance = null;
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Product type instance as singleton
|
92 |
+
*/
|
93 |
+
protected $_typeInstanceSingleton = null;
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Product link instance
|
97 |
+
*
|
98 |
+
* @var Mage_Catalog_Model_Product_Link
|
99 |
+
*/
|
100 |
+
protected $_linkInstance;
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Product object customization (not stored in DB)
|
104 |
+
*
|
105 |
+
* @var array
|
106 |
+
*/
|
107 |
+
protected $_customOptions = array();
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Product Url Instance
|
111 |
+
*
|
112 |
+
* @var Mage_Catalog_Model_Product_Url
|
113 |
+
*/
|
114 |
+
protected $_urlModel = null;
|
115 |
+
protected static $_url;
|
116 |
+
protected static $_urlRewrite;
|
117 |
+
protected $_errors = array();
|
118 |
+
protected $_optionInstance;
|
119 |
+
protected $_options = array();
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Product reserved attribute codes
|
123 |
+
*/
|
124 |
+
protected $_reservedAttributes;
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Flag for available duplicate function
|
128 |
+
*
|
129 |
+
* @var boolean
|
130 |
+
*/
|
131 |
+
protected $_isDuplicable = true;
|
132 |
|
133 |
}
|
134 |
?>
|
app/code/local/Bintime/Icecatimport/Model/Import.php
CHANGED
@@ -5,346 +5,370 @@
|
|
5 |
*
|
6 |
*/
|
7 |
class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
return false;
|
53 |
-
}
|
54 |
-
if (empty($vendorName)){
|
55 |
-
$this->errorMessage = "Given product has no manufacturer specified.";
|
56 |
-
return false;
|
57 |
-
}
|
58 |
-
if (empty($locale)) {
|
59 |
-
$this->errorMessage = "Please specify product description locale";
|
60 |
-
return false;
|
61 |
-
}
|
62 |
-
if ( empty($userName)) {
|
63 |
-
$this->errorMessage = "No ICEcat login provided";
|
64 |
-
return false;
|
65 |
-
}
|
66 |
-
if (empty($userPass)){
|
67 |
-
$this->errorMessage = "No ICEcat password provided";
|
68 |
-
return false;
|
69 |
-
}
|
70 |
-
|
71 |
-
$getParamsArray = array("prod_id" => $productId,
|
72 |
-
"lang" =>$locale,
|
73 |
-
"vendor" => $vendorName,
|
74 |
-
"output" =>'productxml'
|
75 |
-
);
|
76 |
-
Varien_Profiler::start('Bintime FILE DOWNLOAD:');
|
77 |
-
try{
|
78 |
-
$webClient = new Zend_Http_Client();
|
79 |
-
$webClient->setUri($dataUrl);
|
80 |
-
$webClient->setMethod(Zend_Http_Client::GET);
|
81 |
-
$webClient->setHeaders('Content-Type: text/xml; charset=UTF-8');
|
82 |
-
$webClient->setParameterGet($getParamsArray);
|
83 |
-
$webClient->setAuth($userName, $userPass, Zend_Http_CLient::AUTH_BASIC);
|
84 |
-
$response = $webClient->request();
|
85 |
-
if ($response->isError()){
|
86 |
-
$this->errorMessage = 'Response Status: '.$response->getStatus()." Response Message: ".$response->getMessage();
|
87 |
-
return false;
|
88 |
-
}
|
89 |
-
}
|
90 |
-
catch (Exception $e) {
|
91 |
-
$this->errorMessage = "Warning: cannot connect to ICEcat. {$e->getMessage()}";
|
92 |
-
return false;
|
93 |
-
}
|
94 |
-
Varien_Profiler::stop('Bintime FILE DOWNLOAD:');
|
95 |
-
$resultString = $response->getBody();
|
96 |
-
Mage::app()->getCache()->save($resultString, $this->_cacheKey . $entityId);
|
97 |
-
} else {
|
98 |
-
$resultString = $cacheDataXml;
|
99 |
-
}
|
100 |
-
if(!$this->parseXml($resultString)){
|
101 |
-
return false;
|
102 |
-
}
|
103 |
-
|
104 |
-
if ($this->checkIcecatResponse($productId, $vendorName)){
|
105 |
-
return false;
|
106 |
-
}
|
107 |
-
|
108 |
-
$this->loadProductDescriptionList();
|
109 |
-
$this->loadOtherProductParams($productId);
|
110 |
-
$this->loadGalleryPhotos();
|
111 |
-
Varien_Profiler::start('Bintime FILE RELATED');
|
112 |
-
$this->loadRelatedProducts();
|
113 |
-
Varien_Profiler::stop('Bintime FILE RELATED');
|
114 |
}
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
public function getGalleryPhotos(){
|
127 |
-
return $this->galleryPhotos;
|
128 |
-
}
|
129 |
-
|
130 |
-
public function getThumbPicture(){
|
131 |
-
return $this->thumb;
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* load Gallery array from XML
|
136 |
-
*/
|
137 |
-
private function loadGalleryPhotos(){
|
138 |
-
$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
|
139 |
-
if (!count($galleryPhotos)){
|
140 |
return false;
|
141 |
}
|
142 |
-
|
143 |
-
if($
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
}//endif
|
156 |
}
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
$errorMessage = $this->simpleDoc->Product['ErrorMessage'];
|
170 |
-
if ($errorMessage != ''){
|
171 |
-
if (preg_match('/^No xml data/', $errorMessage)){
|
172 |
-
$this->errorSystemMessage = $errorMessage;
|
173 |
-
return true;
|
174 |
}
|
175 |
-
if (
|
176 |
-
|
177 |
-
|
178 |
}
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
181 |
}
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
public function getLowPicUrl(){
|
199 |
-
return $this->highPicUrl;
|
200 |
-
}
|
201 |
-
|
202 |
-
public function getRelatedProducts(){
|
203 |
-
return $this->relatedProducts;
|
204 |
-
}
|
205 |
-
|
206 |
-
public function getVendor(){
|
207 |
-
return $this->vendor;
|
208 |
-
}
|
209 |
-
|
210 |
-
public function getMPN(){
|
211 |
-
return $this->productId;
|
212 |
-
}
|
213 |
-
|
214 |
-
public function getEAN(){
|
215 |
-
return $this->EAN;
|
216 |
}
|
|
|
|
|
217 |
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
|
|
|
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
240 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
$productArray = array();
|
250 |
-
$productNS = $product->Product;
|
251 |
-
$productArray['name'] = (string)$productNS['Name'];
|
252 |
-
$productArray['thumb'] = (string)$productNS['ThumbPic'];
|
253 |
-
$mpn = (string)$productNS['Prod_id'];
|
254 |
-
$productSupplier = $productNS->Supplier;
|
255 |
-
$productSupplierId = (int)$productSupplier['ID'];
|
256 |
-
$productArray['supplier_thumb'] = 'http://images2.icecat.biz/thumbs/SUP'.$productSupplierId.'.jpg';
|
257 |
-
$productArray['supplier_name'] = (string)$productSupplier['Name'];
|
258 |
-
$this->relatedProducts[$mpn] = $productArray;
|
259 |
-
}
|
260 |
-
}
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Form product feature Arrray
|
265 |
-
*/
|
266 |
-
private function loadProductDescriptionList(){
|
267 |
-
$descriptionArray = array();
|
268 |
-
|
269 |
-
$specGroups = $this->simpleDoc->Product->CategoryFeatureGroup;
|
270 |
-
$specFeatures = $this->simpleDoc->Product->ProductFeature;
|
271 |
-
foreach($specFeatures as $feature){
|
272 |
-
$id = (int)$feature['CategoryFeatureGroup_ID'];
|
273 |
-
$featureText = (string)$feature["Presentation_Value"];
|
274 |
-
$featureName = (string)$feature->Feature->Name["Value"];
|
275 |
-
foreach($specGroups as $group){
|
276 |
-
$groupId = (int)$group["ID"];
|
277 |
-
if ($groupId == $id){
|
278 |
-
$groupName = (string) $group->FeatureGroup->Name["Value"];
|
279 |
-
$rating = (int)$group['No'];
|
280 |
-
$descriptionArray[$rating][$groupName][$featureName] = $featureText;
|
281 |
-
break;
|
282 |
-
}
|
283 |
-
}
|
284 |
-
}
|
285 |
-
krsort($descriptionArray);
|
286 |
-
$this->productDescriptionList = $descriptionArray;
|
287 |
}
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
$this->_pdfUrl = (string)$productTag->ProductDescription['PDFURL'];
|
304 |
-
|
305 |
-
$this->_multimedia = $productTag->ProductMultimediaObject->MultimediaObject;
|
306 |
-
|
307 |
-
$this->lowPicUrl = (string)$productTag["LowPic"];
|
308 |
-
$this->highPicUrl = (string)$productTag["HighPic"];
|
309 |
-
$this->productName = (string)$productTag["Name"];
|
310 |
-
$this->productId = (string)$productTag['Prod_id'];
|
311 |
-
$this->thumb = (string)$productTag['ThumbPic'];
|
312 |
-
$this->vendor = (string)$productTag->Supplier['Name'];
|
313 |
-
|
314 |
-
$prodEAN = $productTag->EANCode;
|
315 |
-
$EANstr='';
|
316 |
-
$EANarr=null;
|
317 |
-
$j = 0;//counter
|
318 |
-
foreach($prodEAN as $ellEAN){
|
319 |
-
$EANarr[]=$ellEAN['EAN'];$j++;
|
320 |
}
|
321 |
-
$
|
322 |
-
|
323 |
-
|
324 |
-
$g = $i%2;
|
325 |
-
if($g == '0'){if($j == 1){$str .= $EANarr[$i].'<br>';} else {$str .= $EANarr[$i].', ';}
|
326 |
}
|
327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
}
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
|
|
|
|
|
|
|
331 |
}
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
$
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
}
|
350 |
?>
|
5 |
*
|
6 |
*/
|
7 |
class Bintime_Icecatimport_Model_Import extends Mage_Core_Model_Abstract {
|
8 |
+
|
9 |
+
public $entityId;
|
10 |
+
private $productDescriptionList = array();
|
11 |
+
private $productDescription;
|
12 |
+
private $fullProductDescription;
|
13 |
+
private $lowPicUrl;
|
14 |
+
private $highPicUrl;
|
15 |
+
private $errorMessage;
|
16 |
+
private $galleryPhotos = array();
|
17 |
+
private $productName;
|
18 |
+
private $relatedProducts = array();
|
19 |
+
private $thumb;
|
20 |
+
private $errorSystemMessage; //depricated
|
21 |
+
private $_cacheKey = 'bintime_icecatimport_';
|
22 |
+
|
23 |
+
private $_warrantyInfo = '';
|
24 |
+
private $_shortSummaryDesc = '';
|
25 |
+
private $_longSummaryDesc = '';
|
26 |
+
|
27 |
+
private $_manualPdfUrl = '';
|
28 |
+
private $_pdfUrl = '';
|
29 |
+
private $_multimedia = '';
|
30 |
+
|
31 |
+
protected function _construct() {
|
32 |
+
$this->_init('icecatimport/import');
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Perform Curl request with corresponding param check and error processing
|
37 |
+
* @param int $productId
|
38 |
+
* @param string $vendorName
|
39 |
+
* @param string $locale
|
40 |
+
* @param string $userName
|
41 |
+
* @param string $userPass
|
42 |
+
*/
|
43 |
+
public function getProductDescription($productId, $vendorName, $locale, $userName, $userPass, $entityId, $ean_code){
|
44 |
+
$this->entityId = $entityId;
|
45 |
+
if (null === $this->simpleDoc) {
|
46 |
+
if (!$cacheDataXml = Mage::app()->getCache()->load($this->_cacheKey . $entityId . '_' . $locale)) {
|
47 |
+
$dataUrl = 'http://data.icecat.biz/xml_s3/xml_server3.cgi';
|
48 |
+
$successRespondByMPNVendorFlag = false;
|
49 |
+
if ( empty($userName)) {
|
50 |
+
$this->errorMessage = "No ICEcat login provided";
|
51 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
+
if (empty($userPass)){
|
54 |
+
$this->errorMessage = "No ICEcat password provided";
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
if (empty($locale)) {
|
58 |
+
$this->errorMessage = "Please specify product description locale";
|
59 |
+
return false;
|
60 |
+
}
|
61 |
+
if ((empty($productId) && empty($ean_code))
|
62 |
+
|| (empty($vendorName) && empty($ean_code))) {
|
63 |
+
$this->errorMessage = 'Given product has invalid IceCat data';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return false;
|
65 |
}
|
66 |
+
|
67 |
+
if (!empty($productId) && !empty($vendorName)) {
|
68 |
+
$resultString = $this->_getIceCatData($userName, $userPass, $dataUrl, array(
|
69 |
+
"prod_id" => $productId,
|
70 |
+
"lang" => $locale,
|
71 |
+
"vendor" => $vendorName,
|
72 |
+
"output" => 'productxml'
|
73 |
+
));
|
74 |
+
if ($this->parseXml($resultString)) {
|
75 |
+
if (!$this->checkIcecatResponse()) {
|
76 |
+
$successRespondByMPNVendorFlag = true;
|
77 |
+
}
|
78 |
+
}
|
|
|
79 |
}
|
80 |
+
// if get data by MPN & brand name wrong => trying by Ean code
|
81 |
+
if (!$successRespondByMPNVendorFlag) {
|
82 |
+
$error = false;
|
83 |
+
if (!empty($ean_code)) {
|
84 |
+
$resultString = $this->_getIceCatData($userName, $userPass, $dataUrl, array(
|
85 |
+
'ean_upc' => $ean_code,
|
86 |
+
'lang' => $locale,
|
87 |
+
'output' => 'productxml'
|
88 |
+
));
|
89 |
+
if (!$this->parseXml($resultString)) {
|
90 |
+
$error = true;
|
91 |
+
$this->simpleDoc = null;
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
+
if ($this->checkIcecatResponse()) {
|
94 |
+
$error = true;
|
95 |
+
$this->simpleDoc = null;
|
96 |
}
|
97 |
+
} else {
|
98 |
+
$error = true;
|
99 |
+
}
|
100 |
+
if ($error) {
|
101 |
+
$this->errorMessage = 'Given product has invalid IceCat data';
|
102 |
+
return false;
|
103 |
+
}
|
104 |
}
|
105 |
+
Mage::app()->getCache()->save($resultString, $this->_cacheKey . $entityId . '_' . $locale);
|
106 |
+
} else {
|
107 |
+
$resultString = $cacheDataXml;
|
108 |
+
if (!$this->parseXml($resultString)){
|
109 |
+
return false;
|
110 |
+
}
|
111 |
+
if ($this->checkIcecatResponse()){
|
112 |
+
return false;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
$this->loadProductDescriptionList();
|
116 |
+
$this->loadOtherProductParams($productId);
|
117 |
+
$this->loadGalleryPhotos();
|
118 |
+
Varien_Profiler::start('Bintime FILE RELATED');
|
119 |
+
$this->loadRelatedProducts();
|
120 |
+
Varien_Profiler::stop('Bintime FILE RELATED');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
+
return true;
|
123 |
+
}
|
124 |
|
125 |
+
private function _getIceCatData($userName, $userPass, $dataUrl, $productAttributes){
|
126 |
+
try{
|
127 |
+
$webClient = new Zend_Http_Client();
|
128 |
+
$webClient->setUri($dataUrl);
|
129 |
+
$webClient->setMethod(Zend_Http_Client::GET);
|
130 |
+
$webClient->setHeaders('Content-Type: text/xml; charset=UTF-8');
|
131 |
+
$webClient->setParameterGet($productAttributes);
|
132 |
+
$webClient->setAuth($userName, $userPass, Zend_Http_CLient::AUTH_BASIC);
|
133 |
+
$response = $webClient->request();
|
134 |
+
if ($response->isError()){
|
135 |
+
$this->errorMessage = 'Response Status: '.$response->getStatus()." Response Message: ".$response->getMessage();
|
136 |
+
return false;
|
137 |
+
}
|
138 |
+
} catch (Exception $e) {
|
139 |
+
$this->errorMessage = "Warning: cannot connect to ICEcat. {$e->getMessage()}";
|
140 |
+
return false;
|
141 |
}
|
142 |
+
return $response->getBody();
|
143 |
+
}
|
144 |
|
145 |
+
public function getSystemError(){
|
146 |
+
return $this->errorSystemMessage;
|
147 |
+
}
|
148 |
|
149 |
+
public function getProductName(){
|
150 |
+
return $this->productName;
|
151 |
+
}
|
152 |
|
153 |
+
public function getGalleryPhotos(){
|
154 |
+
return $this->galleryPhotos;
|
155 |
+
}
|
156 |
|
157 |
+
public function getThumbPicture(){
|
158 |
+
return $this->thumb;
|
159 |
+
}
|
160 |
|
161 |
+
/**
|
162 |
+
* load Gallery array from XML
|
163 |
+
*/
|
164 |
+
private function loadGalleryPhotos(){
|
165 |
+
$galleryPhotos = $this->simpleDoc->Product->ProductGallery->ProductPicture;
|
166 |
+
if (!count($galleryPhotos)){
|
167 |
+
return false;
|
168 |
}
|
169 |
+
foreach($galleryPhotos as $photo){
|
170 |
+
if ($photo["Size"] > 0){
|
171 |
+
$picHeight = (int)$photo["PicHeight"];
|
172 |
+
$picWidth = (int)$photo["PicWidth"];
|
173 |
+
$thumbUrl = (string)$photo["ThumbPic"];
|
174 |
+
$picUrl = (string)$photo["Pic"];
|
175 |
|
176 |
+
array_push($this->galleryPhotos, array(
|
177 |
+
'height' => $picHeight,
|
178 |
+
'width' => $picWidth,
|
179 |
+
'thumb' => $thumbUrl,
|
180 |
+
'pic' => $picUrl
|
181 |
+
));
|
182 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
}
|
184 |
+
}
|
185 |
+
|
186 |
+
public function getErrorMessage(){
|
187 |
+
return $this->errorMessage;
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Checks response XML for error messages
|
192 |
+
*/
|
193 |
+
private function checkIcecatResponse(){
|
194 |
+
$errorMessage = $this->simpleDoc->Product['ErrorMessage'];
|
195 |
+
if ($errorMessage != ''){
|
196 |
+
if (preg_match('/^No xml data/', $errorMessage)){
|
197 |
+
$this->errorSystemMessage = $errorMessage;
|
198 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
}
|
200 |
+
if (preg_match('/^The specified vendor does not exist$/', $errorMessage)) {
|
201 |
+
$this->errorSystemMessage = $errorMessage;
|
202 |
+
return true;
|
|
|
|
|
203 |
}
|
204 |
+
$this->errorMessage = "Ice Cat Error: ".$errorMessage;
|
205 |
+
return true;
|
206 |
+
}
|
207 |
+
return false;
|
208 |
+
}
|
209 |
+
|
210 |
+
public function getProductDescriptionList(){
|
211 |
+
return $this->productDescriptionList;
|
212 |
+
}
|
213 |
+
|
214 |
+
public function getShortProductDescription(){
|
215 |
+
return $this->productDescription;
|
216 |
+
}
|
217 |
+
|
218 |
+
public function getFullProductDescription(){
|
219 |
+
return $this->fullProductDescription;
|
220 |
+
}
|
221 |
+
|
222 |
+
public function getLowPicUrl(){
|
223 |
+
return $this->highPicUrl;
|
224 |
+
}
|
225 |
+
|
226 |
+
public function getRelatedProducts(){
|
227 |
+
return $this->relatedProducts;
|
228 |
+
}
|
229 |
+
|
230 |
+
public function getVendor(){
|
231 |
+
return $this->vendor;
|
232 |
+
}
|
233 |
+
|
234 |
+
public function getMPN(){
|
235 |
+
return $this->productId;
|
236 |
+
}
|
237 |
+
|
238 |
+
public function getEAN(){
|
239 |
+
return $this->EAN;
|
240 |
+
}
|
241 |
+
|
242 |
+
public function getWarrantyInfo(){
|
243 |
+
return $this->_warrantyInfo;
|
244 |
+
}
|
245 |
+
|
246 |
+
public function getShortSummaryDescription(){
|
247 |
+
return $this->_shortSummaryDesc;
|
248 |
+
}
|
249 |
+
|
250 |
+
public function getLongSummaryDescription(){
|
251 |
+
return $this->_longSummaryDesc;
|
252 |
+
}
|
253 |
+
|
254 |
+
public function getManualPDF(){
|
255 |
+
return $this->_manualPdfUrl;
|
256 |
+
}
|
257 |
+
|
258 |
+
public function getPDF(){
|
259 |
+
return $this->_pdfUrl;
|
260 |
+
}
|
261 |
+
|
262 |
+
public function getIceCatMedia(){
|
263 |
+
return $this->_multimedia;
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Form related products Array
|
268 |
+
*/
|
269 |
+
private function loadRelatedProducts(){
|
270 |
+
$relatedProductsArray = $this->simpleDoc->Product->ProductRelated;
|
271 |
+
if (count($relatedProductsArray)){
|
272 |
+
foreach($relatedProductsArray as $product){
|
273 |
+
$productArray = array();
|
274 |
+
$productNS = $product->Product;
|
275 |
+
$productArray['name'] = (string)$productNS['Name'];
|
276 |
+
$productArray['thumb'] = (string)$productNS['ThumbPic'];
|
277 |
+
$mpn = (string)$productNS['Prod_id'];
|
278 |
+
$productSupplier = $productNS->Supplier;
|
279 |
+
$productSupplierId = (int)$productSupplier['ID'];
|
280 |
+
$productArray['supplier_thumb'] = 'http://images2.icecat.biz/thumbs/SUP'.$productSupplierId.'.jpg';
|
281 |
+
$productArray['supplier_name'] = (string)$productSupplier['Name'];
|
282 |
+
$this->relatedProducts[$mpn] = $productArray;
|
283 |
}
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Form product feature Arrray
|
289 |
+
*/
|
290 |
+
private function loadProductDescriptionList(){
|
291 |
+
$descriptionArray = array();
|
292 |
+
$specGroups = $this->simpleDoc->Product->CategoryFeatureGroup;
|
293 |
+
$specFeatures = $this->simpleDoc->Product->ProductFeature;
|
294 |
+
foreach($specFeatures as $feature){
|
295 |
+
$id = (int)$feature['CategoryFeatureGroup_ID'];
|
296 |
+
$featureText = (string)$feature["Presentation_Value"];
|
297 |
+
$featureValue = (string)$feature["Value"];
|
298 |
+
$featureName = (string)$feature->Feature->Name["Value"];
|
299 |
+
if ($featureValue == 'Y' || $featureValue == 'N') {
|
300 |
+
$featureText = $featureValue;
|
301 |
+
}
|
302 |
+
foreach($specGroups as $group){
|
303 |
+
$groupId = (int)$group["ID"];
|
304 |
+
if ($groupId == $id){
|
305 |
+
$groupName = (string) $group->FeatureGroup->Name["Value"];
|
306 |
+
$rating = (int)$group['No'];
|
307 |
+
$descriptionArray[$rating][$groupName][$featureName] = $featureText;
|
308 |
+
break;
|
309 |
+
}
|
310 |
+
}
|
311 |
+
}
|
312 |
+
krsort($descriptionArray);
|
313 |
+
$this->productDescriptionList = $descriptionArray;
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Form Array of non feature-value product params
|
318 |
+
*/
|
319 |
+
private function loadOtherProductParams($productId){
|
320 |
+
$productTag = $this->simpleDoc->Product;
|
321 |
+
$this->productDescription = (string)$productTag->ProductDescription['ShortDesc'];
|
322 |
+
$this->fullProductDescription = (string)$productTag->ProductDescription['LongDesc'];
|
323 |
+
$this->_warrantyInfo = (string)$productTag->ProductDescription['WarrantyInfo'];
|
324 |
+
$this->_shortSummaryDesc = (string)$productTag->SummaryDescription->ShortSummaryDescription;
|
325 |
+
$this->_longSummaryDesc = (string)$productTag->SummaryDescription->LongSummaryDescription;
|
326 |
+
$this->_manualPdfUrl = (string)$productTag->ProductDescription['ManualPDFURL'];
|
327 |
+
$this->_pdfUrl = (string)$productTag->ProductDescription['PDFURL'];
|
328 |
+
$this->_multimedia = $productTag->ProductMultimediaObject->MultimediaObject;
|
329 |
+
$this->lowPicUrl = (string)$productTag["LowPic"];
|
330 |
+
$this->highPicUrl = (string)$productTag["HighPic"];
|
331 |
+
$this->productName = (string)$productTag["Name"];
|
332 |
+
$this->productId = (string)$productTag['Prod_id'];
|
333 |
+
$this->thumb = (string)$productTag['ThumbPic'];
|
334 |
+
$this->vendor = (string)$productTag->Supplier['Name'];
|
335 |
+
$prodEAN = $productTag->EANCode;
|
336 |
+
$EANstr = '';
|
337 |
+
$EANarr = null;
|
338 |
|
339 |
+
$j = 0;//counter
|
340 |
+
foreach($prodEAN as $ellEAN){
|
341 |
+
$EANarr[]=$ellEAN['EAN'];$j++;
|
342 |
}
|
343 |
+
$i = 0;
|
344 |
+
$str = '';
|
345 |
+
for ($i=0;$i<$j;$i++) {
|
346 |
+
$g = $i%2;
|
347 |
+
if ($g == '0') {
|
348 |
+
if($j == 1){
|
349 |
+
$str .= $EANarr[$i].'<br>';
|
350 |
+
} else {$str .= $EANarr[$i].', ';}
|
351 |
+
} else {if($i != $j-1){$str .= $EANarr[$i].', <br>';}else {$str .= $EANarr[$i].' <br>';}}
|
352 |
+
}
|
353 |
+
$this->EAN = $str;
|
354 |
+
|
355 |
+
}
|
356 |
+
|
357 |
+
/**
|
358 |
+
* parse response XML: to SimpleXml
|
359 |
+
* @param string $stringXml
|
360 |
+
*/
|
361 |
+
private function parseXml($stringXml){
|
362 |
+
libxml_use_internal_errors(true);
|
363 |
+
$this->simpleDoc = simplexml_load_string($stringXml);
|
364 |
+
if ($this->simpleDoc){
|
365 |
+
return true;
|
366 |
}
|
367 |
+
$this->simpleDoc = simplexml_load_string(utf8_encode($stringXml));
|
368 |
+
if ($this->simpleDoc){
|
369 |
+
return true;
|
370 |
+
}
|
371 |
+
return false;
|
372 |
+
}
|
373 |
}
|
374 |
?>
|
app/code/local/Bintime/Icecatimport/Model/Observer.php
CHANGED
@@ -5,316 +5,294 @@
|
|
5 |
* @author Sergey Gozhedrianov <info@bintime.com>
|
6 |
*
|
7 |
*/
|
8 |
-
class Bintime_Icecatimport_Model_Observer
|
9 |
{
|
10 |
-
|
11 |
-
|
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 |
-
protected $_supplierMappingUrl = 'http://data.icecat.biz/export/freeurls/supplier_mapping.xml';
|
16 |
-
protected $_connectorDir = '/bintime/icecatimport/';
|
17 |
-
protected $_productFile;
|
18 |
-
protected $_supplierFile;
|
19 |
-
|
20 |
-
protected function _construct()
|
21 |
-
{
|
22 |
-
$this->_init('icecatimport/observer');
|
23 |
-
}
|
24 |
-
|
25 |
-
/**
|
26 |
-
* root method for uploading images to DB
|
27 |
-
*/
|
28 |
-
public function load(){
|
29 |
-
|
30 |
-
$loadUrl = $this->getLoadURL();
|
31 |
-
ini_set('max_execution_time', 0);
|
32 |
-
|
33 |
-
try {
|
34 |
-
$this->_productFile = $this->_prepareFile(basename($loadUrl));
|
35 |
-
$this->_supplierFile = $this->_prepareFile(basename($this->_supplierMappingUrl));
|
36 |
-
echo "Data file downloading started <br>";
|
37 |
-
$this->downloadFile($this->_productFile, $loadUrl);
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
echo "Start File Processing<br>";
|
46 |
-
|
47 |
-
$this->_loadSupplierListToDb();
|
48 |
-
$this->loadFileToDb();
|
49 |
-
|
50 |
-
echo "File Processed Succesfully<br>";
|
51 |
-
} catch( Exception $e) {
|
52 |
-
echo $e->getMessage();
|
53 |
-
Mage::log($e->getMessage());
|
54 |
-
}
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* parse given XML to SIMPLE XML
|
59 |
-
* @param string $stringXml
|
60 |
-
*/
|
61 |
-
protected function _parseXml($stringXml){
|
62 |
-
libxml_use_internal_errors(true);
|
63 |
-
$simpleDoc = simplexml_load_string($stringXml);
|
64 |
-
if ($simpleDoc){
|
65 |
-
return $simpleDoc;
|
66 |
-
}
|
67 |
-
$simpleDoc = simplexml_load_string(utf8_encode($stringXml));
|
68 |
-
if ($simpleDoc){
|
69 |
-
return $simpleDoc;
|
70 |
-
}
|
71 |
-
return false;
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Upload supplier mapping list to Database
|
76 |
-
*/
|
77 |
-
protected function _loadSupplierListToDb()
|
78 |
-
{
|
79 |
-
$connection = $this->getDbConnection();
|
80 |
-
$mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
|
81 |
-
try {
|
82 |
-
$connection->beginTransaction();
|
83 |
-
$xmlString = file_get_contents($this->_supplierFile);
|
84 |
-
$xmlDoc = $this->_parseXml($xmlString);
|
85 |
-
if ($xmlDoc) {
|
86 |
-
$connection->query("DROP TABLE IF EXISTS `".$mappingTable."_temp`");
|
87 |
-
$connection->query("
|
88 |
-
CREATE TABLE `".$mappingTable."_temp` (
|
89 |
-
`supplier_id` int(11) NOT NULL,
|
90 |
-
`supplier_symbol` varchar(255) DEFAULT NULL,
|
91 |
-
KEY `supplier_id` (`supplier_id`)
|
92 |
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
93 |
-
");
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
$supplierId = $supplier['supplier_id'];
|
99 |
-
$connection->insert($mappingTable."_temp", array('supplier_id' => $supplierId, 'supplier_symbol' => (string)$supplier['name']));
|
100 |
-
foreach($supplierSymbolList as $symbol) {
|
101 |
-
$symbolName = (string)$symbol;
|
102 |
-
$connection->insert($mappingTable."_temp", array('supplier_id' => $supplierId, 'supplier_symbol' => $symbolName));
|
103 |
-
}
|
104 |
-
}
|
105 |
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
}
|
127 |
-
else {
|
128 |
-
return $this->freeExportURLs;
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* return error messages
|
134 |
-
*/
|
135 |
-
public function getErrorMessage(){
|
136 |
-
return $this->errorMessage;
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* getImage URL from DB
|
141 |
-
* @param string $productSku
|
142 |
-
* @param string $productManufacturer
|
143 |
-
*/
|
144 |
-
public function getImageURL($productSku, $productManufacturer){
|
145 |
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Singletong for DB connection
|
171 |
-
*/
|
172 |
-
private function getDbConnection(){
|
173 |
-
if ($this->connection){
|
174 |
-
return $this->connection;
|
175 |
-
}
|
176 |
-
$this->connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
177 |
-
return $this->connection;
|
178 |
-
}
|
179 |
-
|
180 |
-
/**
|
181 |
-
* Upload Data file to DP
|
182 |
-
*/
|
183 |
-
private function loadFileToDb(){
|
184 |
-
$connection = $this->getDbConnection();
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
`prod_img` varchar(255) DEFAULT NULL,
|
198 |
-
KEY `PRODUCT_MPN` (`prod_id`),
|
199 |
-
KEY `supplier_id` (`supplier_id`)
|
200 |
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
201 |
-
");
|
202 |
-
$csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp.csv';
|
203 |
-
$csvFileRes = fopen($csvFile, "w+");
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
// $connection->insert($tableName."_temp", array('prod_id' => $oneLine[1], 'prod_img' => $oneLine[6], 'prod_name' => $oneLine[12], 'supplier_id' => $oneLine[13]));
|
211 |
-
|
212 |
-
$prod_id = (!empty($oneLine[1])) ? $oneLine[1] : '';
|
213 |
-
$prod_img = (!empty($oneLine[6])) ? $oneLine[6] : '';
|
214 |
-
$prod_name = (!empty($oneLine[12])) ? $oneLine[12] : '';
|
215 |
-
$supplier_id = (!empty($oneLine[4])) ? $oneLine[4] : '';
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
220 |
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
/**
|
244 |
-
* unzip Uploaded file
|
245 |
-
*/
|
246 |
-
private function unzipFile(){
|
247 |
-
$gz = gzopen ( $this->_productFile, 'rb' );
|
248 |
-
|
249 |
-
if (file_exists($this->XMLfile)){
|
250 |
-
unlink($this->XMLfile);
|
251 |
-
}
|
252 |
-
|
253 |
-
$fileToWrite = @fopen($this->XMLfile, 'w+');
|
254 |
-
|
255 |
-
if (!$fileToWrite){
|
256 |
-
$this->errorMessage = 'Unable to open output txt file. Please remove all *.txt files from '.
|
257 |
-
Mage::getBaseDir('var'). $this->_connectorDir .'folder';
|
258 |
-
return false;
|
259 |
-
}
|
260 |
-
while (!gzeof($gz)) {
|
261 |
-
$buffer = gzgets($gz, 100000);
|
262 |
-
fputs($fileToWrite, $buffer) ;
|
263 |
-
}
|
264 |
-
gzclose ($gz);
|
265 |
-
fclose($fileToWrite);
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* Process downloading files
|
270 |
-
* @param string $destinationFile
|
271 |
-
* @param string $loadUrl
|
272 |
-
*/
|
273 |
-
private function downloadFile($destinationFile, $loadUrl){
|
274 |
-
$userName = Mage::getStoreConfig('icecat_root/icecat/login');
|
275 |
-
$userPass = Mage::getStoreConfig('icecat_root/icecat/password');
|
276 |
-
$fileToWrite = @fopen($destinationFile, 'w+');
|
277 |
-
|
278 |
-
try{
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
-
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
}
|
320 |
?>
|
5 |
* @author Sergey Gozhedrianov <info@bintime.com>
|
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 |
+
protected $_supplierMappingUrl = 'http://data.icecat.biz/export/freeurls/supplier_mapping.xml';
|
16 |
+
protected $_connectorDir = '/bintime/icecatimport/';
|
17 |
+
protected $_productFile;
|
18 |
+
protected $_supplierFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
protected function _construct(){
|
21 |
+
$this->_init('icecatimport/observer');
|
22 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
/**
|
25 |
+
* root method for uploading images to DB
|
26 |
+
*/
|
27 |
+
public function load(){
|
28 |
+
$loadUrl = $this->getLoadURL();
|
29 |
+
ini_set('max_execution_time', 0);
|
30 |
+
try {
|
31 |
+
$this->_productFile = $this->_prepareFile(basename($loadUrl));
|
32 |
+
$this->_supplierFile = $this->_prepareFile(basename($this->_supplierMappingUrl));
|
33 |
+
echo "Data file downloading started <br>";
|
34 |
+
$this->downloadFile($this->_productFile, $loadUrl);
|
35 |
|
36 |
+
echo "Start of supplier mapping file download<br>";
|
37 |
+
$this->downloadFile($this->_supplierFile, $this->_supplierMappingUrl);
|
38 |
+
$this->XMLfile = Mage::getBaseDir('var') . $this->_connectorDir . basename($loadUrl, ".gz");
|
39 |
+
|
40 |
+
echo "Start Unzipping Data File<br>";
|
41 |
+
$this->unzipFile();
|
42 |
+
echo "Start File Processing<br>";
|
43 |
+
|
44 |
+
$this->_loadSupplierListToDb();
|
45 |
+
$this->loadFileToDb();
|
46 |
+
|
47 |
+
echo "File Processed Succesfully<br>";
|
48 |
+
} catch( Exception $e) {
|
49 |
+
echo $e->getMessage();
|
50 |
+
Mage::log($e->getMessage());
|
51 |
+
}
|
52 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
/**
|
55 |
+
* parse given XML to SIMPLE XML
|
56 |
+
* @param string $stringXml
|
57 |
+
*/
|
58 |
+
protected function _parseXml($stringXml){
|
59 |
+
libxml_use_internal_errors(true);
|
60 |
+
$simpleDoc = simplexml_load_string($stringXml);
|
61 |
+
if ($simpleDoc){
|
62 |
+
return $simpleDoc;
|
63 |
+
}
|
64 |
+
$simpleDoc = simplexml_load_string(utf8_encode($stringXml));
|
65 |
+
if ($simpleDoc){
|
66 |
+
return $simpleDoc;
|
67 |
+
}
|
68 |
+
return false;
|
69 |
+
}
|
70 |
|
71 |
+
/**
|
72 |
+
* Upload supplier mapping list to Database
|
73 |
+
*/
|
74 |
+
protected function _loadSupplierListToDb(){
|
75 |
+
$connection = $this->getDbConnection();
|
76 |
+
$mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
|
77 |
+
try {
|
78 |
+
$connection->beginTransaction();
|
79 |
+
$xmlString = file_get_contents($this->_supplierFile);
|
80 |
+
$xmlDoc = $this->_parseXml($xmlString);
|
81 |
+
if ($xmlDoc) {
|
82 |
+
$connection->query("DROP TABLE IF EXISTS `".$mappingTable."_temp`");
|
83 |
+
$connection->query("
|
84 |
+
CREATE TABLE `".$mappingTable."_temp` (
|
85 |
+
`supplier_id` int(11) NOT NULL,
|
86 |
+
`supplier_symbol` varchar(255) DEFAULT NULL,
|
87 |
+
KEY `supplier_id` (`supplier_id`)
|
88 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
89 |
+
");
|
90 |
|
91 |
+
$supplierList = $xmlDoc->SupplierMappings->SupplierMapping;
|
92 |
+
foreach ($supplierList as $supplier) {
|
93 |
+
$supplierSymbolList = $supplier->Symbol;
|
94 |
+
$supplierId = $supplier['supplier_id'];
|
95 |
+
$connection->insert($mappingTable."_temp", array('supplier_id' => $supplierId, 'supplier_symbol' => (string)$supplier['name']));
|
96 |
+
foreach($supplierSymbolList as $symbol) {
|
97 |
+
$symbolName = (string)$symbol;
|
98 |
+
$connection->insert($mappingTable."_temp", array('supplier_id' => $supplierId, 'supplier_symbol' => $symbolName));
|
99 |
+
}
|
100 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
+
$connection->query("DROP TABLE IF EXISTS `".$mappingTable."_old`");
|
103 |
+
$connection->query("rename table `".$mappingTable."` to `".$mappingTable."_old`, `".$mappingTable."_temp` to ".$mappingTable);
|
104 |
+
$connection->commit();
|
105 |
+
} else {
|
106 |
+
throw new Exception('Unable to process supplier file');
|
107 |
+
}
|
108 |
+
} catch (Exception $e) {
|
109 |
+
$connection->rollBack();
|
110 |
+
throw new Exception("Icecat Import Terminated: {$e->getMessage()}");
|
111 |
+
}
|
112 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
/**
|
115 |
+
* retrieve URL of data file that corresponds ICEcat account
|
116 |
+
*/
|
117 |
+
private function getLoadURL(){
|
118 |
+
$subscripionLevel = Mage::getStoreConfig('icecat_root/icecat/icecat_type');
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
if ($subscripionLevel === 'full'){
|
121 |
+
return $this->fullExportURLs;
|
122 |
+
}
|
123 |
+
else {
|
124 |
+
return $this->freeExportURLs;
|
125 |
+
}
|
126 |
+
}
|
127 |
|
128 |
+
/**
|
129 |
+
* return error messages
|
130 |
+
*/
|
131 |
+
public function getErrorMessage(){
|
132 |
+
return $this->errorMessage;
|
133 |
+
}
|
134 |
|
135 |
+
/**
|
136 |
+
* getImage URL from DB
|
137 |
+
* @param string $productSku
|
138 |
+
* @param string $productManufacturer
|
139 |
+
*/
|
140 |
+
public function getImageURL($productSku, $productManufacturer){
|
141 |
+
$connection = $this->getDbConnection();
|
142 |
+
try {
|
143 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
|
144 |
+
$mappingTable = Mage::getSingleton('core/resource')->getTableName('icecatimport/supplier_mapping');
|
145 |
+
|
146 |
+
$selectCondition = $connection->select()
|
147 |
+
->from(array('connector' => $tableName), new Zend_Db_Expr('connector.prod_img'))
|
148 |
+
->joinInner(array('supplier' => $mappingTable), "connector.supplier_id = supplier.supplier_id AND supplier.supplier_symbol = {$this->connection->quote($productManufacturer)}")
|
149 |
+
->where('connector.prod_id = ? ', $productSku);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
+
$imageURL = $connection->fetchOne($selectCondition);
|
152 |
+
if (empty($imageURL)){
|
153 |
+
$this->errorMessage = "Given product id is not present in database";
|
154 |
+
return false;
|
155 |
+
}
|
156 |
+
return $imageURL;
|
157 |
+
} catch (Exception $e) {
|
158 |
+
$this->errorMessage = "DB ERROR: {$e->getMessage()}";
|
159 |
+
return false;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Singletong for DB connection
|
165 |
+
*/
|
166 |
+
private function getDbConnection(){
|
167 |
+
if ($this->connection){
|
168 |
+
return $this->connection;
|
169 |
+
}
|
170 |
+
$this->connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
171 |
+
return $this->connection;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Upload Data file to DP
|
176 |
+
*/
|
177 |
+
private function loadFileToDb(){
|
178 |
+
$connection = $this->getDbConnection();
|
179 |
|
180 |
+
$tableName = Mage::getSingleton('core/resource')->getTableName('icecatimport/data');
|
181 |
+
try {
|
182 |
+
$connection->beginTransaction();
|
183 |
+
$fileHandler = fopen($this->XMLfile, "r");
|
184 |
+
if ($fileHandler) {
|
185 |
+
$connection->query("DROP TABLE IF EXISTS `".$tableName."_temp`");
|
186 |
+
$connection->query("
|
187 |
+
CREATE TABLE `".$tableName."_temp` (
|
188 |
+
`prod_id` varchar(255) NOT NULL,
|
189 |
+
`supplier_id` int(11) DEFAULT NULL,
|
190 |
+
`prod_name` varchar(255) DEFAULT NULL,
|
191 |
+
`prod_img` varchar(255) DEFAULT NULL,
|
192 |
+
KEY `PRODUCT_MPN` (`prod_id`),
|
193 |
+
KEY `supplier_id` (`supplier_id`)
|
194 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
195 |
+
");
|
196 |
+
$csvFile = Mage::getBaseDir('var') . $this->_connectorDir . 'ice_cat_temp.csv';
|
197 |
+
$csvFileRes = fopen($csvFile, "w+");
|
198 |
|
199 |
+
while (!feof($fileHandler)) {
|
200 |
+
$row = fgets($fileHandler);
|
201 |
+
$oneLine = explode("\t", $row);
|
202 |
+
if ($oneLine[0]!= 'product_id' && $oneLine[0]!= ''){
|
203 |
+
try{
|
204 |
+
$prod_id = (!empty($oneLine[1])) ? $oneLine[1] : '';
|
205 |
+
$prod_img = (!empty($oneLine[6])) ? $oneLine[6] : $oneLine[5];
|
206 |
+
$prod_name = (!empty($oneLine[12])) ? $oneLine[12] : '';
|
207 |
+
$supplier_id = (!empty($oneLine[4])) ? $oneLine[4] : '';
|
208 |
+
$line = "$prod_id\t$supplier_id\t$prod_name\t$prod_img\n";
|
209 |
+
fwrite($csvFileRes, $line);
|
210 |
+
}catch(Exception $e){
|
211 |
+
Mage::log("connector issue: {$e->getMessage()}");
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
// write csv file into temp table
|
217 |
+
$connection->query('LOAD DATA LOCAL INFILE "'.$csvFile.'" INTO TABLE '.$tableName.'_temp ( prod_id, supplier_id, prod_name, prod_img )');
|
218 |
+
$connection->query("DROP TABLE IF EXISTS `".$tableName."_old`");
|
219 |
+
$connection->query("rename table `".$tableName."` to `".$tableName."_old`, `".$tableName."_temp` to ".$tableName);
|
220 |
+
$connection->commit();
|
221 |
+
fclose($fileHandler);
|
222 |
+
unlink($csvFile);
|
223 |
+
}
|
224 |
+
} catch (Exception $e) {
|
225 |
+
$connection->rollBack();
|
226 |
+
throw new Exception("Icecat Import Terminated: {$e->getMessage()}");
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* unzip Uploaded file
|
232 |
+
*/
|
233 |
+
private function unzipFile(){
|
234 |
+
$gz = gzopen ( $this->_productFile, 'rb' );
|
235 |
+
if (file_exists($this->XMLfile)){
|
236 |
+
unlink($this->XMLfile);
|
237 |
+
}
|
238 |
+
$fileToWrite = @fopen($this->XMLfile, 'w+');
|
239 |
+
if (!$fileToWrite){
|
240 |
+
$this->errorMessage = 'Unable to open output txt file. Please remove all *.txt files from '.
|
241 |
+
Mage::getBaseDir('var'). $this->_connectorDir .'folder';
|
242 |
+
return false;
|
243 |
+
}
|
244 |
+
while (!gzeof($gz)) {
|
245 |
+
$buffer = gzgets($gz, 100000);
|
246 |
+
fputs($fileToWrite, $buffer) ;
|
247 |
+
}
|
248 |
+
gzclose ($gz);
|
249 |
+
fclose($fileToWrite);
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Process downloading files
|
254 |
+
* @param string $destinationFile
|
255 |
+
* @param string $loadUrl
|
256 |
+
*/
|
257 |
+
private function downloadFile($destinationFile, $loadUrl){
|
258 |
+
$userName = Mage::getStoreConfig('icecat_root/icecat/login');
|
259 |
+
$userPass = Mage::getStoreConfig('icecat_root/icecat/password');
|
260 |
+
$fileToWrite = @fopen($destinationFile, 'w+');
|
261 |
+
|
262 |
+
try{
|
263 |
+
$webClient = new Zend_Http_Client();
|
264 |
+
$webClient->setUri($loadUrl);
|
265 |
+
$webClient->setConfig(array('maxredirects' => 0, 'timeout' => 60));
|
266 |
+
$webClient->setMethod(Zend_Http_Client::GET);
|
267 |
+
$webClient->setHeaders('Content-Type: text/xml; charset=UTF-8');
|
268 |
+
$webClient->setAuth($userName, $userPass, Zend_Http_CLient::AUTH_BASIC);
|
269 |
+
$response = $webClient->request('GET');
|
270 |
+
if ($response->isError()){
|
271 |
+
throw new Exception('<br>ERROR Occured.<br>Response Status: '.$response->getStatus()."<br>Response Message: ".$response->getMessage());
|
272 |
+
}
|
273 |
+
}
|
274 |
+
catch (Exception $e) {
|
275 |
+
throw new Exception("Warning: cannot connect to ICEcat. {$e->getMessage()}");
|
276 |
+
}
|
277 |
+
$resultString = $response->getBody();
|
278 |
+
fwrite($fileToWrite, $resultString);
|
279 |
+
fclose($fileToWrite);
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Prepares file and folder for futur download
|
284 |
+
* @param string $fileName
|
285 |
+
*/
|
286 |
+
protected function _prepareFile($fileName){
|
287 |
+
$varDir = Mage::getBaseDir('var') . $this->_connectorDir;
|
288 |
+
$filePath = $varDir . $fileName;
|
289 |
+
if (!is_dir($varDir)){
|
290 |
+
mkdir($varDir, 0777, true);
|
291 |
+
}
|
292 |
+
if (file_exists($filePath)){
|
293 |
+
unlink($filePath);
|
294 |
+
}
|
295 |
+
return $filePath;
|
296 |
+
}
|
297 |
}
|
298 |
?>
|
app/code/local/Bintime/Icecatimport/Model/System/Config/Descriptionpriority.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bintime_Icecatimport_Model_System_Config_Descriptionpriority
|
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/system.xml
CHANGED
@@ -1,79 +1,97 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
</config>
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<config>
|
3 |
+
<sections>
|
4 |
+
<icecat_root translate="label" module="catalog">
|
5 |
+
<class>separator-top</class>
|
6 |
+
<label>Icecat Live!</label>
|
7 |
+
<tab>catalog</tab>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>200</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>1</show_in_store>
|
13 |
+
<groups>
|
14 |
+
<icecat translate="label">
|
15 |
+
<label>Icecat Live! Settings</label>
|
16 |
+
<frontend_type>text</frontend_type>
|
17 |
+
<sort_order>50</sort_order>
|
18 |
+
<show_in_default>1</show_in_default>
|
19 |
+
<show_in_website>1</show_in_website>
|
20 |
+
<show_in_store>1</show_in_store>
|
21 |
+
<fields>
|
22 |
+
<login translate="label">
|
23 |
+
<label>Icecat User name</label>
|
24 |
+
<frontend_type>text</frontend_type>
|
25 |
+
<sort_order>10</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>1</show_in_website>
|
28 |
+
<show_in_store>1</show_in_store>
|
29 |
+
</login>
|
30 |
+
<password translate="label">
|
31 |
+
<label>Icecat Password</label>
|
32 |
+
<frontend_type>text</frontend_type>
|
33 |
+
<sort_order>20</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>1</show_in_store>
|
37 |
+
</password>
|
38 |
+
<icecat_type translate="label">
|
39 |
+
<label>Subscription level</label>
|
40 |
+
<frontend_type>select</frontend_type>
|
41 |
+
<source_model>icecatimport/system_config_subscription</source_model>
|
42 |
+
<sort_order>25</sort_order>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<show_in_website>1</show_in_website>
|
45 |
+
<show_in_store>1</show_in_store>
|
46 |
+
</icecat_type>
|
47 |
+
<language translate="label">
|
48 |
+
<label>Language</label>
|
49 |
+
<frontend_type>select</frontend_type>
|
50 |
+
<source_model>icecatimport/system_config_locales</source_model>
|
51 |
+
<sort_order>30</sort_order>
|
52 |
+
<show_in_default>1</show_in_default>
|
53 |
+
<show_in_website>1</show_in_website>
|
54 |
+
<show_in_store>1</show_in_store>
|
55 |
+
</language>
|
56 |
+
<sku_field translate="label">
|
57 |
+
<label>MPN</label>
|
58 |
+
<frontend_type>select</frontend_type>
|
59 |
+
<source_model>icecatimport/system_config_attributes</source_model>
|
60 |
+
<sort_order>40</sort_order>
|
61 |
+
<show_in_default>1</show_in_default>
|
62 |
+
<show_in_website>1</show_in_website>
|
63 |
+
<show_in_store>1</show_in_store>
|
64 |
+
</sku_field>
|
65 |
+
<manufacturer translate="label">
|
66 |
+
<label>Manufacturer Name</label>
|
67 |
+
<frontend_type>select</frontend_type>
|
68 |
+
<source_model>icecatimport/system_config_attributes</source_model>
|
69 |
+
<sort_order>50</sort_order>
|
70 |
+
<show_in_default>1</show_in_default>
|
71 |
+
<show_in_website>1</show_in_website>
|
72 |
+
<show_in_store>1</show_in_store>
|
73 |
+
</manufacturer>
|
74 |
+
<ean_code translate="label">
|
75 |
+
<label>Ean Code</label>
|
76 |
+
<frontend_type>select</frontend_type>
|
77 |
+
<source_model>icecatimport/system_config_attributes</source_model>
|
78 |
+
<sort_order>60</sort_order>
|
79 |
+
<show_in_default>1</show_in_default>
|
80 |
+
<show_in_website>1</show_in_website>
|
81 |
+
<show_in_store>1</show_in_store>
|
82 |
+
</ean_code>
|
83 |
+
<descript_priority translate="label">
|
84 |
+
<label>Use Description from </label>
|
85 |
+
<frontend_type>select</frontend_type>
|
86 |
+
<source_model>icecatimport/system_config_descriptionpriority</source_model>
|
87 |
+
<sort_order>70</sort_order>
|
88 |
+
<show_in_default>1</show_in_default>
|
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>
|
95 |
+
</icecat_root>
|
96 |
+
</sections>
|
97 |
</config>
|
app/code/local/Bintime/Icecatimport/sql/icecatimport_setup/mysql4-install-0.1.0.php
CHANGED
@@ -20,4 +20,5 @@ $installer->run("
|
|
20 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bintime Connector supplier mapping table';
|
21 |
|
22 |
");
|
|
|
23 |
$installer->endSetup();
|
20 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bintime Connector supplier mapping table';
|
21 |
|
22 |
");
|
23 |
+
|
24 |
$installer->endSetup();
|
package.xml
CHANGED
@@ -1,23 +1,24 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>IcecatLive</name>
|
4 |
-
<version>1.
|
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
|
12 |
-
-
|
13 |
-
- Added
|
14 |
-
-
|
15 |
-
- Fixed
|
16 |
-
- Fixed
|
|
|
17 |
<authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
|
18 |
-
<date>2012-
|
19 |
-
<time>
|
20 |
-
<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="
|
21 |
<compatible/>
|
22 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
23 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>IcecatLive</name>
|
4 |
+
<version>1.2.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
|
12 |
+
- Added support of Multilanguage stores
|
13 |
+
- Added new setting Description
|
14 |
+
- Fixed problems with Icecat names
|
15 |
+
- Fixed problems with images on product listing/shopping cart.
|
16 |
+
- Fixed problems with correct displaying attributes on product detail page
|
17 |
+
- Fixed problems with description on product detail page</notes>
|
18 |
<authors><author><name>IceShop</name><user>IceShop</user><email>support@iceshop.nl</email></author></authors>
|
19 |
+
<date>2012-10-03</date>
|
20 |
+
<time>14:19:01</time>
|
21 |
+
<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>
|
22 |
<compatible/>
|
23 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
24 |
</package>
|