Version Notes
Supporting v2 type of unbxd field
Download this release
Release Info
Developer | ananthesh |
Extension | unbxd_feedconnector |
Version | 1.0.10 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.10
- app/code/local/Unbxd/Datafeeder/.DS_Store +0 -0
- app/code/local/Unbxd/Datafeeder/Block/Index.php +1 -2
- app/code/local/Unbxd/Datafeeder/Helper/UnbxdIndexingHelper.php +29 -563
- app/code/local/Unbxd/Datafeeder/Model/Attribute.php +1 -1
- app/code/local/Unbxd/Datafeeder/Model/Feed/Feedcreator.php +119 -17
- app/code/local/Unbxd/Datafeeder/Model/Feed/Feedmanager.php +52 -6
- app/code/local/Unbxd/Datafeeder/Model/Feed/Filemanager.php +8 -0
- app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Productbuilder.php +45 -13
- app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Schemabuilder.php +11 -2
- app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Taxonomybuilder.php +187 -0
- app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf.php +4 -1
- app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field.php +14 -13
- app/code/local/Unbxd/Datafeeder/Model/Mysql4/Product/Collection.php +16 -0
- app/code/local/Unbxd/Datafeeder/Model/Observer.php +89 -0
- app/code/local/Unbxd/Datafeeder/controllers/ConfigController.php +7 -0
- app/code/local/Unbxd/Datafeeder/etc/config.xml +1 -1
- app/code/local/Unbxd/Datafeeder/{Helper → sql}/.DS_Store +0 -0
- app/design/adminhtml/base/default/template/datafeeder/conf.phtml +16 -11
- package.xml +4 -4
app/code/local/Unbxd/Datafeeder/.DS_Store
CHANGED
Binary file
|
app/code/local/Unbxd/Datafeeder/Block/Index.php
CHANGED
@@ -5,8 +5,7 @@ class Unbxd_Datafeeder_Block_Index extends Mage_Adminhtml_Block_Template
|
|
5 |
{
|
6 |
public function getFullindexFormAction()
|
7 |
{
|
8 |
-
|
9 |
-
return Mage::getUrl('*/*/fullindex', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
|
10 |
}
|
11 |
|
12 |
public function getTaxonomyUploadFormAction(){
|
5 |
{
|
6 |
public function getFullindexFormAction()
|
7 |
{
|
8 |
+
return Mage::getUrl('*/config/index', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
|
|
|
9 |
}
|
10 |
|
11 |
public function getTaxonomyUploadFormAction(){
|
app/code/local/Unbxd/Datafeeder/Helper/UnbxdIndexingHelper.php
CHANGED
@@ -23,6 +23,14 @@
|
|
23 |
// Feed unlock interval
|
24 |
//LOCK_TIMEOUT = 60 * 30;
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
public function __construct(){
|
27 |
$this->logFile = Mage::getBaseDir('log').DS.'generic.log';
|
28 |
$this->file = Mage::getBaseDir('tmp').DS.'unbxdFeed.xml';
|
@@ -38,61 +46,6 @@
|
|
38 |
$this->log("fields are " .json_encode($this->fields));
|
39 |
}
|
40 |
|
41 |
-
/**
|
42 |
-
* Function to create a file
|
43 |
-
*/
|
44 |
-
private function createXmlFile(){
|
45 |
-
try{
|
46 |
-
$f=fopen($this->file,'w');
|
47 |
-
|
48 |
-
fclose($f);
|
49 |
-
if(!file_exists($this->file)) {
|
50 |
-
$this->log("UNBXD_MODULE:Couldn't create the file");
|
51 |
-
return false;
|
52 |
-
}
|
53 |
-
$this->log("UNBXD_MODULE: created the file");
|
54 |
-
return true;
|
55 |
-
} catch (Exception $ex) {
|
56 |
-
$this->log("UNBXD_MODULE:Error while creating the file");
|
57 |
-
$this->log($ex->getMessage());
|
58 |
-
return false;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Function to append the contents to the file
|
64 |
-
*/
|
65 |
-
private function appendTofile($content){
|
66 |
-
try{
|
67 |
-
|
68 |
-
if(file_put_contents($this->file, $content, FILE_APPEND)) {
|
69 |
-
return true;
|
70 |
-
} else {
|
71 |
-
return false;
|
72 |
-
}
|
73 |
-
} catch(Exception $ex) {
|
74 |
-
$this->log("UNBXD_MODULE:Error while appending the contents to feed file");
|
75 |
-
$this->log($ex->getMessage());
|
76 |
-
return false;
|
77 |
-
}
|
78 |
-
}
|
79 |
-
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Function to create a file
|
83 |
-
*/
|
84 |
-
private function createLogFile(){
|
85 |
-
try {
|
86 |
-
$f=fopen($this->logFile,'w');
|
87 |
-
fclose($f);
|
88 |
-
return true;
|
89 |
-
} catch (Exception $ex) {
|
90 |
-
error_log("UNBXD_MODULE:Error while creating the file");
|
91 |
-
error_log($ex->getMessage());
|
92 |
-
return false;
|
93 |
-
}
|
94 |
-
}
|
95 |
-
|
96 |
/**
|
97 |
* Function to appened the contents to the file
|
98 |
*/
|
@@ -112,178 +65,6 @@
|
|
112 |
return false;
|
113 |
}
|
114 |
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Function to delete the file
|
118 |
-
*/
|
119 |
-
private function deleteFile(){
|
120 |
-
unlink($this->file);
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* function to get the file name
|
125 |
-
*/
|
126 |
-
private function getFile(){
|
127 |
-
return $this->file;
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
* Write Header contents to the file
|
132 |
-
*
|
133 |
-
*/
|
134 |
-
private function writeXmlHeaderContents($operation){
|
135 |
-
$headerContent="<feed>"."<taxonomyname>".$this->tax.
|
136 |
-
"</taxonomyname><username>unbxd</username>".
|
137 |
-
"<feedname>feed</feedname>".
|
138 |
-
"<entry>"."<data>" .
|
139 |
-
"<unbxdActionType>".$operation.
|
140 |
-
"</unbxdActionType>"."<products>";
|
141 |
-
|
142 |
-
return $this->appendTofile($headerContent);
|
143 |
-
|
144 |
-
}
|
145 |
-
|
146 |
-
/**
|
147 |
-
* function to append the xml footer contents to the file
|
148 |
-
*
|
149 |
-
*/
|
150 |
-
private function writeXmlFooterContents(){
|
151 |
-
$footerContent="</products></data></entry></feed>";
|
152 |
-
return $this->appendTofile($footerContent);
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* function to append the product contents to the file
|
157 |
-
*/
|
158 |
-
private function writeXmlProductContents($fromdate,$todate,$site,$operation,$ids){
|
159 |
-
|
160 |
-
|
161 |
-
$collection=$this->getCatalogCollection($fromdate,$todate,$site,$operation,$ids);
|
162 |
-
// get total size
|
163 |
-
//set the time limit to infinite
|
164 |
-
set_time_limit(0);
|
165 |
-
$pageNum = 0;
|
166 |
-
$this->log('started writing products');
|
167 |
-
|
168 |
-
while(true){
|
169 |
-
$collection->clear();
|
170 |
-
$collection->getSelect()->limit($this->PAGE_SIZE, ($pageNum++) * $this->PAGE_SIZE);
|
171 |
-
$collection->load();
|
172 |
-
echo "<pre>";print_r($collection);echo "</pre>";
|
173 |
-
if(count($collection) == 0){
|
174 |
-
if($pageNum == 1){
|
175 |
-
$this->log("No products found");
|
176 |
-
return false;
|
177 |
-
}
|
178 |
-
break;
|
179 |
-
}
|
180 |
-
$content=$this->getCollectionInXML($collection, $operation);
|
181 |
-
$status=$this->appendTofile($content);
|
182 |
-
if(!$status){
|
183 |
-
return false;
|
184 |
-
}
|
185 |
-
$this->log('Added '.($pageNum) * $pageSize.' products');
|
186 |
-
}
|
187 |
-
|
188 |
-
$this->log('Added all products');
|
189 |
-
return true;
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
** This method iterates over the collection and builds the xml for product object
|
194 |
-
**
|
195 |
-
**/
|
196 |
-
private function getCollectionInXML($collection, $operation){
|
197 |
-
|
198 |
-
$content='';
|
199 |
-
$count=0;
|
200 |
-
foreach($collection as $product){
|
201 |
-
$count++;
|
202 |
-
$content=$content.'<product>';
|
203 |
-
$content=$content.$this->getProductInXML($product, $operation);
|
204 |
-
$content=$content.'</product>';
|
205 |
-
}
|
206 |
-
|
207 |
-
return $content;
|
208 |
-
}
|
209 |
-
|
210 |
-
/**
|
211 |
-
** This method builds xml string, given the product object
|
212 |
-
**
|
213 |
-
**/
|
214 |
-
private function getProductInXML($product, $operation){
|
215 |
-
$content='';
|
216 |
-
if($operation != "add"){
|
217 |
-
return $this->getAttributesInXML('uniqueId',$product->getData('entity_id'));
|
218 |
-
}
|
219 |
-
|
220 |
-
foreach($product->getData('') as $columnHeader=>$columndata){
|
221 |
-
|
222 |
-
if(!in_array($columnHeader, $this->fields)) {
|
223 |
-
continue;
|
224 |
-
}
|
225 |
-
if(is_null($columndata)|| !isset($columndata) || $columndata==""){
|
226 |
-
continue;
|
227 |
-
}
|
228 |
-
if($columnHeader=="entity_id"){
|
229 |
-
$content=$content. $this->getAttributesInXML('uniqueId',$columndata);
|
230 |
-
}
|
231 |
-
if($columnHeader=="name"){
|
232 |
-
$content=$content. $this->getAttributesInXML('productname',$columndata);
|
233 |
-
}
|
234 |
-
if($columnHeader=="small_image"){
|
235 |
-
$content=$content. $this->getAttributesInXML('image_url',$columndata);
|
236 |
-
}
|
237 |
-
|
238 |
-
if($columnHeader=="entity_id"){
|
239 |
-
$content=$content. $this->getAttributesInXML('uniqueId',$columndata);
|
240 |
-
}
|
241 |
-
if($columnHeader == "visibility") {
|
242 |
-
$content = $content.$this->getAttributesInXML('unbxdVisibility', $columndata);
|
243 |
-
}
|
244 |
-
if($columnHeader=="url_path"){
|
245 |
-
$content=$content. $this->getAttributesInXML('url', Mage::getUrl('').$columndata);
|
246 |
-
$content=$content. $this->getAttributesInXML('url_path', Mage::getUrl('').$columndata);
|
247 |
-
} else if( $this->isMultiSelect($columnHeader) && $columnHeader != "status"){
|
248 |
-
$data = explode(",", $columndata);
|
249 |
-
$attributeModel = Mage::getResourceSingleton("datafeeder/attribute");
|
250 |
-
foreach( $data as $eachdata){
|
251 |
-
$attributeValue = $attributeModel ->getAttributeValue($columnHeader, trim($eachdata), $product);
|
252 |
-
$value = $value .$this->getAttributesInXML($columnHeader,$attributeModel ->getAttributeValue($columnHeader, trim($eachdata), $product));
|
253 |
-
if(isset($this->filterable[$columnHeader]) && ($this->filterable[$columnHeader] == 1) && isset($attributeValue) && $attributeValue != ""){
|
254 |
-
$value = $value.$this->getAttributesInXML($columnHeader."_id", trim($eachdata));
|
255 |
-
}
|
256 |
-
}
|
257 |
-
} else if($columnHeader == "created_at" ||$columnHeader == "updated_at") {
|
258 |
-
$tokens = explode(" ",$columndata);
|
259 |
-
$columndata =$tokens[0].'T'.$tokens[1].'Z';
|
260 |
-
$value =$this->getAttributesInXML($columnHeader,$columndata);
|
261 |
-
} else if($columnHeader == "category_id"){
|
262 |
-
if(!isset($columndata)){
|
263 |
-
continue;
|
264 |
-
}
|
265 |
-
$categoryIds = explode(",",$columndata);
|
266 |
-
foreach($categoryIds as $categoryId){
|
267 |
-
$value = $value.$this->getAttributesInXML($columnHeader, trim($categoryId));
|
268 |
-
$value = $value.$this->getAttributesInXML("unbxdTaxonomyId",trim($categoryId));
|
269 |
-
$value = $value.$this->getAttributesInXML("category",$this->getCategoryName(trim($categoryId)));
|
270 |
-
}
|
271 |
-
|
272 |
-
} else if (is_array($columndata)){
|
273 |
-
$value = $this->getArrayAttributesInXML($columnHeader,$columndata);
|
274 |
-
} else if ($columndata instanceof Varien_Object){
|
275 |
-
$value = $this->getArrayAttributesInXML($columnHeader,$columndata->getData());
|
276 |
-
} else if ( !isset($value) || $value == ""){
|
277 |
-
$value =$this->getAttributesInXML($columnHeader, $columndata);
|
278 |
-
}
|
279 |
-
$content = $content.$value;
|
280 |
-
$value = "";
|
281 |
-
}
|
282 |
-
|
283 |
-
$content=$content.$this->getCategoryAttribute($product);
|
284 |
-
$content=$content.$this->getAttributesInXML('store','default');
|
285 |
-
return $content;
|
286 |
-
}
|
287 |
|
288 |
/*
|
289 |
* function to check whether the field is a multiSelect/select or not,
|
@@ -291,6 +72,9 @@
|
|
291 |
* where it fetches from the local variable, which holds the information of field to fieldType mapping
|
292 |
*/
|
293 |
public function isMultiSelect($attributeName = ""){
|
|
|
|
|
|
|
294 |
if($this->getFieldType($attributeName) == "select" || $this->getFieldType($attributeName) == "multiselect" || $attributeName == "categoryIds"){
|
295 |
return true;
|
296 |
}
|
@@ -318,161 +102,25 @@
|
|
318 |
}
|
319 |
return $this->categoryMap[$category_id];
|
320 |
}
|
321 |
-
|
322 |
-
/**
|
323 |
-
* Method to get stock attribute in xml given the product
|
324 |
-
*/
|
325 |
-
private function getStockAttribute($product){
|
326 |
-
$model = Mage::getModel('catalog/product');
|
327 |
-
$_product = $model->load($product->getId());
|
328 |
-
$stocklevel = Mage::getModel('cataloginventory/stock_item')
|
329 |
-
->loadByProduct($product)->getQty();
|
330 |
-
|
331 |
-
$content=$this->getAttributesInXML("stock",$stocklevel);
|
332 |
-
|
333 |
-
if($stocklevel > 0){
|
334 |
-
$content=$content.$this->getAttributesInXML("Instock","1");
|
335 |
-
}
|
336 |
-
else{
|
337 |
-
$content=$content.$this->getAttributesInXML("Instock","0");
|
338 |
-
}
|
339 |
-
return $content;
|
340 |
-
}
|
341 |
-
|
342 |
-
/**
|
343 |
-
* method to get category content in xml given the product object
|
344 |
-
*/
|
345 |
-
private function getCategoryAttribute($product){
|
346 |
-
$cats = $product->getCategoryIds();
|
347 |
-
$categoryId=array();
|
348 |
-
$category=array();
|
349 |
-
$content = "";
|
350 |
-
foreach ($cats as $category_id) {
|
351 |
-
|
352 |
-
$_cat = $this->getCategory($category_id);
|
353 |
-
$categoryId[]=$category_id;
|
354 |
-
$category[]=$_cat->getName();
|
355 |
-
}
|
356 |
-
|
357 |
-
$content=$content.$this->getArrayAttributesInXML("categoryIds",$categoryId);
|
358 |
-
$content=$content.$this->getArrayAttributesInXML("unbxdTaxonomyId",$categoryId);
|
359 |
-
$content=$content.$this->getArrayAttributesInXML("category",$category);
|
360 |
-
return $content;
|
361 |
-
}
|
362 |
-
|
363 |
-
/**
|
364 |
-
* method to get the xml content given the fieldname and array
|
365 |
-
*/
|
366 |
-
private function getArrayAttributesInXML($columnHeader,$columndata){
|
367 |
-
$content='';
|
368 |
-
|
369 |
-
foreach($columndata as $element){
|
370 |
-
$content=$content.$this->getAttributesInXML($columnHeader,$element);
|
371 |
-
}
|
372 |
-
|
373 |
-
return $content;
|
374 |
-
}
|
375 |
-
|
376 |
-
/**
|
377 |
-
* method to get the xml content given the fieldname and value
|
378 |
-
*/
|
379 |
-
private function getAttributesInXML($columnHeader,$columndata){
|
380 |
-
|
381 |
-
$columnHeader=$this->_escapeXMLHeader($columnHeader);
|
382 |
-
$content = $this->_escapeXMLValue($columndata);
|
383 |
-
$content = iconv("ISO-8859-1", "UTF-8", $content);
|
384 |
-
if($content != '' && $columnHeader != ''){
|
385 |
-
return '<'.$columnHeader.'>'.$content.'</'.$columnHeader.'>';
|
386 |
-
}else{
|
387 |
-
return '';
|
388 |
-
}
|
389 |
-
}
|
390 |
-
|
391 |
-
/**
|
392 |
-
* method to escape the xml header contents
|
393 |
-
*/
|
394 |
-
private function _escapeXMLHeader($columnHeader){
|
395 |
-
if(is_numeric(substr($columnHeader,0,1))){
|
396 |
-
$columnHeader ='_'.$columnHeader;
|
397 |
-
}
|
398 |
-
return str_replace(' ','_',$columnHeader);
|
399 |
-
}
|
400 |
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
$characterWithSpecialMeaningInXML =true;
|
420 |
-
} else {
|
421 |
-
$characterWithSpecialMeaningInXML =false;
|
422 |
-
}
|
423 |
-
if ($controlCharacter || $characterWithSpecialMeaningInXML || $unicodeButNotAscii) {
|
424 |
-
$encryptedString = $encryptedString . "&#" . (ord($char)) . ";" ;
|
425 |
-
} else {
|
426 |
-
$encryptedString = $encryptedString.$char;
|
427 |
-
}
|
428 |
-
}
|
429 |
-
return $encryptedString;
|
430 |
-
}
|
431 |
-
|
432 |
-
/**
|
433 |
-
* method to get the catalog collection
|
434 |
-
*
|
435 |
-
*/
|
436 |
-
private function getCatalogCollection($fromdate,$todate,$site,$operation,$ids) {
|
437 |
-
try{
|
438 |
-
if ($operation == "add") {
|
439 |
-
// select all the attributes
|
440 |
-
$website =Mage::getModel("core/website")->setName($site);
|
441 |
-
$visiblityCondition = array('in' => array(4));
|
442 |
-
|
443 |
-
$collection = Mage::getResourceModel('catalog/product_collection')
|
444 |
-
->addWebsiteFilter($this->validateSite($site))
|
445 |
-
->addAttributeToFilter('status',1)
|
446 |
-
->joinField("qty", "cataloginventory_stock_item", 'qty', 'product_id=entity_id', null, 'left')
|
447 |
-
->addAttributeToSelect('*')
|
448 |
-
->addAttributeToFilter('visibility',$visiblityCondition);
|
449 |
-
|
450 |
-
if(sizeof($ids) > 0){
|
451 |
-
$condition = array('in' => $ids);
|
452 |
-
$collection=$collection->addAttributeToFilter('entity_id',$condition);
|
453 |
-
}
|
454 |
-
} else {
|
455 |
-
$collection = Mage::getResourceModel('catalog/product_collection');
|
456 |
-
if(sizeof($ids) > 0) {
|
457 |
-
$condition = array('in' => $ids);
|
458 |
-
$collection = $collection->addAttributeToFilter('entity_id',$condition)->addAttributeToSelect('entity_id');
|
459 |
-
}
|
460 |
-
}
|
461 |
-
|
462 |
-
$this->log($collection->getSelect());
|
463 |
-
return $collection;
|
464 |
-
} catch(Exception $e) {
|
465 |
-
$this->log($e->getMessage());
|
466 |
-
}
|
467 |
-
}
|
468 |
-
|
469 |
-
/**
|
470 |
-
* method to get all the attributes
|
471 |
-
**/
|
472 |
-
public function getAttributes(){
|
473 |
-
return Mage::getSingleton('eav/config')
|
474 |
-
->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
|
475 |
-
}
|
476 |
|
477 |
/**
|
478 |
* method to get field type of the field
|
@@ -495,188 +143,6 @@
|
|
495 |
$this->fieldType[$attribute->getAttributeCode()] = $attribute-> getFrontendInput();
|
496 |
}
|
497 |
}
|
498 |
-
|
499 |
-
/**
|
500 |
-
* method to get the zend date condition
|
501 |
-
*/
|
502 |
-
private function getDateCondition($fromdate,$todate){
|
503 |
-
return array('from'=>$fromdate,'to'=>$todate,'date'=>true,);
|
504 |
-
}
|
505 |
-
|
506 |
-
/**
|
507 |
-
* method to create the feed
|
508 |
-
**/
|
509 |
-
public function createFeed($fromdate,$todate,$site,$operation,$ids){
|
510 |
-
if($this->createXmlFile()){
|
511 |
-
$this->log("started writing header");
|
512 |
-
if(!$this->writeXmlHeaderContents($operation)){
|
513 |
-
return false;
|
514 |
-
}
|
515 |
-
$this->log('Added header contents');
|
516 |
-
try{
|
517 |
-
if(!$this->writeXmlProductContents($fromdate,$todate,$site,$operation,$ids)){
|
518 |
-
return false;
|
519 |
-
}
|
520 |
-
}catch(Exception $e){
|
521 |
-
$this->log($e->getMessage());
|
522 |
-
$this->log($e->getTraceAsString());
|
523 |
-
return false;
|
524 |
-
}
|
525 |
-
$this->log('Added products');
|
526 |
-
|
527 |
-
if(!$this->writeXmlFooterContents()){
|
528 |
-
return false;
|
529 |
-
}
|
530 |
-
} else {
|
531 |
-
return false;
|
532 |
-
}
|
533 |
-
return true;
|
534 |
-
}
|
535 |
-
|
536 |
-
/**
|
537 |
-
* method to initiate task after index
|
538 |
-
**/
|
539 |
-
private function _afterIndex(){
|
540 |
-
$this->deleteFile();
|
541 |
-
}
|
542 |
-
|
543 |
-
/**
|
544 |
-
* method to validate whether the site exists or not
|
545 |
-
**/
|
546 |
-
public function validateSite($site){
|
547 |
-
$sites=Mage::app()->getWebsites();
|
548 |
-
if( !isset($site) || $site == "") {
|
549 |
-
return false;
|
550 |
-
}
|
551 |
-
foreach( $sites as $eachSite){
|
552 |
-
if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
|
553 |
-
return $eachSite->getWebsiteId();
|
554 |
-
}
|
555 |
-
}
|
556 |
-
return -1;
|
557 |
-
}
|
558 |
-
|
559 |
-
/**
|
560 |
-
* method to set the feedName, log, apikey based on site Name
|
561 |
-
**/
|
562 |
-
public function setUnbxdConf($site)
|
563 |
-
{
|
564 |
-
$this->key = Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey");
|
565 |
-
$this->feedName = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/feed");
|
566 |
-
$this->tax = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/tax");
|
567 |
-
$this->logFile = Mage::getBaseDir('log').DS.substr($site,0,strrpos($site, ".")-1).'unbxdDataFeeder.log';
|
568 |
-
$this->file = Mage::getBaseDir('tmp').DS.substr($site,0,strrpos($site, ".")-1).'unbxdFeed.xml';
|
569 |
-
if (!$this->log("Feed uploading started")) {
|
570 |
-
error_log("No permission to write to " + Mage::getBaseDir('log'));
|
571 |
-
return false;
|
572 |
-
}
|
573 |
-
if(!isset($this->key) || $this->key == "" || $this->key == "empty"){
|
574 |
-
$this->log("api key not set");
|
575 |
-
return false;
|
576 |
-
}
|
577 |
-
if(!isset($this->feedName) || $this->feedName == "" || $this->feedName == "empty"){
|
578 |
-
$this->log("Feed Name not set");
|
579 |
-
return false;
|
580 |
-
}
|
581 |
-
$this->setFields($site);
|
582 |
-
return true;
|
583 |
-
}
|
584 |
-
|
585 |
-
/**
|
586 |
-
* method to initiate feed uploading to the unbxd servers
|
587 |
-
**/
|
588 |
-
public function indexUnbxdFeed($fromdate,$site,$operation = "add", $ids=array()){
|
589 |
-
|
590 |
-
$this->log('unbxd Datafeeder initiated');
|
591 |
-
// validatest the site
|
592 |
-
if($this->validateSite($site) == -1){
|
593 |
-
$this->log("Invalid site Name".$site);
|
594 |
-
return;
|
595 |
-
}
|
596 |
-
// set the basic
|
597 |
-
if(! $this->setUnbxdConf($site)){
|
598 |
-
return;
|
599 |
-
}
|
600 |
-
$todate =date('Y-m-d H:i:s');
|
601 |
-
|
602 |
-
// check the lock, that if already indexing is happening
|
603 |
-
if($this->checkSiteLock($site)){
|
604 |
-
$this->log('site '. $site.' has been locked');
|
605 |
-
$action=$site.'/status';
|
606 |
-
// lock the feed
|
607 |
-
Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'1');
|
608 |
-
// create the feed
|
609 |
-
|
610 |
-
$status=$this->createFeed($fromdate,$todate,$site,$operation,$ids);
|
611 |
-
$this->log('unbxd Datafeeder finished creating file');
|
612 |
-
|
613 |
-
if($status){
|
614 |
-
try{
|
615 |
-
// if successful push it to unbxd servers
|
616 |
-
$status=$this->pushFeed($site);
|
617 |
-
}catch(Exception $e){
|
618 |
-
$this->log($e->getMessage());
|
619 |
-
|
620 |
-
}
|
621 |
-
if($status){
|
622 |
-
Mage::getResourceSingleton("datafeeder/conf")->updateAction('Lastindex',$todate);
|
623 |
-
}
|
624 |
-
}
|
625 |
-
// unlock the feed once everything is completed
|
626 |
-
Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'0');
|
627 |
-
$this->log('site '. $site.' has been unlocked');
|
628 |
-
} else {
|
629 |
-
$this->log('Feed Uploading failed because site has been locked');
|
630 |
-
}
|
631 |
-
}
|
632 |
-
|
633 |
-
|
634 |
-
/**
|
635 |
-
* method to push the feed to the Unbxd server
|
636 |
-
**/
|
637 |
-
public function pushFeed($site){
|
638 |
-
$fields=array('file'=>'@'.$this->file.';filename=unbxdFeedRenamed.xml');
|
639 |
-
$header = array('Content-Type: multipart/form-data');
|
640 |
-
|
641 |
-
$url="feed.unbxdapi.com/upload/".$this->key."/".$this->feedName;
|
642 |
-
//clear the feed
|
643 |
-
$clearFeedUrl = "http://feed.unbxdapi.com/clearfeed.do?key=".$this->key."&feedName=".$this->feedName;
|
644 |
-
file_get_contents($clearFeedUrl);
|
645 |
-
$this->log('cleared the feed');
|
646 |
-
|
647 |
-
|
648 |
-
$ch = curl_init();
|
649 |
-
curl_setopt($ch, CURLOPT_URL,$url);
|
650 |
-
curl_setopt($ch, CURLOPT_POST,true);
|
651 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
|
652 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
653 |
-
try{
|
654 |
-
$this->log('pushing the feed');
|
655 |
-
// push the feed to the server
|
656 |
-
$response = curl_exec ($ch);
|
657 |
-
}catch(Exception $Ex){
|
658 |
-
$this->log($Ex->getMessage());
|
659 |
-
return false;
|
660 |
-
}
|
661 |
-
$this->log($response);
|
662 |
-
curl_close($ch);
|
663 |
-
return true;
|
664 |
-
}
|
665 |
-
|
666 |
-
/**
|
667 |
-
* method to check the status of the uploading
|
668 |
-
**/
|
669 |
-
public function checkSiteLock($site)
|
670 |
-
{
|
671 |
-
$value = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/status");
|
672 |
-
if($value == '0' || $value == 'empty'){
|
673 |
-
$this->log("true");
|
674 |
-
return true;
|
675 |
-
}else{
|
676 |
-
$this->log("false". $value);
|
677 |
-
return false;
|
678 |
-
}
|
679 |
-
}
|
680 |
}
|
681 |
?>
|
682 |
|
23 |
// Feed unlock interval
|
24 |
//LOCK_TIMEOUT = 60 * 30;
|
25 |
|
26 |
+
/**
|
27 |
+
* method to get all the attributes
|
28 |
+
**/
|
29 |
+
public function getAttributes(){
|
30 |
+
return Mage::getSingleton('eav/config')
|
31 |
+
->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
|
32 |
+
}
|
33 |
+
|
34 |
public function __construct(){
|
35 |
$this->logFile = Mage::getBaseDir('log').DS.'generic.log';
|
36 |
$this->file = Mage::getBaseDir('tmp').DS.'unbxdFeed.xml';
|
46 |
$this->log("fields are " .json_encode($this->fields));
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
/**
|
50 |
* Function to appened the contents to the file
|
51 |
*/
|
65 |
return false;
|
66 |
}
|
67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
/*
|
70 |
* function to check whether the field is a multiSelect/select or not,
|
72 |
* where it fetches from the local variable, which holds the information of field to fieldType mapping
|
73 |
*/
|
74 |
public function isMultiSelect($attributeName = ""){
|
75 |
+
if($attributeName == "status" || $attributeName == "visibility") {
|
76 |
+
return false;
|
77 |
+
}
|
78 |
if($this->getFieldType($attributeName) == "select" || $this->getFieldType($attributeName) == "multiselect" || $attributeName == "categoryIds"){
|
79 |
return true;
|
80 |
}
|
102 |
}
|
103 |
return $this->categoryMap[$category_id];
|
104 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
public function getCategoryOnLevel($category_ids, $level) {
|
107 |
+
if(!is_array($category_ids)) {
|
108 |
+
return array();
|
109 |
+
}
|
110 |
+
$categoryValues = array();
|
111 |
+
foreach($category_ids as $category_id) {
|
112 |
+
$category = $this->getCategory($category_id);
|
113 |
+
$parentIds = $category->getParentIds();
|
114 |
+
if(!is_null($category) && $category->getLevel() == $level + 1) {
|
115 |
+
$categoryValues = array_merge($categoryValues, array($category->getName()));
|
116 |
+
} else if ($category instanceof Mage_Catalog_Model_Category &&
|
117 |
+
is_array($parentIds) &&
|
118 |
+
(sizeof($parentIds) >0)) {
|
119 |
+
$categoryValues = array_merge($categoryValues, $this->getCategoryOnLevel($parentIds, $level));
|
120 |
+
}
|
121 |
+
}
|
122 |
+
return array_unique($categoryValues);
|
123 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
/**
|
126 |
* method to get field type of the field
|
143 |
$this->fieldType[$attribute->getAttributeCode()] = $attribute-> getFrontendInput();
|
144 |
}
|
145 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
?>
|
148 |
|
app/code/local/Unbxd/Datafeeder/Model/Attribute.php
CHANGED
@@ -14,7 +14,7 @@ class Unbxd_Datafeeder_Model_Attribute{
|
|
14 |
$this->attributeMap[$option["label"]] = $option["value"];
|
15 |
}
|
16 |
}
|
17 |
-
|
18 |
}
|
19 |
|
20 |
}
|
14 |
$this->attributeMap[$option["label"]] = $option["value"];
|
15 |
}
|
16 |
}
|
17 |
+
return array_key_exists($value, $this->attributeMap)?$this->attributeMap[$value]:NULL;
|
18 |
}
|
19 |
|
20 |
}
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Feedcreator.php
CHANGED
@@ -77,10 +77,23 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
77 |
return false;
|
78 |
}
|
79 |
|
80 |
-
|
|
|
81 |
$this->log("Error writing closing catalog tag");
|
82 |
return false;
|
83 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
return true;
|
85 |
}
|
86 |
|
@@ -109,6 +122,7 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
109 |
$collection->clear();
|
110 |
$collection->getSelect()->limit(self::PAGE_SIZE, ($pageNum++) * self::PAGE_SIZE);
|
111 |
$collection->load();
|
|
|
112 |
if(count($collection) == 0){
|
113 |
if($pageNum == 1){
|
114 |
$this->log("No products found");
|
@@ -129,7 +143,7 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
129 |
$this->log("Error while addings items");
|
130 |
return false;
|
131 |
}
|
132 |
-
$this->log('Added '.($pageNum) *
|
133 |
$firstLoop = false;
|
134 |
}
|
135 |
|
@@ -143,6 +157,57 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
143 |
return true;
|
144 |
}
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
private function setFields($site) {
|
148 |
$this->fields = Mage::getResourceSingleton('datafeeder/field')->getFieldMapping($site, true);
|
@@ -153,9 +218,26 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
153 |
$this->fields["entity_id"] = array(self::STATUS => 1,
|
154 |
self::DATA_TYPE => "text",
|
155 |
self::AUTOSUGGEST => 0 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
$this->fields["categoryIds"] = array(self::STATUS => 1,
|
157 |
self::DATA_TYPE => "text",
|
158 |
self::AUTOSUGGEST => 0 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
$this->fields = array_merge($this->fields, Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields());
|
161 |
}
|
@@ -167,20 +249,25 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
167 |
public function getCatalogCollection($fromdate,$todate,$site,$operation,$ids) {
|
168 |
try{
|
169 |
if ($operation == "add") {
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
->addAttributeToFilter('status',1)
|
177 |
-
->joinField("qty", "cataloginventory_stock_item", 'qty', 'product_id=entity_id', null, 'left')
|
178 |
-
->addAttributeToSelect('*')
|
179 |
-
->addAttributeToFilter('visibility',$visiblityCondition);
|
180 |
|
181 |
if(sizeof($ids) > 0){
|
182 |
$condition = array('in' => $ids);
|
183 |
-
$collection
|
184 |
}
|
185 |
} else {
|
186 |
$collection = Mage::getResourceModel('catalog/product_collection');
|
@@ -197,7 +284,6 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
197 |
}
|
198 |
}
|
199 |
|
200 |
-
|
201 |
/**
|
202 |
* Function to initialize to feed creation process
|
203 |
*/
|
@@ -216,17 +302,33 @@ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
|
|
216 |
/**
|
217 |
* method to validate whether the site exists or not
|
218 |
**/
|
219 |
-
|
220 |
$sites=Mage::app()->getWebsites();
|
221 |
if( !isset($site) || $site == "") {
|
222 |
return false;
|
223 |
}
|
224 |
foreach( $sites as $eachSite){
|
225 |
if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
|
226 |
-
return $eachSite
|
227 |
}
|
228 |
}
|
229 |
-
return
|
230 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
}
|
232 |
-
?>
|
77 |
return false;
|
78 |
}
|
79 |
|
80 |
+
|
81 |
+
if(!$this->appendTofile("}")) {
|
82 |
$this->log("Error writing closing catalog tag");
|
83 |
return false;
|
84 |
}
|
85 |
+
|
86 |
+
/*
|
87 |
+
if(!$this->writeTaxonomyContents($site)) {
|
88 |
+
return false;
|
89 |
+
}*/
|
90 |
+
|
91 |
+
if(!$this->appendTofile("}")) {
|
92 |
+
$this->log("Error writing closing feed tag");
|
93 |
+
return false;
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
return true;
|
98 |
}
|
99 |
|
122 |
$collection->clear();
|
123 |
$collection->getSelect()->limit(self::PAGE_SIZE, ($pageNum++) * self::PAGE_SIZE);
|
124 |
$collection->load();
|
125 |
+
Mage::getModel('cataloginventory/stock_status')->addStockStatusToProducts($collection);
|
126 |
if(count($collection) == 0){
|
127 |
if($pageNum == 1){
|
128 |
$this->log("No products found");
|
143 |
$this->log("Error while addings items");
|
144 |
return false;
|
145 |
}
|
146 |
+
$this->log('Added '.($pageNum) * self::PAGE_SIZE.' products');
|
147 |
$firstLoop = false;
|
148 |
}
|
149 |
|
157 |
return true;
|
158 |
}
|
159 |
|
160 |
+
private function writeTaxonomyContents($site){
|
161 |
+
|
162 |
+
$collection=$this->getTaxonomyMappingCollection();
|
163 |
+
// get total size
|
164 |
+
//set the time limit to infinite
|
165 |
+
ignore_user_abort(true);
|
166 |
+
set_time_limit(0);
|
167 |
+
$pageNum = 0;
|
168 |
+
$this->log('started writing taxonomy tree');
|
169 |
+
|
170 |
+
if(!$this->appendTofile(',"'. 'taxonomy' . '":{ "tree":[')) {
|
171 |
+
$this->log("Error while adding tree tag");
|
172 |
+
return false;
|
173 |
+
}
|
174 |
+
|
175 |
+
$content=Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_taxonomybuilder')->createTaxonomyFeed($site);
|
176 |
+
$status=$this->appendTofile($content);
|
177 |
+
|
178 |
+
if(!$status){
|
179 |
+
$this->log("Error while addings taxonomy");
|
180 |
+
return false;
|
181 |
+
}
|
182 |
+
|
183 |
+
if(!$this->appendTofile("]")) {
|
184 |
+
$this->log("Error writing closing tree tag");
|
185 |
+
return false;
|
186 |
+
}
|
187 |
+
|
188 |
+
if(!$this->appendTofile(',"mapping":[')) {
|
189 |
+
$this->log("Error writing opening mapping tag");
|
190 |
+
return false;
|
191 |
+
}
|
192 |
+
|
193 |
+
$content=Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_taxonomybuilder')->createMappingFeed($collection);
|
194 |
+
$status=$this->appendTofile($content);
|
195 |
+
|
196 |
+
if(!$status){
|
197 |
+
$this->log("Error while addings taxonomy mappings");
|
198 |
+
return false;
|
199 |
+
}
|
200 |
+
|
201 |
+
if(!$this->appendTofile(']}')) {
|
202 |
+
$this->log("Error writing closing mapping tag");
|
203 |
+
return false;
|
204 |
+
}
|
205 |
+
$this->log('Added all categories');
|
206 |
+
return true;
|
207 |
+
}
|
208 |
+
|
209 |
+
|
210 |
+
|
211 |
|
212 |
private function setFields($site) {
|
213 |
$this->fields = Mage::getResourceSingleton('datafeeder/field')->getFieldMapping($site, true);
|
218 |
$this->fields["entity_id"] = array(self::STATUS => 1,
|
219 |
self::DATA_TYPE => "text",
|
220 |
self::AUTOSUGGEST => 0 );
|
221 |
+
$this->fields["entity_idAssociated"] = array(self::STATUS => 1,
|
222 |
+
self::DATA_TYPE => "text",
|
223 |
+
self::AUTOSUGGEST => 0 );
|
224 |
+
$this->fields["uniqueIdAssociated"] = array(self::STATUS => 1,
|
225 |
+
self::DATA_TYPE => "text",
|
226 |
+
self::AUTOSUGGEST => 0 );
|
227 |
+
|
228 |
+
|
229 |
$this->fields["categoryIds"] = array(self::STATUS => 1,
|
230 |
self::DATA_TYPE => "text",
|
231 |
self::AUTOSUGGEST => 0 );
|
232 |
+
$this->fields["qty"] = array(self::STATUS => 1,
|
233 |
+
self::DATA_TYPE => "number",
|
234 |
+
self::AUTOSUGGEST => 0 );
|
235 |
+
$this->fields["qtyAssociated"] = array(self::STATUS => 1,
|
236 |
+
self::DATA_TYPE => "number",
|
237 |
+
self::AUTOSUGGEST => 0 );
|
238 |
+
$this->fields["final_price"] = array(self::STATUS => 1,
|
239 |
+
self::DATA_TYPE => "decimal",
|
240 |
+
self::AUTOSUGGEST => 0 );
|
241 |
|
242 |
$this->fields = array_merge($this->fields, Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields());
|
243 |
}
|
249 |
public function getCatalogCollection($fromdate,$todate,$site,$operation,$ids) {
|
250 |
try{
|
251 |
if ($operation == "add") {
|
252 |
+
$adapter = Mage::getSingleton("core/resource");
|
253 |
+
$_catalogInventoryTable = method_exists($adapter, 'getTableName')
|
254 |
+
? $adapter->getTableName('cataloginventory_stock_item'): 'catalog_category_product_index';
|
255 |
+
$website = $this->getWebsite($site);
|
256 |
+
if($website === false){
|
257 |
+
throw new Exception("Invalid website");
|
258 |
+
}
|
259 |
+
$collection = Mage::getResourceModel('datafeeder/product_collection')
|
260 |
+
->addWebsiteFilter($website->getWebsiteId())
|
261 |
+
->joinField("qty", $_catalogInventoryTable, 'qty', 'product_id=entity_id', null, 'left')
|
262 |
+
->addAttributeToSelect('*')
|
263 |
+
->addPriceData(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID, $website->getWebsiteId());
|
264 |
|
265 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
266 |
+
Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection);
|
|
|
|
|
|
|
|
|
267 |
|
268 |
if(sizeof($ids) > 0){
|
269 |
$condition = array('in' => $ids);
|
270 |
+
$collection->addAttributeToFilter('entity_id',$condition);
|
271 |
}
|
272 |
} else {
|
273 |
$collection = Mage::getResourceModel('catalog/product_collection');
|
284 |
}
|
285 |
}
|
286 |
|
|
|
287 |
/**
|
288 |
* Function to initialize to feed creation process
|
289 |
*/
|
302 |
/**
|
303 |
* method to validate whether the site exists or not
|
304 |
**/
|
305 |
+
private function getWebsite($site){
|
306 |
$sites=Mage::app()->getWebsites();
|
307 |
if( !isset($site) || $site == "") {
|
308 |
return false;
|
309 |
}
|
310 |
foreach( $sites as $eachSite){
|
311 |
if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
|
312 |
+
return $eachSite;
|
313 |
}
|
314 |
}
|
315 |
+
return false;
|
316 |
}
|
317 |
+
|
318 |
+
public function getTaxonomyMappingCollection() {
|
319 |
+
$reader = Mage::getSingleton('core/resource')->getConnection('core_read');
|
320 |
+
$adapter= Mage::getSingleton("core/resource");
|
321 |
+
$_productCategoryTable = method_exists($adapter, 'getTableName')
|
322 |
+
? $adapter->getTableName('catalog_category_product_index'): 'catalog_category_product_index';
|
323 |
+
$_productTable = method_exists($adapter, 'getTableName')
|
324 |
+
? $adapter->getTableName('catalog_product_entity'): 'catalog_product_entity';
|
325 |
+
|
326 |
+
return $reader->query("select {$_productCategoryTable}.product_id as entity_id,
|
327 |
+
GROUP_CONCAT({$_productCategoryTable}.category_id SEPARATOR ',') as category_id
|
328 |
+
FROM {$_productCategoryTable}
|
329 |
+
join {$_productTable} where {$_productCategoryTable}.product_id = {$_productTable}.entity_id
|
330 |
+
group by {$_productCategoryTable}.product_id");
|
331 |
+
}
|
332 |
+
|
333 |
}
|
334 |
+
?>
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Feedmanager.php
CHANGED
@@ -1,16 +1,19 @@
|
|
1 |
<?php
|
2 |
|
3 |
class Unbxd_Datafeeder_Model_Feed_Feedmanager {
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
/**
|
7 |
* method to push the feed to the Unbxd server
|
8 |
**/
|
9 |
-
public function pushFeed($site){
|
10 |
-
$fields=array('file'=>'@'.$
|
11 |
$header = array('Content-Type: multipart/form-data');
|
12 |
|
13 |
-
$url="http://feed.unbxdapi.com/upload/v2/".$this->key."/".$this->siteName."?fullimport=true";
|
14 |
|
15 |
$ch = curl_init();
|
16 |
curl_setopt($ch, CURLOPT_URL,$url);
|
@@ -48,8 +51,8 @@ class Unbxd_Datafeeder_Model_Feed_Feedmanager {
|
|
48 |
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
|
49 |
$result['header'] = substr($response, 0, $header_size);
|
50 |
$result['body'] = substr( $response, $header_size );
|
51 |
-
$result['http_code'] = curl_getinfo($
|
52 |
-
$result['last_url'] = curl_getinfo($
|
53 |
return $result;
|
54 |
}
|
55 |
|
@@ -120,7 +123,7 @@ class Unbxd_Datafeeder_Model_Feed_Feedmanager {
|
|
120 |
if($status){
|
121 |
try{
|
122 |
// if successful push it to unbxd servers
|
123 |
-
$status=$this->pushFeed($site);
|
124 |
}catch(Exception $e){
|
125 |
$this->log($e->getMessage());
|
126 |
|
@@ -155,5 +158,48 @@ class Unbxd_Datafeeder_Model_Feed_Feedmanager {
|
|
155 |
public function log($message) {
|
156 |
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log($message);
|
157 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
?>
|
1 |
<?php
|
2 |
|
3 |
class Unbxd_Datafeeder_Model_Feed_Feedmanager {
|
4 |
+
|
5 |
+
//Delete the file after uploading the feed
|
6 |
+
var $deleteIncrementalFeed = true;
|
7 |
|
8 |
|
9 |
/**
|
10 |
* method to push the feed to the Unbxd server
|
11 |
**/
|
12 |
+
public function pushFeed($site, $file, $fullimport=true){
|
13 |
+
$fields=array('file'=>'@'.$file.';filename=unbxdFeedRenamed.json');
|
14 |
$header = array('Content-Type: multipart/form-data');
|
15 |
|
16 |
+
$url="http://feed.unbxdapi.com/upload/v2/".$this->key."/".$this->siteName. ($fullimport?"?fullimport=true":"");
|
17 |
|
18 |
$ch = curl_init();
|
19 |
curl_setopt($ch, CURLOPT_URL,$url);
|
51 |
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
|
52 |
$result['header'] = substr($response, 0, $header_size);
|
53 |
$result['body'] = substr( $response, $header_size );
|
54 |
+
$result['http_code'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
55 |
+
$result['last_url'] = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
|
56 |
return $result;
|
57 |
}
|
58 |
|
123 |
if($status){
|
124 |
try{
|
125 |
// if successful push it to unbxd servers
|
126 |
+
$status=$this->pushFeed($site,$this->fileName);
|
127 |
}catch(Exception $e){
|
128 |
$this->log($e->getMessage());
|
129 |
|
158 |
public function log($message) {
|
159 |
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log($message);
|
160 |
}
|
161 |
+
|
162 |
+
public function processIncremental($fromdate,$site,$operation = "update", $ids=array()){
|
163 |
+
|
164 |
+
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log('Incremental feed upload initiated');
|
165 |
+
$date = new DateTime();
|
166 |
+
$this->incrementalFileName = Mage::getBaseDir('tmp').DS.str_replace(' ', '_',$site).$date->getTimestamp()."_Feed.json";
|
167 |
+
// validatest the site
|
168 |
+
if($this->validateSite($site) == -1){
|
169 |
+
$this->log("Invalid site Name".$site);
|
170 |
+
return;
|
171 |
+
}
|
172 |
+
// set the basic
|
173 |
+
if(! $this->init($site)){
|
174 |
+
$this->log("Site cannot be initiated");
|
175 |
+
return;
|
176 |
+
}
|
177 |
+
$todate =date('Y-m-d H:i:s');
|
178 |
+
|
179 |
+
$status=Mage::getSingleton('unbxd_datafeeder/feed_feedcreator')
|
180 |
+
->createFeed($this->incrementalFileName, $fromdate,$todate,$site,$operation,$ids);
|
181 |
+
|
182 |
+
$this->log('unbxd Datafeeder finished creating file');
|
183 |
+
|
184 |
+
if($status){
|
185 |
+
try{
|
186 |
+
// if successful push it to unbxd servers
|
187 |
+
$this->log("successfully completed incremental feed upload");
|
188 |
+
$status=$this->pushFeed($site,$this->incrementalFileName,false);
|
189 |
+
}catch(Exception $e){
|
190 |
+
$this->log($e->getMessage());
|
191 |
+
|
192 |
+
}
|
193 |
+
if($status){
|
194 |
+
Mage::getResourceSingleton("datafeeder/conf")->updateAction('Lastindex',$todate);
|
195 |
+
|
196 |
+
}
|
197 |
+
if($status && $this->deleteIncrementalFeed){
|
198 |
+
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->deleteFile($this->incrementalFileName);
|
199 |
+
|
200 |
+
|
201 |
+
}
|
202 |
+
}
|
203 |
+
}
|
204 |
}
|
205 |
?>
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Filemanager.php
CHANGED
@@ -70,5 +70,13 @@ class Unbxd_Datafeeder_Model_Feed_Filemanager {
|
|
70 |
return false;
|
71 |
}
|
72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
74 |
?>
|
70 |
return false;
|
71 |
}
|
72 |
}
|
73 |
+
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Function to delete the file
|
77 |
+
*/
|
78 |
+
public function deleteFile($file){
|
79 |
+
unlink($file);
|
80 |
+
}
|
81 |
}
|
82 |
?>
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Productbuilder.php
CHANGED
@@ -10,6 +10,7 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
10 |
const IMAGE_HEIGHT = "image_height";
|
11 |
const IMAGE_WIDTH = "image_width";
|
12 |
const GENERATE_IMAGE = "generate_image";
|
|
|
13 |
|
14 |
/*
|
15 |
* method to get the products in json
|
@@ -48,7 +49,8 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
48 |
}
|
49 |
|
50 |
if($columnHeader=="entity_id"){
|
51 |
-
$
|
|
|
52 |
}
|
53 |
|
54 |
if($columnHeader=="url_path"){
|
@@ -79,6 +81,8 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
79 |
$category = $this->getCategoryAttribute($product);
|
80 |
// adding the category
|
81 |
$productArray = $category + $productArray;
|
|
|
|
|
82 |
}
|
83 |
return $productArray;
|
84 |
}
|
@@ -91,17 +95,36 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
91 |
$categoryIds = array();
|
92 |
$category = array();
|
93 |
$categoryData = array();
|
94 |
-
$index = 0;
|
95 |
foreach ($cats as $categoryId) {
|
96 |
$_cat = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getCategory($categoryId);
|
|
|
|
|
|
|
97 |
$categoryName = $_cat->getName();
|
98 |
-
if($
|
99 |
-
|
100 |
-
$categoryData['catlevel' . $index . 'Name'] = $categoryName;
|
101 |
}
|
102 |
$categoryIds[] = (string)$categoryId;
|
103 |
$category[] = $categoryName;
|
104 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
$categoryData['categoryIds'] = $categoryIds;
|
106 |
$categoryData['category'] = $category;
|
107 |
return $categoryData;
|
@@ -116,7 +139,7 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
116 |
foreach($data as $eachdata){
|
117 |
$attributeValue = Mage::getResourceSingleton("datafeeder/attribute")
|
118 |
->getAttributeValue($fieldName, trim($eachdata), $product);
|
119 |
-
if(!is_null($attributeValue) && $attributeValue != "") {
|
120 |
$valueAsAnArray[] = $attributeValue;
|
121 |
}
|
122 |
}
|
@@ -132,13 +155,13 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
132 |
private function getImage($fieldName, $unbxdFieldName, $product, $fields) {
|
133 |
|
134 |
if($fields[$unbxdFieldName][self::GENERATE_IMAGE] == "1") {
|
|
|
135 |
try {
|
136 |
return (string)Mage::helper('catalog/image')->init($product, $fieldName)
|
137 |
->resize($fields[$unbxdFieldName][self::IMAGE_WIDTH],
|
138 |
$fields[$unbxdFieldName][self::IMAGE_HEIGHT]);
|
139 |
} catch (Exception $e) {
|
140 |
-
|
141 |
-
error_log("Error while fetching the image" . $e->getTraceAsString());
|
142 |
}
|
143 |
}
|
144 |
return $product->getData($fieldName);
|
@@ -170,13 +193,18 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
170 |
* gives the children in form of array
|
171 |
*/
|
172 |
public function addChildrens($product, $fields, $productArray) {
|
|
|
173 |
$type = $product->getData('type_id');
|
174 |
if ($type == "configurable" || $type == "grouped" ) {
|
175 |
$associatedProducts = array();
|
176 |
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
|
|
|
|
|
|
|
177 |
$childrens = $conf->getUsedProductCollection()
|
178 |
->addAttributeToSelect('*')
|
179 |
-
->addFilterByRequiredOptions()
|
|
|
180 |
foreach ($childrens as $children)
|
181 |
{
|
182 |
$childProduct = $this->getProduct($children, $fields, true);
|
@@ -203,7 +231,7 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
203 |
} else {
|
204 |
$product = $this->convertMultivalued($product, $fields);
|
205 |
}
|
206 |
-
$product = $this->convertDataType($product, $fields, $
|
207 |
return $product;
|
208 |
}
|
209 |
|
@@ -286,8 +314,12 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Dataf
|
|
286 |
*/
|
287 |
public function convertMultivalued($product, $fields = null) {
|
288 |
foreach($product as $field=>$value) {
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
|
|
291 |
$valueAsAnArray = array();
|
292 |
$valueAsAnArray[] = $value;
|
293 |
$product[$field] = $valueAsAnArray;
|
10 |
const IMAGE_HEIGHT = "image_height";
|
11 |
const IMAGE_WIDTH = "image_width";
|
12 |
const GENERATE_IMAGE = "generate_image";
|
13 |
+
const AVAILABILITY = "availability";
|
14 |
|
15 |
/*
|
16 |
* method to get the products in json
|
49 |
}
|
50 |
|
51 |
if($columnHeader=="entity_id"){
|
52 |
+
$uniqueIdField = 'uniqueId'.(($childProduct)?'Associated':'');
|
53 |
+
$productArray[$uniqueIdField] = $columndata;
|
54 |
}
|
55 |
|
56 |
if($columnHeader=="url_path"){
|
81 |
$category = $this->getCategoryAttribute($product);
|
82 |
// adding the category
|
83 |
$productArray = $category + $productArray;
|
84 |
+
$productArray[self::AVAILABILITY] =
|
85 |
+
$product->isSalable()? "true": "false";
|
86 |
}
|
87 |
return $productArray;
|
88 |
}
|
95 |
$categoryIds = array();
|
96 |
$category = array();
|
97 |
$categoryData = array();
|
|
|
98 |
foreach ($cats as $categoryId) {
|
99 |
$_cat = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getCategory($categoryId);
|
100 |
+
if($_cat == null) {
|
101 |
+
continue;
|
102 |
+
}
|
103 |
$categoryName = $_cat->getName();
|
104 |
+
if($categoryName == null || $categoryName == "") {
|
105 |
+
continue;
|
|
|
106 |
}
|
107 |
$categoryIds[] = (string)$categoryId;
|
108 |
$category[] = $categoryName;
|
109 |
+
}
|
110 |
+
$level1Categories = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
|
111 |
+
->getCategoryOnLevel($categoryIds, 1);
|
112 |
+
$level2Categories = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
|
113 |
+
->getCategoryOnLevel($categoryIds, 2);
|
114 |
+
$level3Categories = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
|
115 |
+
->getCategoryOnLevel($categoryIds, 3);
|
116 |
+
if(isset($level1Categories) && sizeof(array_values($level1Categories))> 0) {
|
117 |
+
$categories = array_values($level1Categories);
|
118 |
+
$categoryData['catlevel1Name'] = $categories[0];
|
119 |
+
}
|
120 |
+
if(isset($level2Categories) && sizeof(array_values($level2Categories)) > 0) {
|
121 |
+
$categories = array_values($level2Categories);
|
122 |
+
$categoryData['catlevel2Name'] = $categories[0];
|
123 |
+
}
|
124 |
+
if(isset($level3Categories) && sizeof(array_values($level3Categories)) > 0) {
|
125 |
+
$categories = array_values($level3Categories);
|
126 |
+
$categoryData['catlevel3Name'] = $categories[0];
|
127 |
+
}
|
128 |
$categoryData['categoryIds'] = $categoryIds;
|
129 |
$categoryData['category'] = $category;
|
130 |
return $categoryData;
|
139 |
foreach($data as $eachdata){
|
140 |
$attributeValue = Mage::getResourceSingleton("datafeeder/attribute")
|
141 |
->getAttributeValue($fieldName, trim($eachdata), $product);
|
142 |
+
if(!is_null($attributeValue) && $attributeValue != "" && attributeValue != "Use Config") {
|
143 |
$valueAsAnArray[] = $attributeValue;
|
144 |
}
|
145 |
}
|
155 |
private function getImage($fieldName, $unbxdFieldName, $product, $fields) {
|
156 |
|
157 |
if($fields[$unbxdFieldName][self::GENERATE_IMAGE] == "1") {
|
158 |
+
Mage::getDesign()->setArea('frontend');
|
159 |
try {
|
160 |
return (string)Mage::helper('catalog/image')->init($product, $fieldName)
|
161 |
->resize($fields[$unbxdFieldName][self::IMAGE_WIDTH],
|
162 |
$fields[$unbxdFieldName][self::IMAGE_HEIGHT]);
|
163 |
} catch (Exception $e) {
|
164 |
+
error_log("Error while fetching the image" . $e->getMessage());
|
|
|
165 |
}
|
166 |
}
|
167 |
return $product->getData($fieldName);
|
193 |
* gives the children in form of array
|
194 |
*/
|
195 |
public function addChildrens($product, $fields, $productArray) {
|
196 |
+
|
197 |
$type = $product->getData('type_id');
|
198 |
if ($type == "configurable" || $type == "grouped" ) {
|
199 |
$associatedProducts = array();
|
200 |
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
|
201 |
+
$adapter = Mage::getSingleton("core/resource");
|
202 |
+
$_catalogInventoryTable = method_exists($adapter, 'getTableName')
|
203 |
+
? $adapter->getTableName('cataloginventory_stock_item'): 'catalog_category_product_index';
|
204 |
$childrens = $conf->getUsedProductCollection()
|
205 |
->addAttributeToSelect('*')
|
206 |
+
->addFilterByRequiredOptions()
|
207 |
+
->joinField("qtyAssociated", $_catalogInventoryTable, 'qty', 'product_id=entity_id', null, 'left');
|
208 |
foreach ($childrens as $children)
|
209 |
{
|
210 |
$childProduct = $this->getProduct($children, $fields, true);
|
231 |
} else {
|
232 |
$product = $this->convertMultivalued($product, $fields);
|
233 |
}
|
234 |
+
$product = $this->convertDataType($product, $fields, $isChild);
|
235 |
return $product;
|
236 |
}
|
237 |
|
314 |
*/
|
315 |
public function convertMultivalued($product, $fields = null) {
|
316 |
foreach($product as $field=>$value) {
|
317 |
+
if((is_null($fields) ||
|
318 |
+
(($field != "associatedProducts") &&
|
319 |
+
array_key_exists(self::MULTIVALUED,$fields[$field]) &&
|
320 |
+
$fields[$field][self::MULTIVALUED])) &&
|
321 |
+
!is_array($value)) {
|
322 |
+
|
323 |
$valueAsAnArray = array();
|
324 |
$valueAsAnArray[] = $value;
|
325 |
$product[$field] = $valueAsAnArray;
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Schemabuilder.php
CHANGED
@@ -19,11 +19,20 @@ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Schemabuilder extends Unbxd_Datafe
|
|
19 |
$jsonString = "";
|
20 |
$fieldList = array();
|
21 |
$featuredFields = Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields();
|
|
|
22 |
foreach($fields as $fieldName=>$values ) {
|
23 |
-
if($values[self::FIELD_STATUS] == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
$fieldList[] = array(self::FIELD_NAME => $fieldName,
|
25 |
self::DATA_TYPE => $values[self::FIELD_DATA_TYPE],
|
26 |
-
self::MULTIVALUED => ($this->endsWith($fieldName, "Associated")?self::TRUE:(Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
|
|
|
27 |
self::TRUE:self::FALSE)),
|
28 |
self::AUTOSUGGEST => ($values[self::FIELD_AUTOSUGGEST] == 1?
|
29 |
self::TRUE: self::FALSE));
|
19 |
$jsonString = "";
|
20 |
$fieldList = array();
|
21 |
$featuredFields = Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields();
|
22 |
+
$conflictedFeatureFields = Mage::getResourceSingleton("datafeeder/field")->getConflictedFeatureFieldLust();
|
23 |
foreach($fields as $fieldName=>$values ) {
|
24 |
+
if((array_key_exists(self::FIELD_STATUS, $values) && $values[self::FIELD_STATUS] == 1)
|
25 |
+
|| !array_key_exists($fieldName, $featuredFields)) {
|
26 |
+
$origFieldName = $fieldName;
|
27 |
+
if($fieldName[0] == "_") {
|
28 |
+
$origFieldName = (in_array(substr($fieldName, 1, strlen($fieldName)), $conflictedFeatureFields))
|
29 |
+
? substr($fieldName, 1, strlen($fieldName))
|
30 |
+
: $fieldName;
|
31 |
+
}
|
32 |
$fieldList[] = array(self::FIELD_NAME => $fieldName,
|
33 |
self::DATA_TYPE => $values[self::FIELD_DATA_TYPE],
|
34 |
+
self::MULTIVALUED => ($this->endsWith($fieldName, "Associated")?self::TRUE:(Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
|
35 |
+
->isMultiSelect($origFieldName)?
|
36 |
self::TRUE:self::FALSE)),
|
37 |
self::AUTOSUGGEST => ($values[self::FIELD_AUTOSUGGEST] == 1?
|
38 |
self::TRUE: self::FALSE));
|
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Taxonomybuilder.php
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Taxonomybuilder extends Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Jsonbuilder {
|
4 |
+
|
5 |
+
var $file='unbxdTaxonomy.xml';
|
6 |
+
|
7 |
+
public function __construct(){
|
8 |
+
//$this->file = Mage::getBaseDir('tmp').DS.'unbxdTaxonomy.xml';
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Function to appened the contents to the file
|
13 |
+
*/
|
14 |
+
private function appendTofile($content){
|
15 |
+
|
16 |
+
try{
|
17 |
+
|
18 |
+
file_put_contents($this->file, $content, FILE_APPEND);
|
19 |
+
return true;
|
20 |
+
}catch(Exception $Ex){
|
21 |
+
error_log("UNBXD_MODULE:Error while appending the contents to file");
|
22 |
+
error_log($Ex->getMessage());
|
23 |
+
return false;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
private function log($content){
|
28 |
+
try{
|
29 |
+
file_put_contents($this->logFile, date('Y-m-d H:i:s').$content."\n", FILE_APPEND);
|
30 |
+
return true;
|
31 |
+
}catch(Exception $Ex){
|
32 |
+
error_log("UNBXD_MODULE:Error while appending the contents to file");
|
33 |
+
Mage::throwException($Ex->getMessage());
|
34 |
+
return false;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Function to delete the file
|
40 |
+
*/
|
41 |
+
private function deleteFile(){
|
42 |
+
unlink($this->file);
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
private function writeJSONProductsContents($site){
|
47 |
+
$stores= $this->getStores($site);
|
48 |
+
$content='';
|
49 |
+
foreach( $stores as $store){
|
50 |
+
$categories=$this->getStoreCategories($store);
|
51 |
+
foreach($categories as $category){
|
52 |
+
$category_obj = Mage::getModel('catalog/category')->load($category->getId());
|
53 |
+
if(!is_null($category_obj) && $category_obj->getName()== "" ){
|
54 |
+
continue;
|
55 |
+
}
|
56 |
+
$content =$content.$this->getCategoryContent($category_obj);
|
57 |
+
$childrens = $category_obj->getAllChildren(true);
|
58 |
+
$childrenCategories = Mage::getResourceSingleton('catalog/category_collection')
|
59 |
+
->addIdFilter($childrens)
|
60 |
+
->addAttributeToSelect('*')
|
61 |
+
->load();
|
62 |
+
|
63 |
+
foreach($childrenCategories as $childCategory){
|
64 |
+
$childCategory = Mage::getModel('catalog/category')->load($childCategory->getId());
|
65 |
+
$content=$content.$this->getCategoryContent($childCategory);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
return $content;
|
70 |
+
}
|
71 |
+
|
72 |
+
private function getCategoryContent($category){
|
73 |
+
$content=array();
|
74 |
+
$content["nodeName"]= $category->getName();
|
75 |
+
$content["parentNodeId"] = array((string)$category->getParentId());
|
76 |
+
$content["nodeId"] =(string)$category->getId();
|
77 |
+
return json_encode($content).',';
|
78 |
+
}
|
79 |
+
|
80 |
+
private function getStores($site){
|
81 |
+
$sites=Mage::app()->getWebsites();
|
82 |
+
foreach( $sites as $eachSite){
|
83 |
+
if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
|
84 |
+
return $eachSite->getStores();
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
public function createTaxonomyFeed($site){
|
90 |
+
|
91 |
+
$content=$this->writeJSONProductsContents($site);
|
92 |
+
|
93 |
+
if(!$content){
|
94 |
+
return false;
|
95 |
+
}
|
96 |
+
$this->log('writing content');
|
97 |
+
|
98 |
+
return rtrim($content, ",");;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function createMappingFeed($collection){
|
102 |
+
|
103 |
+
$content=$this->writeJSONMappingContents($collection);
|
104 |
+
|
105 |
+
if(!$content){
|
106 |
+
|
107 |
+
return false;
|
108 |
+
}
|
109 |
+
|
110 |
+
$this->log('writing content');
|
111 |
+
|
112 |
+
return rtrim($content, ",");
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
private function writeJSONMappingContents($collection)
|
117 |
+
{
|
118 |
+
$content='';
|
119 |
+
foreach($collection as $mapping) {
|
120 |
+
|
121 |
+
$content =$content.$this->getMappingContent( $mapping);
|
122 |
+
}
|
123 |
+
return $content;
|
124 |
+
|
125 |
+
}
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
private function getMappingContent($mapping){
|
130 |
+
|
131 |
+
$content=array();
|
132 |
+
$content["uniqueId"]= (string)$mapping['entity_id'];
|
133 |
+
$content["nodeId"] = explode(",", $mapping['category_id']);
|
134 |
+
return json_encode($content).',';
|
135 |
+
}
|
136 |
+
|
137 |
+
public function validateSite($site){
|
138 |
+
$sites=Mage::app()->getWebsites();
|
139 |
+
if( !isset($site) || $site == "") {
|
140 |
+
return false;
|
141 |
+
}
|
142 |
+
foreach( $sites as $eachSite){
|
143 |
+
if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
|
144 |
+
return $eachSite->getWebsiteId();
|
145 |
+
}
|
146 |
+
}
|
147 |
+
return -1;
|
148 |
+
}
|
149 |
+
|
150 |
+
public function getStoreCategories($store, $sorted=false, $asCollection=false, $toLoad=true)
|
151 |
+
{
|
152 |
+
$parent = $store->getRootCategoryId();
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Check if parent node of the store still exists
|
156 |
+
*/
|
157 |
+
$category = Mage::getModel('catalog/category');
|
158 |
+
/* @var $category Mage_Catalog_Model_Category */
|
159 |
+
if (!$category->checkId($parent)) {
|
160 |
+
if ($asCollection) {
|
161 |
+
return new Varien_Data_Collection();
|
162 |
+
}
|
163 |
+
return array();
|
164 |
+
}
|
165 |
+
|
166 |
+
$recursionLevel = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
|
167 |
+
$tree = Mage::getResourceModel('catalog/category_tree');
|
168 |
+
/* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
|
169 |
+
$nodes = $tree->loadNode($parent)
|
170 |
+
->loadChildren($recursionLevel)
|
171 |
+
->getChildren();
|
172 |
+
//added to fetch non flat data all the time
|
173 |
+
$emptyResourceModel = Mage::getResourceSingleton('catalog/category_collection');
|
174 |
+
$tree->addCollectionData($emptyResourceModel, $sorted, $parent, $toLoad, false);
|
175 |
+
if ($asCollection) {
|
176 |
+
return $tree->getCollection();
|
177 |
+
}
|
178 |
+
return $nodes;
|
179 |
+
}
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
+
public function updateAction($action,$value){
|
184 |
+
Mage::getResourceSingleton("datafeeder/conf")->updateAction($action, $value);
|
185 |
+
}
|
186 |
+
}
|
187 |
+
?>
|
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf.php
CHANGED
@@ -26,7 +26,10 @@ class Unbxd_Datafeeder_Model_Mysql4_Conf extends Mage_Core_Model_Mysql4_Abstract
|
|
26 |
}
|
27 |
|
28 |
public function updateAction($action,$value)
|
29 |
-
{
|
|
|
|
|
|
|
30 |
$collection=Mage::getModel('datafeeder/conf')->getCollection()
|
31 |
->addFieldToFilter('action',$action);
|
32 |
|
26 |
}
|
27 |
|
28 |
public function updateAction($action,$value)
|
29 |
+
{
|
30 |
+
if (!isset($value) || $value == "") {
|
31 |
+
return;
|
32 |
+
}
|
33 |
$collection=Mage::getModel('datafeeder/conf')->getCollection()
|
34 |
->addFieldToFilter('action',$action);
|
35 |
|
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field.php
CHANGED
@@ -26,8 +26,9 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
26 |
$results = Mage::getModel('datafeeder/field')->getCollection()->addFieldToFilter(self::SITE, $site);
|
27 |
$fieldMapping = array();
|
28 |
$_reader = Mage::getSingleton('core/resource')->getConnection('core_read');
|
29 |
-
|
30 |
-
|
|
|
31 |
} else {
|
32 |
$table = self::TABLE_NAME;
|
33 |
}
|
@@ -60,10 +61,12 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
60 |
$fieldMapping = $this->getFieldMapping($site);
|
61 |
$deltaUpdate = array();
|
62 |
$attributes = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getAttributes();
|
|
|
63 |
foreach($attributes as $attribute){
|
64 |
$fieldName = $attribute->getAttributeCode();
|
65 |
-
|
66 |
-
|
|
|
67 |
}
|
68 |
if (!array_key_exists($fieldName, $fieldMapping)) {
|
69 |
$deltaUpdate[$fieldName] = array(self::STATUS => 1, self::DATA_TYPE => 'longText');
|
@@ -95,8 +98,9 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
95 |
*/
|
96 |
public function updateFields($fieldMapping, $site) {
|
97 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
98 |
-
|
99 |
-
|
|
|
100 |
} else {
|
101 |
$table = self::TABLE_NAME;
|
102 |
}
|
@@ -136,8 +140,9 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
136 |
$insertingRequest[self::GENERATE_IMAGE] = $value[self::GENERATE_IMAGE];
|
137 |
$insertingRequestArray[] = $insertingRequest;
|
138 |
}
|
139 |
-
|
140 |
-
|
|
|
141 |
} else {
|
142 |
$table = self::TABLE_NAME;
|
143 |
}
|
@@ -159,10 +164,6 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
159 |
$featuredFields["catlevel2Name"]=$this->getField("text", "false", "false");
|
160 |
$featuredFields["catlevel3Name"]=$this->getField("text", "false", "false");
|
161 |
$featuredFields["catlevel4Name"]=$this->getField("text", "false", "false");
|
162 |
-
$featuredFields["catlevel1Id"]=$this->getField("text", "false", "false");
|
163 |
-
$featuredFields["catlevel2Id"]=$this->getField("text", "false", "false");
|
164 |
-
$featuredFields["catlevel3Id"]=$this->getField("text", "false", "false");
|
165 |
-
$featuredFields["catlevel4Id"]=$this->getField("text", "false", "false");
|
166 |
$featuredFields["category"]=$this->getField("text", "true", "true");
|
167 |
$featuredFields["subCategory"]=$this->getField("text", "true", "true");
|
168 |
$featuredFields["color"]=$this->getField("text", "true", "false");
|
@@ -191,4 +192,4 @@ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstrac
|
|
191 |
return array('gender');
|
192 |
}
|
193 |
}
|
194 |
-
?>
|
26 |
$results = Mage::getModel('datafeeder/field')->getCollection()->addFieldToFilter(self::SITE, $site);
|
27 |
$fieldMapping = array();
|
28 |
$_reader = Mage::getSingleton('core/resource')->getConnection('core_read');
|
29 |
+
$adapter= Mage::getSingleton("core/resource");
|
30 |
+
if(method_exists($adapter, 'getTableName')) {
|
31 |
+
$table = $adapter->getTableName(self::TABLE_NAME);
|
32 |
} else {
|
33 |
$table = self::TABLE_NAME;
|
34 |
}
|
61 |
$fieldMapping = $this->getFieldMapping($site);
|
62 |
$deltaUpdate = array();
|
63 |
$attributes = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getAttributes();
|
64 |
+
$escapedFields = $this->getConflictedFeatureFieldLust();
|
65 |
foreach($attributes as $attribute){
|
66 |
$fieldName = $attribute->getAttributeCode();
|
67 |
+
|
68 |
+
if (in_array($fieldName, $escapedFields)) {
|
69 |
+
$fieldName = "_".$fieldName;
|
70 |
}
|
71 |
if (!array_key_exists($fieldName, $fieldMapping)) {
|
72 |
$deltaUpdate[$fieldName] = array(self::STATUS => 1, self::DATA_TYPE => 'longText');
|
98 |
*/
|
99 |
public function updateFields($fieldMapping, $site) {
|
100 |
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
101 |
+
$adapter= Mage::getSingleton("core/resource");
|
102 |
+
if(method_exists($adapter, 'getTableName')) {
|
103 |
+
$table = $adapter->getTableName(self::TABLE_NAME);
|
104 |
} else {
|
105 |
$table = self::TABLE_NAME;
|
106 |
}
|
140 |
$insertingRequest[self::GENERATE_IMAGE] = $value[self::GENERATE_IMAGE];
|
141 |
$insertingRequestArray[] = $insertingRequest;
|
142 |
}
|
143 |
+
$adapter= Mage::getSingleton("core/resource");
|
144 |
+
if(method_exists($adapter, 'getTableName')) {
|
145 |
+
$table = $adapter->getTableName(self::TABLE_NAME);
|
146 |
} else {
|
147 |
$table = self::TABLE_NAME;
|
148 |
}
|
164 |
$featuredFields["catlevel2Name"]=$this->getField("text", "false", "false");
|
165 |
$featuredFields["catlevel3Name"]=$this->getField("text", "false", "false");
|
166 |
$featuredFields["catlevel4Name"]=$this->getField("text", "false", "false");
|
|
|
|
|
|
|
|
|
167 |
$featuredFields["category"]=$this->getField("text", "true", "true");
|
168 |
$featuredFields["subCategory"]=$this->getField("text", "true", "true");
|
169 |
$featuredFields["color"]=$this->getField("text", "true", "false");
|
192 |
return array('gender');
|
193 |
}
|
194 |
}
|
195 |
+
?>
|
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Product/Collection.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Unbxd_Datafeeder_Model_Mysql4_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
|
4 |
+
|
5 |
+
protected function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
}
|
9 |
+
|
10 |
+
public function isEnabledFlat()
|
11 |
+
{
|
12 |
+
return false;
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
?>
|
app/code/local/Unbxd/Datafeeder/Model/Observer.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*@author Pooja
|
3 |
+
*
|
4 |
+
* Observer to capture order event from frontend
|
5 |
+
* It captures the event and sends the ordered product Ids to inremmental feed upload in FeedManager
|
6 |
+
*/
|
7 |
+
|
8 |
+
|
9 |
+
class Unbxd_Datafeeder_Model_Observer
|
10 |
+
{
|
11 |
+
|
12 |
+
var $websiteMap ;
|
13 |
+
|
14 |
+
/*Mapping between siteId & websiteName */
|
15 |
+
private function getSite($websiteId) {
|
16 |
+
|
17 |
+
if(!isset($this->websiteMap)) {
|
18 |
+
$sites=Mage::app()->getWebsites();
|
19 |
+
foreach( $sites as $eachSite){
|
20 |
+
$this->websiteMap[$eachSite->getWebsiteId()] = $eachSite->getName();
|
21 |
+
}
|
22 |
+
}
|
23 |
+
return $this->websiteMap[$websiteId];
|
24 |
+
}
|
25 |
+
|
26 |
+
public function logorderStockupdate($observer)
|
27 |
+
{
|
28 |
+
$updateIds = array();
|
29 |
+
$siteIds = array();
|
30 |
+
$event = $observer->getEvent();
|
31 |
+
if(!$event->hasData('order')) {
|
32 |
+
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log('Order data not present in the event');
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
$order = $observer->getEvent()->getOrder();
|
36 |
+
$items = $order->getAllItems();
|
37 |
+
//get entity_id of all the ordered products
|
38 |
+
foreach ($items as $item)
|
39 |
+
{
|
40 |
+
//get product from Order_Sales item object
|
41 |
+
$product = $item->getProduct();
|
42 |
+
array_push($updateIds,$product->getId());
|
43 |
+
foreach($product->getWebsiteIds() as $websiteId){
|
44 |
+
array_push($siteIds,$websiteId);
|
45 |
+
}
|
46 |
+
//get a set of siteIds from all the products
|
47 |
+
$siteIds = array_unique($siteIds);
|
48 |
+
}
|
49 |
+
//update the feed for each site
|
50 |
+
foreach($siteIds as $siteId) {
|
51 |
+
$site = $this->getSite($siteId);
|
52 |
+
if(!isset($site)) {
|
53 |
+
continue;
|
54 |
+
}
|
55 |
+
|
56 |
+
//call incremental feed upload
|
57 |
+
Mage::getSingleton('unbxd_datafeeder/feed_feedmanager')->processIncremental("1970-01-01 00:00:00",$site,"add",$updateIds);
|
58 |
+
}
|
59 |
+
|
60 |
+
return $this;
|
61 |
+
}
|
62 |
+
public function inventoryStockUpdate($observer)
|
63 |
+
{
|
64 |
+
$event = $observer->getEvent();
|
65 |
+
if(!$event->hasData('item')) {
|
66 |
+
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log('Item data not present in the inventory event');
|
67 |
+
return;
|
68 |
+
}
|
69 |
+
$item = $event->getItem();
|
70 |
+
$product = $item->getProduct();
|
71 |
+
$updateIds = array($product->getId());
|
72 |
+
$siteIds = array();
|
73 |
+
foreach($product->getWebsiteIds() as $websiteId){
|
74 |
+
array_push($siteIds,$websiteId);
|
75 |
+
}
|
76 |
+
$siteIds = array_unique($siteIds);
|
77 |
+
|
78 |
+
Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log('Inventory stock update initiated');
|
79 |
+
foreach($siteIds as $siteId) {
|
80 |
+
$site = $this->getSite($siteId);
|
81 |
+
if(!isset($site)) {
|
82 |
+
continue;
|
83 |
+
}
|
84 |
+
|
85 |
+
//call incremental feed upload
|
86 |
+
Mage::getSingleton('unbxd_datafeeder/feed_feedmanager')->processIncremental("1970-01-01 00:00:00",$site,"add",$updateIds);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
app/code/local/Unbxd/Datafeeder/controllers/ConfigController.php
CHANGED
@@ -2,6 +2,13 @@
|
|
2 |
class Unbxd_Datafeeder_ConfigController extends Mage_Core_Controller_Front_Action
|
3 |
{
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
/**
|
6 |
* gets all the stores
|
7 |
*/
|
2 |
class Unbxd_Datafeeder_ConfigController extends Mage_Core_Controller_Front_Action
|
3 |
{
|
4 |
|
5 |
+
public function indexAction(){
|
6 |
+
$fromdate="1970-01-01 00:00:00";
|
7 |
+
$site=$this->getRequest()->getParam("site");
|
8 |
+
Mage::getSingleton('unbxd_datafeeder/feed_feedmanager')->process($fromdate,$site);
|
9 |
+
echo "Done";
|
10 |
+
}
|
11 |
+
|
12 |
/**
|
13 |
* gets all the stores
|
14 |
*/
|
app/code/local/Unbxd/Datafeeder/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Unbxd_Datafeeder>
|
5 |
-
<version>1.0.
|
6 |
</Unbxd_Datafeeder>
|
7 |
</modules>
|
8 |
<frontend>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Unbxd_Datafeeder>
|
5 |
+
<version>1.0.10</version>
|
6 |
</Unbxd_Datafeeder>
|
7 |
</modules>
|
8 |
<frontend>
|
app/code/local/Unbxd/Datafeeder/{Helper → sql}/.DS_Store
RENAMED
Binary file
|
app/design/adminhtml/base/default/template/datafeeder/conf.phtml
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
<script src="
|
2 |
-
<script src="
|
3 |
<style type="text/css">
|
4 |
td
|
5 |
{
|
@@ -61,7 +61,7 @@
|
|
61 |
<p class="switcher">
|
62 |
<label for="store_switcher"><b>Choose Store View: </b><label>
|
63 |
|
64 |
-
<select id="site" class="site" name="site" onload="newajaxcall('<?php echo $this->getFeedConf(); ?>')" onchange="newajaxcall('<?php echo $this->getFeedConf();?>')">
|
65 |
<?php $allsites=Mage::app()->getWebsites();?>
|
66 |
<?php foreach ($allsites as $site):?>
|
67 |
<option value="<?php echo $site->getName()?>"><?php echo $site->getName()?></option>
|
@@ -134,7 +134,7 @@
|
|
134 |
$jq.ajax({
|
135 |
|
136 |
url: ajaxurl,
|
137 |
-
timeout:
|
138 |
type:"POST",
|
139 |
dataType: "json",
|
140 |
data:{"form_key":"<?php echo Mage::getSingleton('core/session')->getFormKey()?>",
|
@@ -144,7 +144,7 @@
|
|
144 |
success: function(data) {
|
145 |
|
146 |
if(data.feed !== "empty") $jq('[name=feedName]').val(data.feed); else $jq('[name=feedName]').val("");
|
147 |
-
if(data.
|
148 |
},
|
149 |
|
150 |
fail: function(XMLHttpRequest, textStatus, errorThrown) {
|
@@ -195,11 +195,11 @@
|
|
195 |
field["generate_image"] = $jq(this).find('[id=generate_image]').is(':checked')?1:0;
|
196 |
element = this.querySelector('#image_height');
|
197 |
if(element) {
|
198 |
-
field["image_height"] = element.value;
|
199 |
}
|
200 |
element = this.querySelector('#image_width') ;
|
201 |
if (element) {
|
202 |
-
field["image_width"] = element.value;
|
203 |
}
|
204 |
fields[$jq(this).find(".label").text()] = JSON.stringify(field);
|
205 |
|
@@ -243,15 +243,20 @@
|
|
243 |
tableHtml="<tbody>";
|
244 |
$jq("#field-list").find("tr").remove();
|
245 |
tableHtml += addFieldConfTableHeader();
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
childExists = false;
|
248 |
if ((key + "Associated") in jarray && jarray[key + "Associated"]["status"] == "1") {
|
249 |
-
childExists = true
|
250 |
}
|
251 |
if( key.substr(-10) != "Associated" ) {
|
252 |
-
tableHtml += constructRow(key,
|
253 |
}
|
254 |
-
}
|
255 |
tableHtml+="</tbody>";
|
256 |
$jq('#field-list').append(tableHtml)
|
257 |
});
|
1 |
+
<script src="//code.jquery.com/jquery-1.8.0.min.js"></script>
|
2 |
+
<script src="//malsup.github.com/jquery.form.js"></script>
|
3 |
<style type="text/css">
|
4 |
td
|
5 |
{
|
61 |
<p class="switcher">
|
62 |
<label for="store_switcher"><b>Choose Store View: </b><label>
|
63 |
|
64 |
+
<select id="site" class="site" name="site" onload="newajaxcall('<?php echo $this->getFeedConf(); ?>')" onchange="newajaxcall('<?php echo $this->getFeedConf();?>');createTable('<?php echo $this->getEditUrl();?>');">
|
65 |
<?php $allsites=Mage::app()->getWebsites();?>
|
66 |
<?php foreach ($allsites as $site):?>
|
67 |
<option value="<?php echo $site->getName()?>"><?php echo $site->getName()?></option>
|
134 |
$jq.ajax({
|
135 |
|
136 |
url: ajaxurl,
|
137 |
+
timeout:30000,
|
138 |
type:"POST",
|
139 |
dataType: "json",
|
140 |
data:{"form_key":"<?php echo Mage::getSingleton('core/session')->getFormKey()?>",
|
144 |
success: function(data) {
|
145 |
|
146 |
if(data.feed !== "empty") $jq('[name=feedName]').val(data.feed); else $jq('[name=feedName]').val("");
|
147 |
+
if(data.siteName !== "empty") $jq('[name=siteName]').val(data.siteName); else $jq('[name=siteName]').val("");
|
148 |
},
|
149 |
|
150 |
fail: function(XMLHttpRequest, textStatus, errorThrown) {
|
195 |
field["generate_image"] = $jq(this).find('[id=generate_image]').is(':checked')?1:0;
|
196 |
element = this.querySelector('#image_height');
|
197 |
if(element) {
|
198 |
+
field["image_height"] = parseInt(element.value);
|
199 |
}
|
200 |
element = this.querySelector('#image_width') ;
|
201 |
if (element) {
|
202 |
+
field["image_width"] = parseInt(element.value);
|
203 |
}
|
204 |
fields[$jq(this).find(".label").text()] = JSON.stringify(field);
|
205 |
|
243 |
tableHtml="<tbody>";
|
244 |
$jq("#field-list").find("tr").remove();
|
245 |
tableHtml += addFieldConfTableHeader();
|
246 |
+
keys = Object.keys(jarray)
|
247 |
+
for(index in keys) {
|
248 |
+
key = keys[index];
|
249 |
+
if (!(key in jarray)) {
|
250 |
+
continue;
|
251 |
+
}
|
252 |
childExists = false;
|
253 |
if ((key + "Associated") in jarray && jarray[key + "Associated"]["status"] == "1") {
|
254 |
+
childExists = true;
|
255 |
}
|
256 |
if( key.substr(-10) != "Associated" ) {
|
257 |
+
tableHtml += constructRow(key, jarray[key], childExists);
|
258 |
}
|
259 |
+
}
|
260 |
tableHtml+="</tbody>";
|
261 |
$jq('#field-list').append(tableHtml)
|
262 |
});
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>unbxd_feedconnector</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>pushes the products from the magento to unbxd servers</description>
|
11 |
<notes>Supporting v2 type of unbxd field</notes>
|
12 |
<authors><author><name>ananthesh</name><user>ananthesh</user><email>ananthesh@unbxd.com</email></author></authors>
|
13 |
-
<date>
|
14 |
-
<time>
|
15 |
-
<contents><target name="magelocal"><dir name="Unbxd"><dir name="Datafeeder"><dir name="Block"><file name="Edit.php" hash="6cc7e0396c298656c2529d2651bc0ae1"/><file name="Index.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>unbxd_feedconnector</name>
|
4 |
+
<version>1.0.10</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
10 |
<description>pushes the products from the magento to unbxd servers</description>
|
11 |
<notes>Supporting v2 type of unbxd field</notes>
|
12 |
<authors><author><name>ananthesh</name><user>ananthesh</user><email>ananthesh@unbxd.com</email></author></authors>
|
13 |
+
<date>2015-02-12</date>
|
14 |
+
<time>10:44:44</time>
|
15 |
+
<contents><target name="magelocal"><dir name="Unbxd"><dir name="Datafeeder"><dir name="Block"><file name="Edit.php" hash="6cc7e0396c298656c2529d2651bc0ae1"/><file name="Index.php" hash="3c1be9d48589ffbb418df7993c2f664e"/></dir><dir name="Helper"><file name="Analyticshelper.php" hash="9c841be95363d1e100e9a00c7d95f7d6"/><file name="Data.php" hash="cc32188ca72c365a3177b8439188f4b0"/><file name="UnbxdIndexingHelper.php" hash="c7961ac730e61a533e449901f8f09688"/><file name="UnbxdTaxonomyHelper.php" hash="9c16f370fa44807d8524c549c1ddb017"/></dir><dir name="Model"><file name="Attribute.php" hash="9b7e4dea003568ffb016b60f20b35e74"/><file name="Conf.php" hash="b9a9627d779f473b7ab1696fd44a877b"/><file name="Facet.php" hash="a778acee165d1ff0162be6664f4ecf1a"/><dir name="Feed"><file name="Feedcreator.php" hash="ec7e6ae0f07d5160e87f1b17b2ced3b7"/><file name="Feedmanager.php" hash="dc1a79b2aa454b4528946ba0a1a129ff"/><file name="Filemanager.php" hash="3523f7b33ecd308fb3ca39096dc4942e"/><dir name="Jsonbuilder"><file name="Jsonbuilder.php" hash="77635e52b5ec7c39dae78094efed566e"/><file name="Productbuilder.php" hash="d55b3e6ea3975c9f86264aa2eb1e6789"/><file name="Schemabuilder.php" hash="240d31fc4a3829d075d0ed83daf2ddae"/><file name="Taxonomybuilder.php" hash="44adff807b76a5325ba9c2c09c9da4d4"/></dir></dir><file name="Field.php" hash="4206919e3762907aba7d38b39733deba"/><dir name="Mysql4"><file name="Attribute.php" hash="7ec9732a1399db03dec0b6002d1aeb58"/><dir name="Conf"><file name="Collection.php" hash="fa30f58432618d2822ce0e3fe1483efe"/></dir><file name="Conf.php" hash="ad03b89d6bd43893f171fb08e142fbc0"/><dir name="Field"><file name="Collection.php" hash="5c9a40a3f2df168531c1af18be63bf16"/></dir><file name="Field.php" hash="905b8b02bc273cc4b0edcde927984777"/><dir name="Product"><file name="Collection.php" hash="fe33bac35a5af9d785c9a3443586a67f"/></dir><dir name="Resource"><file name="Attribute.php" hash="9353baa4f14eeb342de93d20c566bfee"/></dir><file name="Upgrade.php" hash="e3e259f32cdcf58d2dca2a21d6262767"/></dir><file name="Observer.php" hash="aeecd0939ea640b7f228708e08acd838"/></dir><dir name="controllers"><file name="ConfigController.php" hash="e9b049ba4913e4733a251035f9654beb"/><file name="FieldController.php" hash="0c93a9c339d718179641c0a47cccaa6c"/><file name="IndexController.php" hash="90a2150b94caa81fd598d01f3e0c124b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="243eca656901fd022f8119a3ad46b569"/><file name="config.xml" hash="4c35bd27940d0f5272f4c75dc853c769"/></dir><dir name="scripts"><file name="Cron.php" hash="087a021cf47794f337e4ce0130b2d3b7"/><file name="abstract.php" hash="757e66bc99da02c274a0d9723923329e"/></dir><dir name="sql"><dir name="datafeeder_setup"><file name="mysql4-install-1.0.5.php" hash="27ecb984b7419e2fc58433db370fe43d"/><file name="mysql4-upgrade-0.1.0-1.0.5.php" hash="27ecb984b7419e2fc58433db370fe43d"/></dir><file name=".DS_Store" hash="8213304460d382069de99d7420416e07"/></dir><file name=".DS_Store" hash="693bb0be4c803c357534a7c5dcd288c5"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="template"><dir name="datafeeder"><file name="conf.phtml" hash="a852eedfd5ea3b25be10725d9a5e72e7"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="shell"><file name="UnbxdFeed.php" hash="2b70f51b04c4b62b4a51aca0efae7050"/></dir></target><target name="mageetc"><dir name="modules"><file name="Unbxd_Datafeeder.xml" hash="73f1469ef7c4f5c4eef05900302239de"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|