Version Notes
Export Your Magento Store To Popular Feed Formats (csv, txt) for Google Shopping, and other CSEs
Download this release
Release Info
Developer | Magento Core Team |
Extension | Ranvii_Feed |
Version | 2.2.5 |
Comparing to | |
See all releases |
Version 2.2.5
- app/code/community/Ranvii/Feed/Block/Adminhtml/Config/Form/Renderer/Website.php +13 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items.php +23 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit.php +139 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Form.php +37 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Advanced.php +217 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Content/Csv.php +244 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Main.php +128 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Type.php +124 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tabs.php +101 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid.php +226 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid/Renderer/AccessUrl.php +21 -0
- app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid/Renderer/Datetime.php +27 -0
- app/code/community/Ranvii/Feed/Helper/Data.php +55 -0
- app/code/community/Ranvii/Feed/Model/Adminhtml/System/Config/Source/Store.php +6 -0
- app/code/community/Ranvii/Feed/Model/Custom/Attribute.php +21 -0
- app/code/community/Ranvii/Feed/Model/Item.php +887 -0
- app/code/community/Ranvii/Feed/Model/Item/Block.php +350 -0
- app/code/community/Ranvii/Feed/Model/Item/Block/Category.php +45 -0
- app/code/community/Ranvii/Feed/Model/Item/Block/Product.php +1501 -0
- app/code/community/Ranvii/Feed/Model/Mysql4/Custom/Attribute.php +17 -0
- app/code/community/Ranvii/Feed/Model/Mysql4/Custom/Attribute/Collection.php +19 -0
- app/code/community/Ranvii/Feed/Model/Mysql4/Item.php +17 -0
- app/code/community/Ranvii/Feed/Model/Mysql4/Item/Collection.php +19 -0
- app/code/community/Ranvii/Feed/Model/Observer.php +87 -0
- app/code/community/Ranvii/Feed/Model/Product/Collection.php +180 -0
- app/code/community/Ranvii/Feed/controllers/Adminhtml/ItemsController.php +294 -0
- app/code/community/Ranvii/Feed/controllers/IndexController.php +37 -0
- app/code/community/Ranvii/Feed/etc/adminhtml.xml +23 -0
- app/code/community/Ranvii/Feed/etc/config.xml +134 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.0.php +22 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.3.php +26 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.4.php +29 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-2.0.php +34 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-upgrade-1.3-1.4.php +17 -0
- app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-upgrade-1.4-2.0.php +13 -0
- app/design/adminhtml/default/default/layout/ranvii-feed.xml +42 -0
- app/design/adminhtml/default/default/template/ranvii/feed/item/edit/content.phtml +187 -0
- app/design/adminhtml/default/default/template/ranvii/feed/item/edit/content/mapping.phtml +44 -0
- app/design/adminhtml/default/default/template/ranvii/feed/item/import/form.phtml +27 -0
- app/etc/modules/Ranvii_Feed.xml +10 -0
- package.xml +18 -0
- skin/adminhtml/default/default/ranvii/feed.css +105 -0
app/code/community/Ranvii/Feed/Block/Adminhtml/Config/Form/Renderer/Website.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Config_Form_Renderer_Website extends Mage_Adminhtml_Block_System_Config_Form_Field
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
7 |
+
{
|
8 |
+
|
9 |
+
$html = '';
|
10 |
+
return $html;
|
11 |
+
|
12 |
+
}
|
13 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items extends Mage_Adminhtml_Block_Widget_Grid_Container
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function __construct()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
$this->_controller = 'adminhtml_items';
|
12 |
+
|
13 |
+
$this->_blockGroup = 'ranvii_feed';
|
14 |
+
|
15 |
+
$this->_headerText = $this->__('Manage Feeds');
|
16 |
+
|
17 |
+
$this->_addButtonLabel = $this->__('Add Feed');
|
18 |
+
|
19 |
+
parent::__construct();
|
20 |
+
|
21 |
+
}
|
22 |
+
|
23 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit.php
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function __construct(){
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
parent::__construct();
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
$this->_objectId = 'id';
|
16 |
+
|
17 |
+
$this->_blockGroup = 'ranvii_feed';
|
18 |
+
|
19 |
+
$this->_controller = 'adminhtml_items';
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
$this->_updateButton('save', 'label', $this->__('Save'));
|
24 |
+
|
25 |
+
$this->_updateButton('delete', 'label', $this->__('Delete'));
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
$feed = Mage::registry('ranvii_feed');
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
if($feed && $feed->getId() > 0){
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
$this->_addButton('generate', array(
|
38 |
+
|
39 |
+
'label' => $this->__('Generate File'),
|
40 |
+
|
41 |
+
'onclick' => 'if($(\'loading-mask\')){$(\'loading-mask\').show();}setLocation(\''.$this->getUrl('*/*/generate', array('id'=>$feed->getId())).'\')',
|
42 |
+
|
43 |
+
), -100);
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
if($feed->getFtpActive()){
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
$this->_addButton('upload', array(
|
52 |
+
|
53 |
+
'label' => $this->__('Upload File'),
|
54 |
+
|
55 |
+
'onclick' => 'setLocation(\''.$this->getUrl('*/*/upload', array('id'=>$feed->getId())).'\')',
|
56 |
+
|
57 |
+
), -100);
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
$this->_addButton('saveandcontinue', array(
|
70 |
+
|
71 |
+
'label' => $this->__('Save And Continue Edit'),
|
72 |
+
|
73 |
+
'onclick' => 'saveAndContinueEdit()',
|
74 |
+
|
75 |
+
'class' => 'save',
|
76 |
+
|
77 |
+
), -100);
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
$_data = array();
|
82 |
+
|
83 |
+
$_data['data'] = Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Content_Csv::getSystemSections();
|
84 |
+
|
85 |
+
$_data['url'] = $this->getUrl('*/*/mappingimportsection', array('id'=>($feed && $feed->getId() ? $feed->getId() : 0)));
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
$this->_formScripts[] = "
|
90 |
+
|
91 |
+
function saveAndContinueEdit(){
|
92 |
+
|
93 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
var RanviFeedAdmin = new RanviFeedAdminSettings(" . Zend_Json::encode($_data) . ");
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
";
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
if ($this->getRequest()->getActionName() == 'new' &&
|
108 |
+
|
109 |
+
!$this->getRequest()->getParam('type')){
|
110 |
+
|
111 |
+
$this->removeButton('save');
|
112 |
+
|
113 |
+
$this->removeButton('saveandcontinue');
|
114 |
+
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
}
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
public function getHeaderText(){
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
if( Mage::registry('ranvii_feed') && Mage::registry('ranvii_feed')->getId() ) {
|
128 |
+
|
129 |
+
return $this->__("Edit %s", $this->htmlEscape(Mage::registry('ranvii_feed')->getName()));
|
130 |
+
|
131 |
+
} else {
|
132 |
+
|
133 |
+
return $this->__('Add Item');
|
134 |
+
|
135 |
+
}
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Form.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
protected function _prepareForm(){
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
$form = new Varien_Data_Form(array(
|
12 |
+
|
13 |
+
'id' => 'edit_form',
|
14 |
+
|
15 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
16 |
+
|
17 |
+
'method' => 'post',
|
18 |
+
|
19 |
+
'enctype' => 'multipart/form-data'
|
20 |
+
|
21 |
+
));
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
$form->setUseContainer(true);
|
26 |
+
|
27 |
+
$this->setForm($form);
|
28 |
+
|
29 |
+
return parent::_prepareForm();
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Advanced.php
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Advanced extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
protected function _prepareForm()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
$form = new Varien_Data_Form();
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
if(Mage::registry('ranvii_feed')){
|
18 |
+
|
19 |
+
$item = Mage::registry('ranvii_feed');
|
20 |
+
|
21 |
+
}else{
|
22 |
+
|
23 |
+
$item = Mage::getModel('ranvii_feed/item');
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
$this->setForm($form);
|
30 |
+
|
31 |
+
$fieldset = $form->addFieldset('advanced', array('legend' => $this->__('File Creation Settings')));
|
32 |
+
|
33 |
+
|
34 |
+
$field = $fieldset->addField('use_layer', 'select', array(
|
35 |
+
|
36 |
+
'name' => 'use_layer',
|
37 |
+
|
38 |
+
'label' => $this->__('Export Out of Stock Products'),
|
39 |
+
|
40 |
+
'title' => $this->__('Export Out of Stock Products'),
|
41 |
+
|
42 |
+
'required' => false,
|
43 |
+
|
44 |
+
'values' => array(1=>$this->__('No'),0=>$this->__('Yes')),
|
45 |
+
|
46 |
+
));
|
47 |
+
|
48 |
+
if(!$item->getId()){
|
49 |
+
|
50 |
+
$field ->setValue('1');
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
$field = $fieldset->addField('use_disabled', 'select', array(
|
57 |
+
|
58 |
+
'name' => 'use_disabled',
|
59 |
+
|
60 |
+
'label' => $this->__('Export Disabled Products'),
|
61 |
+
|
62 |
+
'title' => $this->__('Export Disabled Products'),
|
63 |
+
|
64 |
+
'required' => false,
|
65 |
+
|
66 |
+
'values' => array(1=>$this->__('No'),0=>$this->__('Yes'))
|
67 |
+
|
68 |
+
));
|
69 |
+
|
70 |
+
if(!$item->getId()){
|
71 |
+
|
72 |
+
$field ->setValue('1');
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
$fieldset = $form->addFieldset('upload_settings', array('legend' => $this->__('CRON Settings')));
|
77 |
+
|
78 |
+
$field = $fieldset->addField('upload_day', 'multiselect', array(
|
79 |
+
|
80 |
+
'name' => 'upload_day',
|
81 |
+
|
82 |
+
'label' => $this->__('Available Days'),
|
83 |
+
|
84 |
+
'title' => $this->__('Available Days'),
|
85 |
+
|
86 |
+
'required' => false,
|
87 |
+
|
88 |
+
'values' => array(
|
89 |
+
|
90 |
+
array('label'=>$this->__('Sunday'), 'value'=>'sun'),
|
91 |
+
|
92 |
+
array('label'=>$this->__('Monday'), 'value'=>'mon'),
|
93 |
+
|
94 |
+
array('label'=>$this->__('Tuesday'), 'value'=>'tue'),
|
95 |
+
|
96 |
+
array('label'=>$this->__('Wednesday'), 'value'=>'wed'),
|
97 |
+
|
98 |
+
array('label'=>$this->__('Thursday'), 'value'=>'thu'),
|
99 |
+
|
100 |
+
array('label'=>$this->__('Friday'), 'value'=>'fri'),
|
101 |
+
|
102 |
+
array('label'=>$this->__('Saturday'), 'value'=>'sat'),
|
103 |
+
|
104 |
+
)
|
105 |
+
|
106 |
+
));
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
if(!$item->getId()){
|
111 |
+
|
112 |
+
$field ->setValue('sun,mon,tue,wed,thu,fri,sat');
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
$hours = array();
|
119 |
+
|
120 |
+
$locale = Mage::getSingleton('core/locale');
|
121 |
+
|
122 |
+
for($i = 0;$i<24;$i++){
|
123 |
+
|
124 |
+
$hours[] = array('label'=>sprintf('%02d:00',$i), 'value'=>date('H', mktime($i, 0, 0, 1, 1, 1970)+$locale->date()->getGmtOffset()));
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
|
129 |
+
$field = $fieldset->addField('upload_interval', 'select', array(
|
130 |
+
|
131 |
+
'name' => 'upload_interval',
|
132 |
+
|
133 |
+
'label' => $this->__('Interval, hours'),
|
134 |
+
|
135 |
+
'title' => $this->__('Interval, hours'),
|
136 |
+
|
137 |
+
'required' => false,
|
138 |
+
|
139 |
+
'values' => array(
|
140 |
+
|
141 |
+
array('label'=>$this->__('every 5 mins'), 'value'=>50),
|
142 |
+
|
143 |
+
array('label'=>$this->__('every 10 mins'), 'value'=>100),
|
144 |
+
|
145 |
+
array('label'=>$this->__('every 15 mins'), 'value'=>150),
|
146 |
+
|
147 |
+
array('label'=>$this->__('every 20 mins'), 'value'=>200),
|
148 |
+
|
149 |
+
array('label'=>$this->__('every 30 mins'), 'value'=>300),
|
150 |
+
|
151 |
+
array('label'=>$this->__('every 1 hour'), 'value'=>1),
|
152 |
+
|
153 |
+
array('label'=>$this->__('every 3 hours'), 'value'=>3),
|
154 |
+
|
155 |
+
array('label'=>$this->__('every 6 hours'), 'value'=>6),
|
156 |
+
|
157 |
+
array('label'=>$this->__('every 12 hours'), 'value'=>12),
|
158 |
+
|
159 |
+
array('label'=>$this->__('every 24 hours'), 'value'=>24),
|
160 |
+
|
161 |
+
),
|
162 |
+
|
163 |
+
'class' => 'ranvi-feed-validate-interval'
|
164 |
+
|
165 |
+
));
|
166 |
+
|
167 |
+
if(!$item->getId()){
|
168 |
+
|
169 |
+
$field ->setValue('24');
|
170 |
+
|
171 |
+
}
|
172 |
+
|
173 |
+
/* $field->setOnchange('ranvifeed_setinterval(this, \'upload_hour_to\')');
|
174 |
+
|
175 |
+
$field = $field = $fieldset->addField('restart_cron', 'select', array(
|
176 |
+
|
177 |
+
'name' => 'restart_cron',
|
178 |
+
|
179 |
+
'label' => $this->__('Restart Cron, times'),
|
180 |
+
|
181 |
+
'title' => $this->__('Restart Cron, times'),
|
182 |
+
|
183 |
+
'required' => false,
|
184 |
+
|
185 |
+
'values' => array(
|
186 |
+
|
187 |
+
array('label'=>$this->__('1'), 'value'=>1),
|
188 |
+
|
189 |
+
array('label'=>$this->__('2'), 'value'=>2),
|
190 |
+
|
191 |
+
array('label'=>$this->__('3'), 'value'=>3),
|
192 |
+
|
193 |
+
array('label'=>$this->__('4'), 'value'=>4),
|
194 |
+
|
195 |
+
array('label'=>$this->__('5'), 'value'=>5),
|
196 |
+
|
197 |
+
)
|
198 |
+
|
199 |
+
));
|
200 |
+
|
201 |
+
if(!$item->getId()){
|
202 |
+
|
203 |
+
$field ->setValue('3');
|
204 |
+
|
205 |
+
}*/
|
206 |
+
|
207 |
+
if($item->getId()){
|
208 |
+
|
209 |
+
$form->setValues($item->getData());
|
210 |
+
|
211 |
+
}
|
212 |
+
|
213 |
+
return parent::_prepareForm();
|
214 |
+
|
215 |
+
}
|
216 |
+
|
217 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Content/Csv.php
ADDED
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Content_Csv extends Mage_Adminhtml_Block_Template
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $attribute_collection;
|
7 |
+
protected $options;
|
8 |
+
protected $_config;
|
9 |
+
|
10 |
+
public function __construct()
|
11 |
+
{
|
12 |
+
parent::__construct();
|
13 |
+
$this->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/ajaxupload'));
|
14 |
+
$this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
|
15 |
+
$this->getConfig()->setFileField('file');
|
16 |
+
$this->getConfig()->setFilters(array(
|
17 |
+
'all' => array(
|
18 |
+
'label' => Mage::helper('adminhtml')->__('All Files'),
|
19 |
+
'files' => array('*.*')
|
20 |
+
)
|
21 |
+
));
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getHtmlId()
|
25 |
+
{
|
26 |
+
if ($this->getData('upload_id')===null) {
|
27 |
+
$this->setData('upload_id', 'id_ranvii_feed_upload' );
|
28 |
+
}
|
29 |
+
return $this->getData('upload_id');
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getConfigJson()
|
33 |
+
{
|
34 |
+
return Zend_Json::encode($this->getConfig()->getData());
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getConfig()
|
38 |
+
{
|
39 |
+
if(is_null($this->_config)) {
|
40 |
+
$this->_config = new Varien_Object();
|
41 |
+
}
|
42 |
+
|
43 |
+
return $this->_config;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function getJsObjectName()
|
47 |
+
{
|
48 |
+
return $this->getHtmlId() . 'JsObject';
|
49 |
+
}
|
50 |
+
|
51 |
+
public function getPostMaxSize()
|
52 |
+
{
|
53 |
+
return ini_get('post_max_size');
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getUploadMaxSize()
|
57 |
+
{
|
58 |
+
return ini_get('upload_max_filesize');
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getDataMaxSize()
|
62 |
+
{
|
63 |
+
return min($this->getPostMaxSize(), $this->getUploadMaxSize());
|
64 |
+
}
|
65 |
+
|
66 |
+
public function getDataMaxSizeInBytes()
|
67 |
+
{
|
68 |
+
$iniSize = $this->getDataMaxSize();
|
69 |
+
$size = substr($iniSize, 0, strlen($iniSize)-1);
|
70 |
+
$parsedSize = 0;
|
71 |
+
switch (strtolower(substr($iniSize, strlen($iniSize)-1))) {
|
72 |
+
case 't':
|
73 |
+
$parsedSize = $size*(1024*1024*1024*1024);
|
74 |
+
break;
|
75 |
+
case 'g':
|
76 |
+
$parsedSize = $size*(1024*1024*1024);
|
77 |
+
break;
|
78 |
+
case 'm':
|
79 |
+
$parsedSize = $size*(1024*1024);
|
80 |
+
break;
|
81 |
+
case 'k':
|
82 |
+
$parsedSize = $size*1024;
|
83 |
+
break;
|
84 |
+
case 'b':
|
85 |
+
default:
|
86 |
+
$parsedSize = $size;
|
87 |
+
break;
|
88 |
+
}
|
89 |
+
return $parsedSize;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function getUploaderUrl($url)
|
93 |
+
{
|
94 |
+
if (!is_string($url)) {
|
95 |
+
$url = '';
|
96 |
+
}
|
97 |
+
$design = Mage::getDesign();
|
98 |
+
$theme = $design->getTheme('skin');
|
99 |
+
if (empty($url) || !$design->validateFile($url, array('_type' => 'skin', '_theme' => $theme))) {
|
100 |
+
$theme = $design->getDefaultTheme();
|
101 |
+
}
|
102 |
+
return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) .
|
103 |
+
$design->getArea() . '/' . $design->getPackageName() . '/' . $theme . '/' . $url;
|
104 |
+
}
|
105 |
+
|
106 |
+
public function getDeleteButtonHtml()
|
107 |
+
{
|
108 |
+
return $this->getChildHtml('delete_button');
|
109 |
+
}
|
110 |
+
|
111 |
+
protected function _prepareLayout()
|
112 |
+
{
|
113 |
+
$this->setChild(
|
114 |
+
'delete_button',
|
115 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
116 |
+
->addData(array(
|
117 |
+
'id' => '{{id}}-delete',
|
118 |
+
'class' => 'delete',
|
119 |
+
'type' => 'button',
|
120 |
+
'label' => Mage::helper('adminhtml')->__('Remove'),
|
121 |
+
'onclick' => $this->getJsObjectName() . '.removeFile(\'{{fileId}}\')'
|
122 |
+
))
|
123 |
+
);
|
124 |
+
|
125 |
+
return parent::_prepareLayout();
|
126 |
+
}
|
127 |
+
|
128 |
+
public function getFeed(){
|
129 |
+
|
130 |
+
if(Mage::registry('ranvii_feed')){
|
131 |
+
return Mage::registry('ranvii_feed');
|
132 |
+
}else{
|
133 |
+
return new Varien_Object();
|
134 |
+
}
|
135 |
+
|
136 |
+
}
|
137 |
+
|
138 |
+
public static function getAttributeCollection(){
|
139 |
+
|
140 |
+
$attribute_collection = Mage::getResourceModel('eav/entity_attribute_collection')
|
141 |
+
->setItemObjectClass('catalog/resource_eav_attribute')
|
142 |
+
->setEntityTypeFilter(Mage::getResourceModel('catalog/product')->getTypeId());
|
143 |
+
|
144 |
+
return $attribute_collection;
|
145 |
+
}
|
146 |
+
|
147 |
+
public static function getAttributeOptionsArray(){
|
148 |
+
|
149 |
+
$options = array();
|
150 |
+
|
151 |
+
$options['Product Id'] = array('code'=>"entity_id", 'label' => "Product Id");
|
152 |
+
$options['Product Type'] = array('code'=>"product_type" , 'label' => "Product Type");
|
153 |
+
$options['Is In Stock'] = array('code'=>"is_in_stock" , 'label' => "Is In Stock");
|
154 |
+
$options['Qty'] = array('code'=>"qty" , 'label' => "Qty");
|
155 |
+
$options['Image'] = array('code'=>"image" , 'label' => "Image");
|
156 |
+
$options['URL'] = array('code'=>"url" , 'label' => "URL");
|
157 |
+
/*$options['URL (Parent product)'] = array('code'=>"parent_url" , 'label' => "URL (Parent product)");*/
|
158 |
+
$options['Category'] = array('code'=>"category", 'label' => "Category");
|
159 |
+
$options['Final Price'] = array('code'=>"final_price", 'label' => "Final Price");
|
160 |
+
$options['Store Price'] = array('code'=>"store_price", 'label' => "Store Price");
|
161 |
+
$options['Image 2'] = array('code'=>"image_2", 'label' => "Image 2");
|
162 |
+
$options['Image 3'] = array('code'=>"image_3", 'label' => "Image 3");
|
163 |
+
$options['Image 4'] = array('code'=>"image_4", 'label' => "Image 4");
|
164 |
+
$options['Image 5'] = array('code'=>"image_5", 'label' => "Image 5");
|
165 |
+
$options['Parent Product Base Image'] = array('code'=>"parent_base_image" , 'label' => "Parent Base Image");
|
166 |
+
$options['Category > SubCategory'] = array('code'=>"category_subcategory", 'label' => "Category > SubCategory");
|
167 |
+
$options['Parent Product Name'] = array('code'=>"parent_name", 'label' => "Parent Product Name");
|
168 |
+
$options['Parent Product SKU'] = array('code'=>"parent_sku", 'label' => "Parent Product SKU");
|
169 |
+
$options['Parent Product URL'] = array('code'=>"parent_url", 'label' => "Parent Product URL");
|
170 |
+
$options['Parent Product Description'] = array('code'=>"parent_description" , 'label' => "Parent Product Description");
|
171 |
+
$options['Parent Product Price'] = array('code'=>"parent_product_price" , 'label' => "Parent Product Price");
|
172 |
+
$options['Parent Product Special Price'] = array('code'=>"parent_product_special_price" , 'label' => "Parent Product Special Price");
|
173 |
+
$options['Parent Product Brand'] = array('code'=>"parent_brand" , 'label' => "Parent Product Brand");
|
174 |
+
$options['Product Product Image Url'] = array('code'=>"image_link" , 'label' => "Product Product Image Url");
|
175 |
+
$options['Parent Product Name with Simple Color Size'] = array('code'=>"parent_name_color_size" , 'label' => "Parent Product Name with Simple Color Size");
|
176 |
+
|
177 |
+
|
178 |
+
foreach(self::getAttributeCollection() as $attribute){
|
179 |
+
if($attribute->getFrontendLabel()){
|
180 |
+
$options[$attribute->getFrontendLabel()] = array('code'=>$attribute->getAttributeCode(), 'label'=>($attribute->getFrontendLabel() ? $attribute->getFrontendLabel() : $attribute->getAttributeCode()));
|
181 |
+
/*$options['Parent '.$attribute->getFrontendLabel()] = array('code'=>'parent_'.$attribute->getAttributeCode(), 'label'=>($attribute->getFrontendLabel() ? 'Parent '.$attribute->getFrontendLabel() : 'Parent '.$attribute->getAttributeCode()));*/
|
182 |
+
}
|
183 |
+
|
184 |
+
}
|
185 |
+
|
186 |
+
ksort($options);
|
187 |
+
|
188 |
+
return $options;
|
189 |
+
|
190 |
+
}
|
191 |
+
public static function getAttributeSelect($i, $current = null, $active = true){
|
192 |
+
|
193 |
+
$options = array();
|
194 |
+
|
195 |
+
$options[] = "<option value=''>Not Set</option>";
|
196 |
+
|
197 |
+
foreach(self::getAttributeOptionsArray() as $attribute){
|
198 |
+
|
199 |
+
extract($attribute);
|
200 |
+
|
201 |
+
$selected = '';
|
202 |
+
|
203 |
+
if($code == $current){
|
204 |
+
$selected = 'selected="selected"';
|
205 |
+
}
|
206 |
+
|
207 |
+
$options[] = "<option value=\"{$code}\" {$selected}>{$label}</option>";
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
return '<select style="width:260px;display:'.($active ? 'block' : 'none').'" id="mapping-'.$i.'-attribute-value" name="field['.$i.'][attribute_value]">'.implode('', $options).'</select>';
|
212 |
+
|
213 |
+
}
|
214 |
+
|
215 |
+
public static function getSystemSections()
|
216 |
+
{
|
217 |
+
$data = array();
|
218 |
+
|
219 |
+
$fileDir = Mage::getBaseDir('media') . DS . 'productsfeed' . DS . 'examples';
|
220 |
+
if ($handle = opendir($fileDir))
|
221 |
+
{
|
222 |
+
while (false !== ($dir = readdir($handle))) {
|
223 |
+
if ($dir != '.' && $dir != '..')
|
224 |
+
{
|
225 |
+
if (is_dir($fileDir . DS . $dir) && ($sub_handle = opendir($fileDir . DS . $dir)))
|
226 |
+
{
|
227 |
+
$data[$dir] = array();
|
228 |
+
while (false !== ($file = readdir($sub_handle))) {
|
229 |
+
if ($file != '.' && $file != '..') {
|
230 |
+
$data[$dir][] = $file;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
closedir($sub_handle);
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
closedir($handle);
|
238 |
+
}
|
239 |
+
|
240 |
+
return $data;
|
241 |
+
|
242 |
+
}
|
243 |
+
|
244 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Main.php
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
protected function _prepareForm()
|
12 |
+
|
13 |
+
{
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
$form = new Varien_Data_Form();
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
if(Mage::registry('ranvii_feed')){
|
22 |
+
|
23 |
+
$item = Mage::registry('ranvii_feed');
|
24 |
+
|
25 |
+
}else{
|
26 |
+
|
27 |
+
$item = new Varien_Object();
|
28 |
+
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
$this->setForm($form);
|
34 |
+
|
35 |
+
$fieldset = $form->addFieldset('main_fieldset', array('legend' => $this->__('Item information')));
|
36 |
+
|
37 |
+
|
38 |
+
$fieldset->addField('type', 'hidden', array(
|
39 |
+
|
40 |
+
'name' => 'type',
|
41 |
+
|
42 |
+
));
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
$fieldset->addField('name', 'text', array(
|
47 |
+
|
48 |
+
'name' => 'name',
|
49 |
+
|
50 |
+
'label' => $this->__('Name'),
|
51 |
+
|
52 |
+
'title' => $this->__('Name'),
|
53 |
+
|
54 |
+
'required' => true,
|
55 |
+
|
56 |
+
));
|
57 |
+
|
58 |
+
if($item->getId() && ($url = $item->getUrl())){
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
$fieldset->addField('comments', 'note', array(
|
63 |
+
|
64 |
+
'label' => $this->__('Access Url'),
|
65 |
+
|
66 |
+
'title' => $this->__('Access Url'),
|
67 |
+
|
68 |
+
'text' => '<a href="'.$url.'" target="_blank">'.$url.'</a>',
|
69 |
+
|
70 |
+
));
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
$fieldset->addField('filename', 'text', array(
|
77 |
+
|
78 |
+
'name' => 'filename',
|
79 |
+
|
80 |
+
'label' => $this->__('Filename'),
|
81 |
+
|
82 |
+
'title' => $this->__('Filename'),
|
83 |
+
|
84 |
+
'required' => false,
|
85 |
+
|
86 |
+
));
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
$fieldset->addField('store_id', 'select', array(
|
91 |
+
|
92 |
+
'label' => $this->__('Store View'),
|
93 |
+
|
94 |
+
'required' => true,
|
95 |
+
|
96 |
+
'name' => 'store_id',
|
97 |
+
|
98 |
+
'values' => Mage::getModel('ranvii_feed/adminhtml_system_config_source_store')->getStoreValuesForForm(),
|
99 |
+
|
100 |
+
));
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
if(!$item->getType() && $this->getRequest()->getParam('type')){
|
105 |
+
|
106 |
+
$item->setType($this->getRequest()->getParam('type'));
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
$form->setValues($item->getData());
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
return parent::_prepareForm();
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tab/Type.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Type extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
protected function _toHtml(){
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
return parent::_toHtml().'
|
14 |
+
|
15 |
+
<script type="text/javascript">
|
16 |
+
|
17 |
+
var templateSyntax = /(^|.|\r|\n)({{(\w+)}})/;
|
18 |
+
|
19 |
+
function setSettings(urlTemplate, typeElement) {
|
20 |
+
|
21 |
+
var template = new Template(urlTemplate, templateSyntax);
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
setLocation(template.evaluate({type:$F(typeElement)}));
|
26 |
+
|
27 |
+
}
|
28 |
+
|
29 |
+
</script>';
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
protected function _prepareLayout()
|
38 |
+
|
39 |
+
{
|
40 |
+
|
41 |
+
$this->setChild('continue_button',
|
42 |
+
|
43 |
+
$this->getLayout()->createBlock('adminhtml/widget_button')
|
44 |
+
|
45 |
+
->setData(array(
|
46 |
+
|
47 |
+
'label' => $this->__('Continue'),
|
48 |
+
|
49 |
+
'onclick' => "setSettings('".$this->getContinueUrl()."','type')",
|
50 |
+
|
51 |
+
'class' => 'save'
|
52 |
+
|
53 |
+
))
|
54 |
+
|
55 |
+
);
|
56 |
+
|
57 |
+
return parent::_prepareLayout();
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
public function getContinueUrl()
|
64 |
+
|
65 |
+
{
|
66 |
+
|
67 |
+
return $this->getUrl('*/*/new', array(
|
68 |
+
|
69 |
+
'_current' => true,
|
70 |
+
|
71 |
+
'type' => '{{type}}'
|
72 |
+
|
73 |
+
));
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
protected function _prepareForm(){
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
$form = new Varien_Data_Form();
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
$this->setForm($form);
|
88 |
+
|
89 |
+
$fieldset = $form->addFieldset('main_fieldset', array('legend' => $this->__('Settings')));
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
$fieldset->addField('type', 'select', array(
|
94 |
+
|
95 |
+
'name' => 'type',
|
96 |
+
|
97 |
+
'label' => $this->__('Feed Type'),
|
98 |
+
|
99 |
+
'title' => $this->__('Feed Type'),
|
100 |
+
|
101 |
+
'required' => true,
|
102 |
+
|
103 |
+
'values' =>array('google'=>'Google Shopping','amazon'=>'Amazon Marketplace','other'=>'CPC Strategy'),
|
104 |
+
|
105 |
+
));
|
106 |
+
|
107 |
+
|
108 |
+
$fieldset->addField('continue_button', 'note', array(
|
109 |
+
|
110 |
+
'text' => $this->getChildHtml('continue_button'),
|
111 |
+
|
112 |
+
));
|
113 |
+
|
114 |
+
return parent::_prepareForm();
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Edit/Tabs.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function __construct(){
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
parent::__construct();
|
12 |
+
|
13 |
+
$this->setId('ranvii_feed_tabs');
|
14 |
+
|
15 |
+
$this->setDestElementId('edit_form');
|
16 |
+
|
17 |
+
$this->setTitle($this->__('Feed Information'));
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
protected function _prepareLayout(){
|
26 |
+
|
27 |
+
if(($type = $this->getRequest()->getParam('type', null)) || (Mage::registry('ranvii_feed') && ($type = Mage::registry('ranvii_feed')->getType()))){
|
28 |
+
|
29 |
+
|
30 |
+
$this->addTab('main_section', array(
|
31 |
+
|
32 |
+
'label' => $this->__('Item information'),
|
33 |
+
|
34 |
+
'title' => $this->__('Item information'),
|
35 |
+
|
36 |
+
'content' => $this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tab_main')->toHtml(),
|
37 |
+
|
38 |
+
));
|
39 |
+
|
40 |
+
$this->addTab('content_section', array(
|
41 |
+
|
42 |
+
'label' => $this->__('Content Settings'),
|
43 |
+
|
44 |
+
'title' => $this->__('Content Settings'),
|
45 |
+
|
46 |
+
'content' => $this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tab_content_csv')
|
47 |
+
|
48 |
+
->setTemplate('ranvii/feed/item/edit/content.phtml')->toHtml(),
|
49 |
+
|
50 |
+
));
|
51 |
+
|
52 |
+
|
53 |
+
$this->addTab('advanced', array(
|
54 |
+
|
55 |
+
'label' => $this->__('Advanced Settings'),
|
56 |
+
|
57 |
+
'title' => $this->__('Advanced Settings'),
|
58 |
+
|
59 |
+
'content' => $this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tab_advanced')->toHtml(),
|
60 |
+
|
61 |
+
));
|
62 |
+
|
63 |
+
}else{
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
$this->addTab('main_section', array(
|
68 |
+
|
69 |
+
'label' => $this->__('Content Settings'),
|
70 |
+
|
71 |
+
'title' => $this->__('Content Settings'),
|
72 |
+
|
73 |
+
'content' => $this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tab_type')->toHtml(),
|
74 |
+
|
75 |
+
));
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
}
|
80 |
+
|
81 |
+
if($tabId = addslashes(htmlspecialchars($this->getRequest()->getParam('tab')))){
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
$this->setActiveTab($tabId);
|
86 |
+
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
return parent::_beforeToHtml();
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid.php
ADDED
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
public function __construct(){
|
10 |
+
|
11 |
+
parent::__construct();
|
12 |
+
|
13 |
+
$this->setId('ranvifeedsGrid');
|
14 |
+
|
15 |
+
$this->setDefaultSort('date');
|
16 |
+
|
17 |
+
$this->setDefaultDir('DESC');
|
18 |
+
|
19 |
+
$this->setSaveParametersInSession(true);
|
20 |
+
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
protected function _prepareCollection(){
|
26 |
+
|
27 |
+
$collection = Mage::getModel('ranvii_feed/item')->getCollection();
|
28 |
+
|
29 |
+
$this->setCollection($collection);
|
30 |
+
|
31 |
+
return parent::_prepareCollection();
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
protected function _prepareColumns(){
|
38 |
+
|
39 |
+
$this->addColumn('id', array(
|
40 |
+
|
41 |
+
'header' => $this->__('ID'),
|
42 |
+
|
43 |
+
'align' => 'left',
|
44 |
+
|
45 |
+
'index' => 'id',
|
46 |
+
|
47 |
+
'type' => 'number',
|
48 |
+
|
49 |
+
'width' => '50px',
|
50 |
+
|
51 |
+
));
|
52 |
+
|
53 |
+
$this->addColumn('name', array(
|
54 |
+
|
55 |
+
'header' => $this->__('Name'),
|
56 |
+
|
57 |
+
'align' => 'left',
|
58 |
+
|
59 |
+
'index' => 'name',
|
60 |
+
|
61 |
+
));
|
62 |
+
|
63 |
+
$this->addColumn('filename', array(
|
64 |
+
|
65 |
+
'header' => $this->__('Access Url'),
|
66 |
+
|
67 |
+
'align' =>'left',
|
68 |
+
|
69 |
+
'index' => 'filename',
|
70 |
+
|
71 |
+
'renderer' => 'Ranvii_Feed_Block_Adminhtml_Items_Grid_Renderer_AccessUrl'
|
72 |
+
|
73 |
+
));
|
74 |
+
|
75 |
+
$this->addColumn('last_generated', array(
|
76 |
+
|
77 |
+
'header' => $this->__('Last Generated'),
|
78 |
+
|
79 |
+
'align' => 'left',
|
80 |
+
|
81 |
+
'index' => 'generated_at',
|
82 |
+
|
83 |
+
'type' => 'datetime',
|
84 |
+
|
85 |
+
'renderer' => 'Ranvii_Feed_Block_Adminhtml_Items_Grid_Renderer_Datetime'
|
86 |
+
|
87 |
+
));
|
88 |
+
|
89 |
+
$this->addColumn('store_id', array(
|
90 |
+
|
91 |
+
'header' => $this->__('Store View'),
|
92 |
+
|
93 |
+
'align' => 'left',
|
94 |
+
|
95 |
+
'index' => 'store_id',
|
96 |
+
|
97 |
+
'type' => 'store',
|
98 |
+
|
99 |
+
));
|
100 |
+
|
101 |
+
|
102 |
+
$this->addColumn('action', array(
|
103 |
+
|
104 |
+
'header' => $this->__('Action'),
|
105 |
+
|
106 |
+
'width' => '100',
|
107 |
+
|
108 |
+
'type' => 'action',
|
109 |
+
|
110 |
+
'getter' => 'getId',
|
111 |
+
|
112 |
+
'actions' => array(
|
113 |
+
|
114 |
+
array(
|
115 |
+
|
116 |
+
'caption' => $this->__('Edit'),
|
117 |
+
|
118 |
+
'url' => array('base'=> '*/*/edit'),
|
119 |
+
|
120 |
+
'field' => 'id'
|
121 |
+
|
122 |
+
)
|
123 |
+
|
124 |
+
),
|
125 |
+
|
126 |
+
'filter' => false,
|
127 |
+
|
128 |
+
'sortable' => false,
|
129 |
+
|
130 |
+
'index' => 'stores',
|
131 |
+
|
132 |
+
'is_system' => true,
|
133 |
+
|
134 |
+
));
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
return parent::_prepareColumns();
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
protected function _prepareMassaction(){
|
147 |
+
|
148 |
+
|
149 |
+
|
150 |
+
$this->setMassactionIdField('id');
|
151 |
+
|
152 |
+
$this->getMassactionBlock()->setFormFieldName('id');
|
153 |
+
|
154 |
+
|
155 |
+
|
156 |
+
$this->getMassactionBlock()->addItem('delete', array(
|
157 |
+
|
158 |
+
'label' => $this->__('Delete Feed(s)'),
|
159 |
+
|
160 |
+
'url' => $this->getUrl('*/*/massDelete'),
|
161 |
+
|
162 |
+
'confirm' => $this->__('Are you sure?')
|
163 |
+
|
164 |
+
));
|
165 |
+
|
166 |
+
|
167 |
+
|
168 |
+
|
169 |
+
|
170 |
+
return $this;
|
171 |
+
|
172 |
+
|
173 |
+
|
174 |
+
}
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
protected function _afterLoadCollection(){
|
181 |
+
|
182 |
+
|
183 |
+
|
184 |
+
$this->getCollection()->walk('afterLoad');
|
185 |
+
|
186 |
+
parent::_afterLoadCollection();
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
|
193 |
+
|
194 |
+
protected function _filterStoreCondition($collection, $column){
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
if (!$value = $column->getFilter()->getValue()) {
|
199 |
+
|
200 |
+
return;
|
201 |
+
|
202 |
+
}
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
+
$this->getCollection()->addStoreFilter($value);
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
}
|
211 |
+
|
212 |
+
|
213 |
+
|
214 |
+
public function getRowUrl($row){
|
215 |
+
|
216 |
+
|
217 |
+
|
218 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
219 |
+
|
220 |
+
|
221 |
+
|
222 |
+
}
|
223 |
+
|
224 |
+
|
225 |
+
|
226 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid/Renderer/AccessUrl.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Grid_Renderer_AccessUrl extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
public function render(Varien_Object $feed){
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
if($url = $feed->getUrl()){
|
12 |
+
|
13 |
+
return sprintf('<a href="%s" target="_blank">%s</a>', $url, $url);
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
app/code/community/Ranvii/Feed/Block/Adminhtml/Items/Grid/Renderer/Datetime.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Block_Adminhtml_Items_Grid_Renderer_Datetime extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Datetime{
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
public function render(Varien_Object $row)
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
if('0000-00-00 00:00:00' == $this->_getValue($row)){
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
return $this->getColumn()->getDefault();
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
return parent::render($row);
|
22 |
+
|
23 |
+
}
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
}
|
app/code/community/Ranvii/Feed/Helper/Data.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Helper_Data extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
public function getConfigData($node){
|
6 |
+
return Mage::getStoreConfig('ranvii_feed/'.$node);
|
7 |
+
}
|
8 |
+
|
9 |
+
public function getAllStoreDomains(){
|
10 |
+
|
11 |
+
$domains = array();
|
12 |
+
|
13 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
14 |
+
|
15 |
+
$url = $website->getConfig('web/unsecure/base_url');
|
16 |
+
|
17 |
+
if($domain = trim(preg_replace('/^.*?\\/\\/(.*)?\\//', '$1', $url))){
|
18 |
+
|
19 |
+
$domains[] = $domain;
|
20 |
+
|
21 |
+
}
|
22 |
+
|
23 |
+
$url = $website->getConfig('web/secure/base_url');
|
24 |
+
|
25 |
+
if($domain = trim(preg_replace('/^.*?\\/\\/(.*)?\\//', '$1', $url))){
|
26 |
+
|
27 |
+
$domains[] = $domain;
|
28 |
+
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|
32 |
+
|
33 |
+
return array_unique($domains);
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
public function getAmazonContentJson(){
|
39 |
+
|
40 |
+
$data = '[{"order":0,"name":"Id","attribute_value":"sku"},{"order":0,"name":"title","attribute_value":"name"},{"order":0,"name":"description","attribute_value":"description"},{"order":0,"name":"link","attribute_value":"url"},{"order":0,"name":"price","attribute_value":"price"},{"order":0,"name":"brand","attribute_value":"brand"},{"order":0,"name":"image_link","attribute_value":"image_link"},{"order":0,"name":"product_type","attribute_value":"product_type"},{"order":0,"name":"condition","attribute_value":"condition"},{"order":0,"name":"availability","attribute_value":"is_in_stock"},{"order":0,"name":"gtin","attribute_value":"gtin"},{"order":0,"name":"google_product_category","attribute_value":"google_product_category"},{"order":0,"name":"shipping_weight","attribute_value":"weight"},{"order":0,"name":"tax","attribute_value":"tax_class_id"},{"order":0,"name":"mpn","attribute_value":"mpn"},{"order":0,"name":"gender","attribute_value":"gender"},{"order":0,"name":"size","attribute_value":"size"},{"order":0,"name":"dispenser","attribute_value":"dispenser"},{"order":0,"name":"p_type","attribute_value":"p_type"},{"order":0,"name":"stock_qty","attribute_value":"qty"},{"order":0,"name":"amazon_price","attribute_value":"amazon_price"}]';
|
41 |
+
|
42 |
+
return $data;
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
public function getGoogleContentJson(){
|
48 |
+
|
49 |
+
$data = '[{"order":0,"name":"Id","attribute_value":"sku"},{"order":0,"name":"title","attribute_value":"name"},{"order":0,"name":"description","attribute_value":"description"},{"order":0,"name":"link","attribute_value":"url"},{"order":0,"name":"price","attribute_value":"price"},{"order":0,"name":"brand","attribute_value":"brand"},{"order":0,"name":"condition","attribute_value":"condition"},{"order":0,"name":"image_link","attribute_value":"image_link"},{"order":0,"name":"gtin","attribute_value":"gtin"},{"order":0,"name":"shipping","attribute_value":"shipment_type"},{"order":0,"name":"product_type","attribute_value":"product_type"},{"order":0,"name":"google_product_category","attribute_value":"google_product_category"},{"order":0,"name":"color","attribute_value":"color"},{"order":0,"name":"size","attribute_value":"size"},{"order":0,"name":"mpn","attribute_value":"mpn"},{"order":0,"name":"age group","attribute_value":"age_group"},{"order":0,"name":"gender","attribute_value":"gender"},{"order":0,"name":"availability","attribute_value":"is_in_stock"},{"order":0,"name":"c:druse:boolean","attribute_value":"c_druse"},{"order":0,"name":"item_group_id","attribute_value":"item_group_id"}]';
|
50 |
+
|
51 |
+
return $data;
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
app/code/community/Ranvii/Feed/Model/Adminhtml/System/Config/Source/Store.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Adminhtml_System_Config_Source_Store extends Mage_Adminhtml_Model_System_Store
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/community/Ranvii/Feed/Model/Custom/Attribute.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Custom_Attribute extends Mage_Core_Model_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
public function _construct()
|
10 |
+
|
11 |
+
{
|
12 |
+
|
13 |
+
parent::_construct();
|
14 |
+
|
15 |
+
$this->_init('ranvii_feed/custom_attribute');
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
}
|
app/code/community/Ranvii/Feed/Model/Item.php
ADDED
@@ -0,0 +1,887 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Item extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_productCollection;
|
7 |
+
protected $_categoryCollection;
|
8 |
+
protected $_parentProductsCache = array();
|
9 |
+
|
10 |
+
public function _construct()
|
11 |
+
{
|
12 |
+
parent::_construct();
|
13 |
+
$this->_init('ranvii_feed/item');
|
14 |
+
}
|
15 |
+
|
16 |
+
public function getCategoriesCollection(){
|
17 |
+
|
18 |
+
if(is_null($this->_categoryCollection)){
|
19 |
+
|
20 |
+
$this->_categoryCollection = Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name');
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
return $this->_categoryCollection;
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getParentProduct(Varien_Object $product, $collection = null){
|
29 |
+
|
30 |
+
if (!isset($this->_parentProductsCache[$product->getEntityId()])){
|
31 |
+
|
32 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('read');
|
33 |
+
$table = Mage::getSingleton('core/resource')->getTableName('catalog_product_relation');
|
34 |
+
|
35 |
+
$parent_product = null;
|
36 |
+
|
37 |
+
$parent_id = $connection->fetchOne('SELECT `parent_id` FROM '.$table.' WHERE `child_id` = '.intval($product->getEntityId()));
|
38 |
+
|
39 |
+
if($parent_id > 0){
|
40 |
+
|
41 |
+
if($collection){
|
42 |
+
|
43 |
+
$parent_product = $collection->getItemById($parent_id);
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
if(!$parent_product){
|
48 |
+
|
49 |
+
$parent_product = Mage::getModel('catalog/product')->load($parent_id);
|
50 |
+
|
51 |
+
}
|
52 |
+
|
53 |
+
$this->_parentProductsCache[$product->getEntityId()] = $parent_product;
|
54 |
+
|
55 |
+
}else{
|
56 |
+
|
57 |
+
$this->_parentProductsCache[$product->getEntityId()] = new Varien_Object();
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
return $this->_parentProductsCache[$product->getEntityId()];
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getRootCategory()
|
68 |
+
{
|
69 |
+
$category = Mage::getModel('catalog/category')->load(Mage::app()->getStore()->getRootCategoryId());
|
70 |
+
return $category;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function getProductsCollection($filterData = '', $current_page = 0, $length = 50){
|
74 |
+
|
75 |
+
|
76 |
+
//if (is_null($this->_productCollection) && $this->getId()){
|
77 |
+
|
78 |
+
$collection = Mage::getModel('ranvii_feed/product_collection')->addAttributeToSelect('*');
|
79 |
+
|
80 |
+
$collection->addStoreFilter(Mage::app()->getStore());
|
81 |
+
|
82 |
+
/*if($length != 0){
|
83 |
+
$collection->setPage($current_page+1, $length);
|
84 |
+
}*/
|
85 |
+
$fileDir = sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
86 |
+
|
87 |
+
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
|
88 |
+
->addMinimalPrice()
|
89 |
+
->addFinalPrice()
|
90 |
+
->addTaxPercents()
|
91 |
+
->addUrlRewrite($this->getRootCategory()->getId());
|
92 |
+
|
93 |
+
|
94 |
+
if($this->getUseLayer()){
|
95 |
+
$collection->joinField('is_in_stock',
|
96 |
+
'cataloginventory/stock_item',
|
97 |
+
'is_in_stock',
|
98 |
+
'product_id=entity_id');
|
99 |
+
$collection->addAttributeToFilter('is_in_stock', array('eq'=>Mage_CatalogInventory_Model_Stock::STOCK_IN_STOCK));
|
100 |
+
}
|
101 |
+
|
102 |
+
if($this->getUseDisabled()){
|
103 |
+
|
104 |
+
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
|
105 |
+
$collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
$this->_productCollection = $collection;
|
110 |
+
|
111 |
+
//}
|
112 |
+
|
113 |
+
return $this->_productCollection;
|
114 |
+
}
|
115 |
+
|
116 |
+
public function save(){
|
117 |
+
if(!$this->getFilename()){
|
118 |
+
|
119 |
+
$this->setFilename(preg_replace('/[^\w\d]/', '-', trim(strtolower($this->getName()))).'.csv');
|
120 |
+
|
121 |
+
}
|
122 |
+
if(strpos($this->getFilename(), '.') === false){
|
123 |
+
|
124 |
+
$this->setFilename($this->getFilename().'.csv');
|
125 |
+
}
|
126 |
+
|
127 |
+
if($id = Mage::getModel('ranvii_feed/item')->load($this->getFilename(), 'filename')->getId()){
|
128 |
+
|
129 |
+
if($id != $this->getId()){
|
130 |
+
|
131 |
+
throw new Mage_Core_Exception(Mage::helper('ranvii_feed')->__('Filename "%s" exists', $this->getFilename()));
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
}
|
136 |
+
|
137 |
+
return parent::save();
|
138 |
+
}
|
139 |
+
|
140 |
+
public function getDirPath(){
|
141 |
+
return sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
public function getTempFilePath($start){
|
146 |
+
$filename = 'feed-gen-data-'.$this->getId().$start.'.tmp';
|
147 |
+
return sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $filename);
|
148 |
+
}
|
149 |
+
|
150 |
+
public function writeTempFile($start, $length, $filename = ''){
|
151 |
+
|
152 |
+
try{
|
153 |
+
|
154 |
+
//echo " length ".$length;
|
155 |
+
$filePath = $this->getTempFilePath($start);
|
156 |
+
|
157 |
+
$fileDir = sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
158 |
+
|
159 |
+
|
160 |
+
if(!file_exists($fileDir)){
|
161 |
+
|
162 |
+
mkdir($fileDir);
|
163 |
+
|
164 |
+
chmod($fileDir, 0777);
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
if(is_dir($fileDir)){
|
169 |
+
|
170 |
+
switch($this->getDelimiter()):
|
171 |
+
case('comma'):default:
|
172 |
+
$delimiter = ",";
|
173 |
+
break;
|
174 |
+
case('tab'):
|
175 |
+
$delimiter = "\t";
|
176 |
+
break;
|
177 |
+
case('colon'):
|
178 |
+
$delimiter = ":";
|
179 |
+
break;
|
180 |
+
case('space'):
|
181 |
+
$delimiter = " ";
|
182 |
+
break;
|
183 |
+
case('vertical pipe'):
|
184 |
+
$delimiter = "|";
|
185 |
+
break;
|
186 |
+
case('semi-colon'):
|
187 |
+
$delimiter = ";";
|
188 |
+
break;
|
189 |
+
endswitch;
|
190 |
+
|
191 |
+
switch($this->getEnclosure()):
|
192 |
+
|
193 |
+
case(1): default:
|
194 |
+
|
195 |
+
$enclosure = "'";
|
196 |
+
|
197 |
+
break;
|
198 |
+
|
199 |
+
case(2):
|
200 |
+
|
201 |
+
$enclosure = '"';
|
202 |
+
|
203 |
+
break;
|
204 |
+
|
205 |
+
case(3):
|
206 |
+
|
207 |
+
$enclosure = ' ';
|
208 |
+
|
209 |
+
break;
|
210 |
+
|
211 |
+
endswitch;
|
212 |
+
|
213 |
+
|
214 |
+
$collection = $this->getProductsCollection();
|
215 |
+
$collection->getSelect()->limit($length, $start);
|
216 |
+
//echo "<br><br>Count: ". count($collection);
|
217 |
+
$maping = json_decode($this->getContent());
|
218 |
+
|
219 |
+
$fp = fopen($filePath, 'w');
|
220 |
+
|
221 |
+
$codes = array();
|
222 |
+
|
223 |
+
foreach($maping as $col){
|
224 |
+
//echo "<pre>";print_r($col);exit;
|
225 |
+
//if($col->type == 'attribute'){
|
226 |
+
|
227 |
+
$codes[] = $col->attribute_value;
|
228 |
+
|
229 |
+
//}
|
230 |
+
|
231 |
+
}
|
232 |
+
|
233 |
+
$attributes = Mage::getModel('eav/entity_attribute')
|
234 |
+
->getCollection()
|
235 |
+
->setEntityTypeFilter(Mage::getResourceModel('catalog/product')->getEntityType()->getData('entity_type_id'))
|
236 |
+
->setCodeFilter($codes);
|
237 |
+
|
238 |
+
$log_fp = fopen(sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-'.$this->getId().'.txt'), 'a');
|
239 |
+
fwrite($log_fp, date("F j, Y, g:i:s a").', page:'.$start.', items selected:'.count($collection)."\n");
|
240 |
+
fclose($log_fp);
|
241 |
+
|
242 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
243 |
+
$root_category = Mage::getModel('catalog/category')->load($store->getRootCategoryId());
|
244 |
+
|
245 |
+
if (Mage::getStoreConfig('ranvii_feedpro/imagesettings/enable')){
|
246 |
+
$image_width = intval(Mage::getStoreConfig('ranvii_feedpro/imagesettings/width'));
|
247 |
+
$image_height = intval(Mage::getStoreConfig('ranvii_feedpro/imagesettings/height'));
|
248 |
+
}else{
|
249 |
+
$image_width = 0;
|
250 |
+
$image_height = 0;
|
251 |
+
}
|
252 |
+
$stock_collection = Mage::getResourceModel('cataloginventory/stock_item_collection');
|
253 |
+
|
254 |
+
foreach($collection as $product){
|
255 |
+
|
256 |
+
//echo "<br>Product: ".$product->getId();
|
257 |
+
$fields = array();
|
258 |
+
|
259 |
+
$category = null;
|
260 |
+
|
261 |
+
foreach($product->getCategoryIds() as $id){
|
262 |
+
|
263 |
+
$_category = $this->getCategoriesCollection()->getItemById($id);
|
264 |
+
|
265 |
+
if(is_null($category) || ($category && $_category && $category->getLevel() < $_category->getLevel())){
|
266 |
+
|
267 |
+
$category = $_category;
|
268 |
+
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
if($category){
|
273 |
+
|
274 |
+
$category_path = array($category->getName());
|
275 |
+
|
276 |
+
$parent_id = $category->getParentId();
|
277 |
+
|
278 |
+
if($category->getLevel() > $root_category->getLevel()){
|
279 |
+
|
280 |
+
while($_category = $this->getCategoriesCollection()->getItemById($parent_id)){
|
281 |
+
|
282 |
+
if($_category->getLevel() <= $root_category->getLevel()){
|
283 |
+
break;
|
284 |
+
}
|
285 |
+
|
286 |
+
$category_path[] = $_category->getName();
|
287 |
+
$parent_id = $_category->getParentId();
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
$product->setCategory($category->getName());
|
292 |
+
$product->setCategoryId($category->getEntityId());
|
293 |
+
$product->setCategorySubcategory(implode(' > ', array_reverse($category_path)));
|
294 |
+
|
295 |
+
}else{
|
296 |
+
$product->setCategory('');
|
297 |
+
$product->setCategorySubcategory('');
|
298 |
+
}
|
299 |
+
$parent_product = $this->getParentProduct($product, $collection);
|
300 |
+
$_prod = Mage::getModel('catalog/product')->load($product->getId());
|
301 |
+
|
302 |
+
foreach($maping as $col){
|
303 |
+
|
304 |
+
$value = null;
|
305 |
+
|
306 |
+
if ($col->attribute_value) {
|
307 |
+
|
308 |
+
switch($col->attribute_value){
|
309 |
+
|
310 |
+
case ('parent_sku'):
|
311 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
312 |
+
$value = $parent_product->getSku();
|
313 |
+
}else{
|
314 |
+
$value = '';
|
315 |
+
}
|
316 |
+
break;
|
317 |
+
|
318 |
+
case ('price'):
|
319 |
+
|
320 |
+
if(in_array($product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)))
|
321 |
+
$value = $store->convertPrice($product->getMinimalPrice(), false, false);
|
322 |
+
else
|
323 |
+
$value = $store->convertPrice($product->getPrice(), false, false);
|
324 |
+
|
325 |
+
break;
|
326 |
+
|
327 |
+
case ('store_price'):
|
328 |
+
|
329 |
+
$value = $store->convertPrice($product->getFinalPrice(), false, false);
|
330 |
+
|
331 |
+
break;
|
332 |
+
|
333 |
+
|
334 |
+
case ('parent_url'):
|
335 |
+
|
336 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
337 |
+
|
338 |
+
$value = $parent_product->getProductUrl(false);
|
339 |
+
|
340 |
+
break;
|
341 |
+
|
342 |
+
}
|
343 |
+
|
344 |
+
$value = $product->getProductUrl(false);
|
345 |
+
|
346 |
+
break;
|
347 |
+
|
348 |
+
case 'parent_base_image':
|
349 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
350 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
351 |
+
}
|
352 |
+
try{
|
353 |
+
if ($image_width || $image_height){
|
354 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
355 |
+
}else{
|
356 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
357 |
+
}
|
358 |
+
|
359 |
+
}catch(Exception $e){
|
360 |
+
$image_url = '';
|
361 |
+
}
|
362 |
+
$value = $image_url;
|
363 |
+
break;
|
364 |
+
case 'parent_description':
|
365 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
366 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
367 |
+
}
|
368 |
+
try{
|
369 |
+
$description= $_prod->getDescription();
|
370 |
+
}catch(Exception $e){
|
371 |
+
$description= '';
|
372 |
+
}
|
373 |
+
$value = $description;
|
374 |
+
break;
|
375 |
+
case 'parent_product_price':
|
376 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
377 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
378 |
+
}
|
379 |
+
try{
|
380 |
+
$price= $_prod->getResource()->getAttribute('price')->getFrontend()->getValue($_prod);
|
381 |
+
}catch(Exception $e){
|
382 |
+
$price= '';
|
383 |
+
}
|
384 |
+
$value = number_format($price);
|
385 |
+
break;
|
386 |
+
case 'parent_product_special_price':
|
387 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
388 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
389 |
+
}
|
390 |
+
try{
|
391 |
+
$specialprice= $_prod->getResource()->getAttribute('special_price')->getFrontend()->getValue($_prod);
|
392 |
+
}catch(Exception $e){
|
393 |
+
$specialprice= '';
|
394 |
+
}
|
395 |
+
$value = number_format($specialprice);
|
396 |
+
break;
|
397 |
+
case 'parent_brand':
|
398 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
399 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
400 |
+
}
|
401 |
+
try{
|
402 |
+
$brand= $_prod->getResource()->getAttribute('brand')->getFrontend()->getValue($_prod);
|
403 |
+
}catch(Exception $e){
|
404 |
+
$brand= '';
|
405 |
+
}
|
406 |
+
$value = $brand;
|
407 |
+
break;
|
408 |
+
case 'image_link':
|
409 |
+
|
410 |
+
|
411 |
+
$url=Mage::getBaseUrl('media')."catalog/product".$_prod->getImage();
|
412 |
+
if(!$_prod->getImage()){
|
413 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
414 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
415 |
+
$url=Mage::getBaseUrl('media')."catalog/product".$_prod->getImage();
|
416 |
+
}
|
417 |
+
}else{
|
418 |
+
$url=Mage::getBaseUrl('media')."catalog/product".$_prod->getImage();
|
419 |
+
}
|
420 |
+
if($url==Mage::getBaseUrl('media')."catalog/product" || $url==Mage::getBaseUrl('media')."catalog/productno_selection" ){
|
421 |
+
$url=Mage::getBaseUrl('media')."catalog/product/i/m/img-na-450_1.jpg";
|
422 |
+
}
|
423 |
+
$value = $url;
|
424 |
+
break;
|
425 |
+
case 'parent_name':
|
426 |
+
try{
|
427 |
+
if($parent_product && $parent_product->getEntityId() > 0){
|
428 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
429 |
+
$name=$_prod->getName();
|
430 |
+
}
|
431 |
+
}catch(Exception $e){
|
432 |
+
$name= '';
|
433 |
+
}
|
434 |
+
$value = $name;
|
435 |
+
break;
|
436 |
+
case('image'):
|
437 |
+
case('gallery'):
|
438 |
+
case('media_gallery'):
|
439 |
+
|
440 |
+
if (!$product->hasData('product_base_image'))
|
441 |
+
{
|
442 |
+
try{
|
443 |
+
if ($image_width || $image_height){
|
444 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
445 |
+
}else{
|
446 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
447 |
+
}
|
448 |
+
|
449 |
+
}catch(Exception $e){
|
450 |
+
$image_url = '';
|
451 |
+
}
|
452 |
+
$product->setData('product_base_image', $image_url);
|
453 |
+
$value = $image_url;
|
454 |
+
|
455 |
+
}
|
456 |
+
else
|
457 |
+
{
|
458 |
+
$value = $product->getData('product_base_image');
|
459 |
+
}
|
460 |
+
|
461 |
+
break;
|
462 |
+
case('image_2'):
|
463 |
+
case('image_3'):
|
464 |
+
case('image_4'):
|
465 |
+
case('image_5'):
|
466 |
+
if (!$product->hasData('media_gallery_images'))
|
467 |
+
{
|
468 |
+
$product->setData('media_gallery_images', $_prod->getMediaGalleryImages());
|
469 |
+
}
|
470 |
+
$i = 0;
|
471 |
+
foreach ($product->getMediaGalleryImages() as $_image)
|
472 |
+
{
|
473 |
+
$i++;
|
474 |
+
if (('image_' . $i) == $col->attribute_value){
|
475 |
+
if ($image_width || $image_height){
|
476 |
+
$value = (string)Mage::helper('catalog/image')->init($product, 'image', $_image->getFile())->resize($image_width, $image_height);
|
477 |
+
}else{
|
478 |
+
$value = $_image['url'];
|
479 |
+
}
|
480 |
+
}
|
481 |
+
}
|
482 |
+
break;
|
483 |
+
case('url'):
|
484 |
+
$value = $product->getProductUrl(false);
|
485 |
+
break;
|
486 |
+
case('qty'):
|
487 |
+
|
488 |
+
$value = ceil((int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty());
|
489 |
+
break;
|
490 |
+
case('category'):
|
491 |
+
|
492 |
+
$value = $product->getCategory();
|
493 |
+
|
494 |
+
break;
|
495 |
+
case ('product_type'):
|
496 |
+
|
497 |
+
$value = $product->getTypeId();
|
498 |
+
|
499 |
+
break;
|
500 |
+
|
501 |
+
default:
|
502 |
+
|
503 |
+
if($attribute = $attributes->getItemByColumnValue('attribute_code', $col->attribute_value)){
|
504 |
+
|
505 |
+
if($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect'){
|
506 |
+
|
507 |
+
$value = implode(', ', (array)$product->getAttributeText($col->attribute_value));
|
508 |
+
|
509 |
+
}else{
|
510 |
+
|
511 |
+
$value = $product->getData($col->attribute_value);
|
512 |
+
|
513 |
+
}
|
514 |
+
|
515 |
+
}else{
|
516 |
+
|
517 |
+
$value = $product->getData($col->attribute_value);
|
518 |
+
|
519 |
+
}
|
520 |
+
|
521 |
+
break;
|
522 |
+
}
|
523 |
+
|
524 |
+
} else {
|
525 |
+
|
526 |
+
$value = '';
|
527 |
+
|
528 |
+
}
|
529 |
+
|
530 |
+
$fields[] = $value;
|
531 |
+
}
|
532 |
+
|
533 |
+
if ($enclosure != ' ') {
|
534 |
+
fputcsv($fp, $fields, $delimiter, $enclosure);
|
535 |
+
} else {
|
536 |
+
$this->myfputcsv($fp, $fields, $delimiter);
|
537 |
+
}
|
538 |
+
|
539 |
+
if ( $product != null ) {
|
540 |
+
$product->clearInstance();
|
541 |
+
}
|
542 |
+
|
543 |
+
}
|
544 |
+
|
545 |
+
fclose($fp);
|
546 |
+
foreach ( $this->_parentProductsCache as $one_cache_key => $one_cache_val ) {
|
547 |
+
if ( $one_cache_val != null && $one_cache_val instanceof Mage_Core_Model_Abstract ) {
|
548 |
+
$one_cache_val->clearInstance();
|
549 |
+
}
|
550 |
+
unset( $this->_parentProductsCache[ $one_cache_key ] );
|
551 |
+
unset( $one_cache_val );
|
552 |
+
}
|
553 |
+
$this->_parentProductsCache = array();
|
554 |
+
$collection->clear();
|
555 |
+
unset( $collection );
|
556 |
+
gc_collect_cycles();
|
557 |
+
|
558 |
+
}
|
559 |
+
} catch (Mage_Core_Exception $e) {
|
560 |
+
//mail('___CHANGEME___','exception1',$e->getMessage());
|
561 |
+
} catch(Exception $e){
|
562 |
+
Mage::logException($e);
|
563 |
+
//mail('___CHANGEME___',' exception #2', date('r') ."\n===============================================\n". $e->getMessage() ."\n\n=========================================\n". $e->getTraceAsString() );
|
564 |
+
}
|
565 |
+
|
566 |
+
|
567 |
+
|
568 |
+
}
|
569 |
+
|
570 |
+
public function generate(){
|
571 |
+
|
572 |
+
|
573 |
+
$fileDir = sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
574 |
+
$filePath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $this->getFilename());
|
575 |
+
$logFilepath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-'.$this->getId().'.txt');
|
576 |
+
|
577 |
+
@unlink($filePath);
|
578 |
+
@unlink($logFilepath);
|
579 |
+
|
580 |
+
|
581 |
+
$filePath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $this->getFilename());
|
582 |
+
|
583 |
+
if(!file_exists($fileDir)){
|
584 |
+
|
585 |
+
mkdir($fileDir);
|
586 |
+
|
587 |
+
chmod($fileDir, 0777);
|
588 |
+
|
589 |
+
}
|
590 |
+
|
591 |
+
if(is_dir($fileDir)){
|
592 |
+
|
593 |
+
switch($this->getDelimiter()):
|
594 |
+
case('comma'):default:
|
595 |
+
$delimiter = ",";
|
596 |
+
break;
|
597 |
+
case('tab'):
|
598 |
+
$delimiter = "\t";
|
599 |
+
break;
|
600 |
+
case('colon'):
|
601 |
+
$delimiter = ":";
|
602 |
+
break;
|
603 |
+
case('space'):
|
604 |
+
$delimiter = " ";
|
605 |
+
break;
|
606 |
+
case('vertical pipe'):
|
607 |
+
$delimiter = "|";
|
608 |
+
break;
|
609 |
+
case('semi-colon'):
|
610 |
+
$delimiter = ";";
|
611 |
+
break;
|
612 |
+
endswitch;
|
613 |
+
//$delimiter = $this->getDelimiter();
|
614 |
+
|
615 |
+
switch($this->getEnclosure()):
|
616 |
+
|
617 |
+
case(1): default:
|
618 |
+
|
619 |
+
$enclosure = "'";
|
620 |
+
|
621 |
+
break;
|
622 |
+
|
623 |
+
case(2):
|
624 |
+
|
625 |
+
$enclosure = '"';
|
626 |
+
|
627 |
+
break;
|
628 |
+
|
629 |
+
case(3):
|
630 |
+
|
631 |
+
$enclosure = ' ';
|
632 |
+
|
633 |
+
break;
|
634 |
+
|
635 |
+
endswitch;
|
636 |
+
|
637 |
+
$maping = json_decode($this->getContent());
|
638 |
+
$fp = fopen($filePath, 'w');
|
639 |
+
|
640 |
+
if ($this->getData('use_addition_header') == 1){
|
641 |
+
fwrite($fp, $this->getData('addition_header'));
|
642 |
+
}
|
643 |
+
|
644 |
+
if($this->getShowHeaders()){
|
645 |
+
|
646 |
+
$fields = array();
|
647 |
+
|
648 |
+
foreach($maping as $col){
|
649 |
+
|
650 |
+
$fields[] = $col->name;
|
651 |
+
|
652 |
+
}
|
653 |
+
|
654 |
+
|
655 |
+
fputcsv($fp, $fields, $delimiter, $enclosure);
|
656 |
+
}
|
657 |
+
|
658 |
+
$stock_collection = Mage::getResourceModel('cataloginventory/stock_item_collection');
|
659 |
+
|
660 |
+
if($csv_data = @file_get_contents($this->getTempFilePath())){
|
661 |
+
|
662 |
+
fwrite($fp, $csv_data);
|
663 |
+
|
664 |
+
}
|
665 |
+
|
666 |
+
if (file_exists($this->getTempFilePath()))
|
667 |
+
{
|
668 |
+
unlink($this->getTempFilePath());
|
669 |
+
}
|
670 |
+
fclose($fp);
|
671 |
+
}
|
672 |
+
|
673 |
+
$this->setData('generated_at', date('Y-m-j H:i:s', time()));
|
674 |
+
$this->save();
|
675 |
+
|
676 |
+
}
|
677 |
+
|
678 |
+
|
679 |
+
public function getUrl(){
|
680 |
+
|
681 |
+
$file_path = sprintf('productsfeed/%s', $this->getFilename());
|
682 |
+
|
683 |
+
if(file_exists(Mage::getBaseDir('media').'/'.$file_path)){
|
684 |
+
|
685 |
+
return Mage::getBaseUrl('media', false).$file_path;
|
686 |
+
|
687 |
+
}
|
688 |
+
|
689 |
+
return '';
|
690 |
+
}
|
691 |
+
|
692 |
+
public function delete(){
|
693 |
+
|
694 |
+
if($this->getFilename()){
|
695 |
+
|
696 |
+
$fileDir = sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
697 |
+
$filePath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $this->getFilename());
|
698 |
+
$logFilepath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-'.$this->getId().'.txt');
|
699 |
+
|
700 |
+
@unlink($filePath);
|
701 |
+
@unlink($logFilepath);
|
702 |
+
|
703 |
+
}
|
704 |
+
|
705 |
+
return parent::delete();
|
706 |
+
}
|
707 |
+
|
708 |
+
public function myfputcsv( $fp, $fields, $delimiter = ';', $enclosure = ' ' )
|
709 |
+
{
|
710 |
+
for( $i = 0; $i < sizeof( $fields ); $i++ )
|
711 |
+
{
|
712 |
+
$use_enclosure = false;
|
713 |
+
if ( strpos( $fields[$i], $delimiter ) !== false )
|
714 |
+
{
|
715 |
+
$use_enclosure = true;
|
716 |
+
}
|
717 |
+
if ( strpos( $fields[$i], $enclosure ) !== false )
|
718 |
+
{
|
719 |
+
$use_enclosure = true;
|
720 |
+
}
|
721 |
+
if ( strpos( $fields[$i], "\\" ) !== false )
|
722 |
+
{
|
723 |
+
$use_enclosure = true;
|
724 |
+
}
|
725 |
+
if ( strpos( $fields[$i], "\n" ) !== false )
|
726 |
+
{
|
727 |
+
$use_enclosure = true;
|
728 |
+
}
|
729 |
+
if ( strpos( $fields[$i], "\r" ) !== false )
|
730 |
+
{
|
731 |
+
$use_enclosure = true;
|
732 |
+
}
|
733 |
+
if ( strpos( $fields[$i], "\t" ) !== false )
|
734 |
+
{
|
735 |
+
$use_enclosure = true;
|
736 |
+
}
|
737 |
+
if ( strpos( $fields[$i], " " ) !== false )
|
738 |
+
{
|
739 |
+
$use_enclosure = true;
|
740 |
+
}
|
741 |
+
|
742 |
+
if ( $use_enclosure == true )
|
743 |
+
{
|
744 |
+
$fields[$i] = explode( "\$enclosure", $fields[$i] );
|
745 |
+
for( $j = 0; $j < sizeof( $fields[$i] ); $j++ )
|
746 |
+
{
|
747 |
+
$fields[$i][$j] = explode( $enclosure, $fields[$i][$j] );
|
748 |
+
$fields[$i][$j] = implode( "{$enclosure}", $fields[$i][$j] );
|
749 |
+
}
|
750 |
+
$fields[$i] = implode( "\$enclosure", $fields[$i] );
|
751 |
+
$fields[$i] = "{$fields[$i]}";
|
752 |
+
}
|
753 |
+
}
|
754 |
+
|
755 |
+
return fwrite( $fp, implode( $delimiter, $fields ) . "\n" );
|
756 |
+
}
|
757 |
+
|
758 |
+
public function generateFeed(){
|
759 |
+
|
760 |
+
//ini_set("memory_limit", "-1");
|
761 |
+
//ini_set("upload_max_filesize", "100M");
|
762 |
+
//ini_set("post_max_size", "100M");
|
763 |
+
//set_time_limit(intval(9999999));
|
764 |
+
//ini_set("max_execution_time", 9999999);
|
765 |
+
|
766 |
+
$fileDir = sprintf('%s/productsfeed', Mage::getBaseDir('media'));
|
767 |
+
$filePath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $this->getFilename());
|
768 |
+
$logFilepath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-'.$this->getId().'.txt');
|
769 |
+
$csv_data ='';
|
770 |
+
@unlink($filePath);
|
771 |
+
@unlink($logFilepath);
|
772 |
+
|
773 |
+
|
774 |
+
$filePath = sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), $this->getFilename());
|
775 |
+
|
776 |
+
if(!file_exists($fileDir)){
|
777 |
+
|
778 |
+
mkdir($fileDir);
|
779 |
+
|
780 |
+
chmod($fileDir, 0777);
|
781 |
+
|
782 |
+
}
|
783 |
+
|
784 |
+
if(is_dir($fileDir)){
|
785 |
+
|
786 |
+
switch($this->getDelimiter()):
|
787 |
+
case('comma'):default:
|
788 |
+
$delimiter = ",";
|
789 |
+
break;
|
790 |
+
case('tab'):
|
791 |
+
$delimiter = "\t";
|
792 |
+
break;
|
793 |
+
case('colon'):
|
794 |
+
$delimiter = ":";
|
795 |
+
break;
|
796 |
+
case('space'):
|
797 |
+
$delimiter = " ";
|
798 |
+
break;
|
799 |
+
case('vertical pipe'):
|
800 |
+
$delimiter = "|";
|
801 |
+
break;
|
802 |
+
case('semi-colon'):
|
803 |
+
$delimiter = ";";
|
804 |
+
break;
|
805 |
+
endswitch;
|
806 |
+
//$delimiter = $this->getDelimiter();
|
807 |
+
|
808 |
+
switch($this->getEnclosure()):
|
809 |
+
|
810 |
+
case(1): default:
|
811 |
+
|
812 |
+
$enclosure = "'";
|
813 |
+
|
814 |
+
break;
|
815 |
+
|
816 |
+
case(2):
|
817 |
+
|
818 |
+
$enclosure = '"';
|
819 |
+
|
820 |
+
break;
|
821 |
+
|
822 |
+
case(3):
|
823 |
+
|
824 |
+
$enclosure = ' ';
|
825 |
+
|
826 |
+
break;
|
827 |
+
|
828 |
+
endswitch;
|
829 |
+
|
830 |
+
$maping = json_decode($this->getContent());
|
831 |
+
$fp = fopen($filePath, 'w');
|
832 |
+
|
833 |
+
if ($this->getData('use_addition_header') == 1){
|
834 |
+
fwrite($fp, $this->getData('addition_header'));
|
835 |
+
}
|
836 |
+
|
837 |
+
if($this->getShowHeaders()){
|
838 |
+
|
839 |
+
$fields = array();
|
840 |
+
|
841 |
+
foreach($maping as $col){
|
842 |
+
|
843 |
+
$fields[] = $col->name;
|
844 |
+
|
845 |
+
}
|
846 |
+
fputcsv($fp, $fields, $delimiter, $enclosure);
|
847 |
+
}
|
848 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
849 |
+
for ($i=0; $i < 2000000 ; $i+=500) {
|
850 |
+
$current_time = time();
|
851 |
+
|
852 |
+
$write->query("UPDATE ranvii_feed SET vartimestamp='$current_time' WHERE id=1");
|
853 |
+
//continue;
|
854 |
+
$this->writeTempFile($i,500);
|
855 |
+
if( 0 == filesize($this->getTempFilePath($i))){
|
856 |
+
if (file_exists($this->getTempFilePath($i)))
|
857 |
+
{
|
858 |
+
unlink($this->getTempFilePath($i));
|
859 |
+
}
|
860 |
+
break;
|
861 |
+
}else{
|
862 |
+
|
863 |
+
$csv_data = @file_get_contents($this->getTempFilePath($i));
|
864 |
+
fwrite($fp, $csv_data); unset( $csv_data ); gc_collect_cycles();
|
865 |
+
if (file_exists($this->getTempFilePath($i)))
|
866 |
+
{
|
867 |
+
unlink($this->getTempFilePath($i));
|
868 |
+
}
|
869 |
+
}
|
870 |
+
}
|
871 |
+
//mail('___CHANGEME___','Done Feed','FEED Done - Memory Usage : '. round( ( memory_get_usage() / 1024 / 1024 ) , 2 ) . date('r') ."\n===============================================\n" );
|
872 |
+
|
873 |
+
|
874 |
+
//fwrite($fp, $csv_data);
|
875 |
+
/* if (file_exists($this->getTempFilePath()))
|
876 |
+
{
|
877 |
+
unlink($this->getTempFilePath());
|
878 |
+
}
|
879 |
+
fclose($fp);*/
|
880 |
+
}
|
881 |
+
$this->setData('restart_cron', 0);
|
882 |
+
$this->setData('generated_at', date('Y-m-j H:i:s', time()));
|
883 |
+
$this->save();
|
884 |
+
|
885 |
+
}
|
886 |
+
|
887 |
+
}
|
app/code/community/Ranvii/Feed/Model/Item/Block.php
ADDED
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Item_Block extends Varien_Object
|
4 |
+
{
|
5 |
+
protected $content = '';
|
6 |
+
protected $pattern = '/\\{\\{block\b(.*?)\\}\\}(.*)\\{\\{\\/block\\}\\}/is';
|
7 |
+
protected $var_pattern = '/\\{\\{var:(.+?)(\s.*?)?\\}\\}/s';
|
8 |
+
protected $increment_id = 0;
|
9 |
+
protected $children = array();
|
10 |
+
protected $feed;
|
11 |
+
|
12 |
+
public function getFeed(){
|
13 |
+
return $this->feed;
|
14 |
+
}
|
15 |
+
public function setFeed(Ranvii_Feed_Model_Item $feed){
|
16 |
+
$this->feed = $feed;
|
17 |
+
return $this;
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
public function __construct($vars){
|
22 |
+
|
23 |
+
extract($vars);
|
24 |
+
|
25 |
+
if($feed instanceof Ranvii_Feed_Model_Item){
|
26 |
+
|
27 |
+
$this->feed = $feed;
|
28 |
+
|
29 |
+
$this->setDate(Date('Y-m-d H:i'));
|
30 |
+
|
31 |
+
if(isset($content) && $content){
|
32 |
+
if(isset($is_xml) && $is_xml){
|
33 |
+
$this->content = (string)$content;
|
34 |
+
}else{
|
35 |
+
|
36 |
+
$content = str_replace('<', '|lquote|', $content);
|
37 |
+
$content = str_replace('>', '|rquote|', $content);
|
38 |
+
|
39 |
+
$content = preg_replace('/{{(block.*?)}}/is', '<$1>', $content);
|
40 |
+
$content = preg_replace('/{{(\\/block)}}/is', '<$1>', $content);
|
41 |
+
|
42 |
+
$this->content = $content;
|
43 |
+
|
44 |
+
}
|
45 |
+
$this->parse();
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
}else{
|
50 |
+
throw new Exception('Feed must be instane of "Ranvii_Feed_Model_Item"');
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
protected function _parseChildBlocks(){
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
protected function parse(){
|
63 |
+
|
64 |
+
$match_block = array();
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
$xml = new Varien_Simplexml_Config(sprintf('<xml><body>%s</body></xml>', $this->content));
|
69 |
+
|
70 |
+
$root = $xml->getNode()->descend('body');
|
71 |
+
|
72 |
+
$this->content = preg_replace('/<body\b.*?>(.*)<\\/body>/is', '$1', (string)$root->asXML());
|
73 |
+
|
74 |
+
|
75 |
+
foreach($root->children() as $nodeName=>$xml_block){
|
76 |
+
/*
|
77 |
+
while(preg_match($this->pattern, $this->content, $match_block)){
|
78 |
+
if(isset($match_block[2]) && ($content = trim($match_block[2]))){ /**/
|
79 |
+
|
80 |
+
$wrapper = trim($xml_block->asXML());
|
81 |
+
|
82 |
+
$content = trim(preg_replace('/<block\b.*?>(.*)<\\/block>/is', '\1', $wrapper));
|
83 |
+
|
84 |
+
/*
|
85 |
+
|
86 |
+
$attributes = array();
|
87 |
+
|
88 |
+
if(isset($match_block[1]) && $match_block[1]){
|
89 |
+
|
90 |
+
$_attributes = array();
|
91 |
+
|
92 |
+
preg_match_all('/(.*?)\="(.*?)"/', $match_block[1], $_attributes);
|
93 |
+
|
94 |
+
$attribute_count = count($_attributes[0]);
|
95 |
+
|
96 |
+
for($i=0;$i<$attribute_count;$i++){
|
97 |
+
|
98 |
+
if(isset($_attributes[1][$i]) && isset($_attributes[2][$i]) ){
|
99 |
+
|
100 |
+
$attributes[trim($_attributes[1][$i])] = trim($_attributes[2][$i]);
|
101 |
+
|
102 |
+
}
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
}
|
107 |
+
*/
|
108 |
+
$block = null;
|
109 |
+
|
110 |
+
if(($type = $xml_block->getAttribute('type')) && ($modelClassName = Mage::getConfig()->getModelClassName('ranvii_feed/item_block_'.strtolower($type)))){
|
111 |
+
|
112 |
+
try{
|
113 |
+
|
114 |
+
class_exists($modelClassName);
|
115 |
+
|
116 |
+
$block = new $modelClassName(array('content'=>$content, 'feed'=>$this->feed, 'is_xml'=>1));
|
117 |
+
|
118 |
+
if(false == ($block instanceof Ranvii_Feed_Model_Item_Block)){
|
119 |
+
|
120 |
+
$block = null;
|
121 |
+
|
122 |
+
}
|
123 |
+
|
124 |
+
}catch(Exception $e){
|
125 |
+
$block = null;
|
126 |
+
}
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
if(is_null($block)){
|
131 |
+
|
132 |
+
$block = Mage::getModel('ranvii_feed/item_block', array('content'=>$content, 'feed'=>$this->feed, 'is_xml'=>1));
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
$attrs = array();
|
137 |
+
|
138 |
+
foreach($xml_block->attributes() as $key=>$value){
|
139 |
+
$attrs[$key] = $value;
|
140 |
+
}
|
141 |
+
|
142 |
+
$block->addData($attrs);
|
143 |
+
|
144 |
+
|
145 |
+
/*
|
146 |
+
if(!empty($attributes)){
|
147 |
+
|
148 |
+
$block->addData($attributes);
|
149 |
+
|
150 |
+
}
|
151 |
+
*/
|
152 |
+
|
153 |
+
$this->children[$this->increment_id] = $block;
|
154 |
+
|
155 |
+
$this->content = str_replace($wrapper, sprintf('{{block:%d}}', $this->increment_id), $this->content);
|
156 |
+
|
157 |
+
$this->increment_id++;
|
158 |
+
|
159 |
+
/*}*/
|
160 |
+
|
161 |
+
}
|
162 |
+
}
|
163 |
+
public function getChildren(){
|
164 |
+
return $this->children;
|
165 |
+
}
|
166 |
+
public function getContent(){
|
167 |
+
return $this->content;
|
168 |
+
}
|
169 |
+
public function render(){
|
170 |
+
|
171 |
+
foreach($this->children as $id=>$block){
|
172 |
+
$this->content = str_replace(sprintf('{{block:%d}}', $id), $block->render(), $this->content);
|
173 |
+
}
|
174 |
+
|
175 |
+
$this->content = str_replace('|lquote|', '<', $this->content);
|
176 |
+
$this->content = str_replace('|rquote|', '>', $this->content);
|
177 |
+
|
178 |
+
|
179 |
+
return $this->setVars($this->content, null, (get_class($this) == 'Ranvii_Feed_Model_Item_Block'));
|
180 |
+
|
181 |
+
}
|
182 |
+
|
183 |
+
public function applyAttribute($attribute_name, $attribute_value, $value){
|
184 |
+
|
185 |
+
|
186 |
+
switch(trim($attribute_name)){
|
187 |
+
case 'format':
|
188 |
+
|
189 |
+
switch(trim($attribute_value)){
|
190 |
+
case 'float':
|
191 |
+
|
192 |
+
$value = number_format($value, 2, '.', '');
|
193 |
+
|
194 |
+
break;
|
195 |
+
|
196 |
+
case 'int':
|
197 |
+
|
198 |
+
$value = intval($value);
|
199 |
+
|
200 |
+
break;
|
201 |
+
|
202 |
+
case 'striptags':
|
203 |
+
|
204 |
+
$value = strip_tags($value);
|
205 |
+
$value = trim($value);
|
206 |
+
|
207 |
+
break;
|
208 |
+
|
209 |
+
case 'htmlspecialchars':
|
210 |
+
$encoding = mb_detect_encoding($value);
|
211 |
+
$value = mb_convert_encoding($value, "UTF-8", $encoding);
|
212 |
+
$value = htmlentities($value, null, "UTF-8");
|
213 |
+
break;
|
214 |
+
|
215 |
+
case 'htmlspecialchars_decode':
|
216 |
+
|
217 |
+
$value = htmlspecialchars_decode($value);
|
218 |
+
|
219 |
+
break;
|
220 |
+
|
221 |
+
case 'delete_space':
|
222 |
+
|
223 |
+
$value = str_replace(" ", "", $value);
|
224 |
+
|
225 |
+
break;
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
break;
|
230 |
+
|
231 |
+
case 'limit':
|
232 |
+
if(intval($attribute_value) && $value){
|
233 |
+
$value = substr($value, 0, intval($attribute_value));
|
234 |
+
}
|
235 |
+
break;
|
236 |
+
|
237 |
+
}
|
238 |
+
|
239 |
+
return $value;
|
240 |
+
|
241 |
+
}
|
242 |
+
|
243 |
+
public function getAllVars($content = null){
|
244 |
+
|
245 |
+
if(is_null($content)){
|
246 |
+
$content = $this->getContent();
|
247 |
+
}
|
248 |
+
|
249 |
+
$vars = array();
|
250 |
+
$match = array();
|
251 |
+
|
252 |
+
preg_match_all($this->var_pattern, $content, $match);
|
253 |
+
|
254 |
+
if($var_num = count($match[0])){
|
255 |
+
|
256 |
+
while($var_num--){
|
257 |
+
$vars[] = $match[1][$var_num];
|
258 |
+
}
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
return $vars;
|
263 |
+
|
264 |
+
}
|
265 |
+
|
266 |
+
public function setVars($content = null, $dataObject = null, $clearVars = false){
|
267 |
+
|
268 |
+
if(is_null($content)){
|
269 |
+
$content = $this->getContent();
|
270 |
+
}
|
271 |
+
if(is_null($dataObject)){
|
272 |
+
$dataObject = $this;
|
273 |
+
}
|
274 |
+
|
275 |
+
$match = array();
|
276 |
+
|
277 |
+
preg_match_all('/{{var:(.+?)(\s.*?)?}}/s', $content, $match);
|
278 |
+
|
279 |
+
|
280 |
+
if(!empty($match)){
|
281 |
+
|
282 |
+
if($var_num = count($match[0])){
|
283 |
+
|
284 |
+
while($var_num--){
|
285 |
+
|
286 |
+
$props = explode('.', $match[1][$var_num]);
|
287 |
+
reset($props);
|
288 |
+
|
289 |
+
$value = '';
|
290 |
+
|
291 |
+
if($props_count = count($props)){
|
292 |
+
|
293 |
+
try{
|
294 |
+
|
295 |
+
$value = $dataObject->getData($props[0]);
|
296 |
+
|
297 |
+
if($props_count > 1){
|
298 |
+
|
299 |
+
for($i = 1; $i < $props_count;$i++){
|
300 |
+
|
301 |
+
if($value instanceof Varien_Object){
|
302 |
+
|
303 |
+
$value = $value->getData($props[$i]);
|
304 |
+
|
305 |
+
}else{
|
306 |
+
|
307 |
+
break;
|
308 |
+
|
309 |
+
}
|
310 |
+
|
311 |
+
}
|
312 |
+
|
313 |
+
}
|
314 |
+
|
315 |
+
$attributes = array();
|
316 |
+
|
317 |
+
if($attributes_value = $match[2][$var_num]){
|
318 |
+
|
319 |
+
preg_match_all('/(.*?)\="(.*?)"/s', $attributes_value, $attributes);
|
320 |
+
|
321 |
+
foreach($attributes[1] as $i=>$attribute_name){
|
322 |
+
|
323 |
+
$value = $this->applyAttribute($attribute_name, $attributes[2][$i], $value);
|
324 |
+
|
325 |
+
}
|
326 |
+
|
327 |
+
}
|
328 |
+
|
329 |
+
}catch(Exception $e){
|
330 |
+
$value = '';
|
331 |
+
}
|
332 |
+
|
333 |
+
|
334 |
+
if($value !== null || $clearVars == true){
|
335 |
+
|
336 |
+
$content = str_replace($match[0][$var_num], strval($value), $content);
|
337 |
+
|
338 |
+
}
|
339 |
+
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
}
|
344 |
+
|
345 |
+
return $content;
|
346 |
+
}
|
347 |
+
|
348 |
+
}
|
349 |
+
|
350 |
+
|
app/code/community/Ranvii/Feed/Model/Item/Block/Category.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Item_Block_Category extends Ranvii_Feed_Model_Item_Block{
|
4 |
+
|
5 |
+
public function setVars($content = null, $dataObject=null, $remove_empty=false){
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
$categories = $this->getFeed()->getCategoriesCollection();
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
$contents = array();
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
foreach($categories as $category){
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
if($category->getLevel() > 1){
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
$contents[] = parent::setVars($content, $category);
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
return implode("\r\n", $contents);
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
}
|
app/code/community/Ranvii/Feed/Model/Item/Block/Product.php
ADDED
@@ -0,0 +1,1501 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Item_Block_Product extends Ranvii_Feed_Model_Item_Block{
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
public function writeTempFile($curr_page = 0, $length= 50, $filename = ''){
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
$products = $this->getFeed()->getProductsCollection('', $curr_page, $length);
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
$stock_collection = Mage::getResourceModel('cataloginventory/stock_item_collection');
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
$content = file_get_contents($this->getFeed()->getDirPath().'/feed-'.$this->getFeed()->getId().'-xml-product-block-template.tmp');
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
$fp = fopen($this->getFeed()->getTempFilePath(), 'a');
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
$log_fp = fopen(sprintf('%s/productsfeed/%s', Mage::getBaseDir('media'), 'log-'.$this->getFeed()->getId().'.txt'), 'a');
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
$log_content = date("F j, Y, g:i:s a").', page:'.$curr_page.', items selected:'.count($products)."\n";
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
fwrite($log_fp, $log_content);
|
38 |
+
|
39 |
+
fclose($log_fp);
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
$store = Mage::getModel('core/store')->load($this->getFeed()->getStoreId());
|
44 |
+
|
45 |
+
$root_category = Mage::getModel('catalog/category')->load($store->getRootCategoryId());
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
if (Mage::getStoreConfig('ranvii_feedpro/imagesettings/enable')){
|
50 |
+
|
51 |
+
$image_width = intval(Mage::getStoreConfig('ranvii_feedpro/imagesettings/width'));
|
52 |
+
|
53 |
+
$image_height = intval(Mage::getStoreConfig('ranvii_feedpro/imagesettings/height'));
|
54 |
+
|
55 |
+
}else{
|
56 |
+
|
57 |
+
$image_width = 0;
|
58 |
+
|
59 |
+
$image_height = 0;
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
foreach($products as $_product){
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
$category_path = array();
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
$category = null;
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
foreach($_product->getCategoryIds() as $id){
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
$_category = $this->getFeed()->getCategoriesCollection()->getItemById($id);
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
if(is_null($category) || ($category && $_category && $category->getLevel() < $_category->getLevel())){
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
$category = $_category;
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
if($category){
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
$category_path = array($category->getName());
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
$parent_id = $category->getParentId();
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
if($category->getLevel() > $root_category->getLevel()){
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
while($_category = $this->getFeed()->getCategoriesCollection()->getItemById($parent_id)){
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
if($_category->getLevel() <= $root_category->getLevel()){
|
122 |
+
|
123 |
+
break;
|
124 |
+
|
125 |
+
}
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
$category_path[] = $_category->getName();
|
130 |
+
|
131 |
+
$parent_id = $_category->getParentId();
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
}
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
$product = new Varien_Object();
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
if($category){
|
146 |
+
|
147 |
+
$product->setCategory($category->getName());
|
148 |
+
|
149 |
+
$product->setCategoryId($category->getEntityId());
|
150 |
+
|
151 |
+
$product->setCategorySubcategory(implode(' -> ', array_reverse($category_path)));
|
152 |
+
|
153 |
+
}else{
|
154 |
+
|
155 |
+
$product->setCategory('');
|
156 |
+
|
157 |
+
$product->setCategorySubcategory('');
|
158 |
+
|
159 |
+
}
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
$template_attributes = $this->getAllVars($content);
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
+
$custom_attributes = Mage::getResourceModel('ranvii_feed/custom_attribute_collection');
|
168 |
+
|
169 |
+
$custom_attributes->load();
|
170 |
+
|
171 |
+
|
172 |
+
|
173 |
+
foreach($template_attributes as $attribute_code){
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
+
$value = null;
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
switch($attribute_code):
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
case ('parent_sku'):
|
186 |
+
|
187 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
188 |
+
|
189 |
+
$value = $parent_product->getSku();
|
190 |
+
|
191 |
+
}else{
|
192 |
+
|
193 |
+
$value = '';
|
194 |
+
|
195 |
+
}
|
196 |
+
|
197 |
+
break;
|
198 |
+
|
199 |
+
|
200 |
+
|
201 |
+
case 'parent_base_image':
|
202 |
+
|
203 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
204 |
+
|
205 |
+
$_prod = Mage::getModel('catalog/product')->load($parent_product->getId());
|
206 |
+
|
207 |
+
}else{
|
208 |
+
|
209 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
210 |
+
|
211 |
+
}
|
212 |
+
|
213 |
+
try{
|
214 |
+
|
215 |
+
if ($image_width || $image_height){
|
216 |
+
|
217 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
218 |
+
|
219 |
+
}else{
|
220 |
+
|
221 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
222 |
+
|
223 |
+
}
|
224 |
+
|
225 |
+
}catch(Exception $e){
|
226 |
+
|
227 |
+
$image_url = '';
|
228 |
+
|
229 |
+
}
|
230 |
+
|
231 |
+
$value = $image_url;
|
232 |
+
|
233 |
+
break;
|
234 |
+
|
235 |
+
|
236 |
+
|
237 |
+
case ('price'):
|
238 |
+
|
239 |
+
|
240 |
+
|
241 |
+
if(in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)))
|
242 |
+
|
243 |
+
$value = $store->convertPrice($_product->getMinimalPrice(), false, false);
|
244 |
+
|
245 |
+
else
|
246 |
+
|
247 |
+
$value = $store->convertPrice($_product->getPrice(), false, false);
|
248 |
+
|
249 |
+
|
250 |
+
|
251 |
+
break;
|
252 |
+
|
253 |
+
|
254 |
+
|
255 |
+
case ('store_price'):
|
256 |
+
|
257 |
+
case ('final_price'):
|
258 |
+
|
259 |
+
|
260 |
+
|
261 |
+
$value = $store->convertPrice($_product->getFinalPrice(), false, false);
|
262 |
+
|
263 |
+
|
264 |
+
|
265 |
+
break;
|
266 |
+
|
267 |
+
|
268 |
+
|
269 |
+
case('image'):
|
270 |
+
|
271 |
+
case('gallery'):
|
272 |
+
|
273 |
+
case('media_gallery'):
|
274 |
+
|
275 |
+
|
276 |
+
|
277 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
278 |
+
|
279 |
+
try
|
280 |
+
|
281 |
+
{
|
282 |
+
|
283 |
+
if ($image_width || $image_height){
|
284 |
+
|
285 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
286 |
+
|
287 |
+
}else{
|
288 |
+
|
289 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
290 |
+
|
291 |
+
}
|
292 |
+
|
293 |
+
|
294 |
+
|
295 |
+
}catch(Exception $e)
|
296 |
+
|
297 |
+
{
|
298 |
+
|
299 |
+
$image_url = '';
|
300 |
+
|
301 |
+
}
|
302 |
+
|
303 |
+
$product->setData($attribute_code, $image_url);
|
304 |
+
|
305 |
+
|
306 |
+
|
307 |
+
break;
|
308 |
+
|
309 |
+
|
310 |
+
|
311 |
+
case('image_2'):
|
312 |
+
|
313 |
+
case('image_3'):
|
314 |
+
|
315 |
+
case('image_4'):
|
316 |
+
|
317 |
+
case('image_5'):
|
318 |
+
|
319 |
+
if (!$_product->hasData('media_gallery_images'))
|
320 |
+
|
321 |
+
{
|
322 |
+
|
323 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
324 |
+
|
325 |
+
$_product->setData('media_gallery_images', $_prod->getMediaGalleryImages());
|
326 |
+
|
327 |
+
}
|
328 |
+
|
329 |
+
$i = 0;
|
330 |
+
|
331 |
+
foreach ($_product->getMediaGalleryImages() as $_image)
|
332 |
+
|
333 |
+
{
|
334 |
+
|
335 |
+
$i++;
|
336 |
+
|
337 |
+
if (('image_' . $i) == $attribute_code){
|
338 |
+
|
339 |
+
if ($image_width || $image_height){
|
340 |
+
|
341 |
+
$product->setData($attribute_code, (string)Mage::helper('catalog/image')->init($_product, 'image', $_image->getFile())->resize($image_width, $image_height));
|
342 |
+
|
343 |
+
}else{
|
344 |
+
|
345 |
+
$product->setData($attribute_code, $_image['url']);
|
346 |
+
|
347 |
+
}
|
348 |
+
|
349 |
+
}
|
350 |
+
|
351 |
+
}
|
352 |
+
|
353 |
+
break;
|
354 |
+
|
355 |
+
|
356 |
+
|
357 |
+
|
358 |
+
|
359 |
+
case ('parent_url'):
|
360 |
+
|
361 |
+
|
362 |
+
|
363 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
364 |
+
|
365 |
+
|
366 |
+
|
367 |
+
$product->setParentUrl($parent_product->getProductUrl(false));
|
368 |
+
|
369 |
+
|
370 |
+
|
371 |
+
|
372 |
+
|
373 |
+
break;
|
374 |
+
|
375 |
+
}
|
376 |
+
|
377 |
+
|
378 |
+
|
379 |
+
$product->setParentUrl($_product->getProductUrl(false));
|
380 |
+
|
381 |
+
|
382 |
+
|
383 |
+
break;
|
384 |
+
|
385 |
+
|
386 |
+
|
387 |
+
case('url'):
|
388 |
+
|
389 |
+
$product->setUrl($_product->getProductUrl(false));
|
390 |
+
|
391 |
+
break;
|
392 |
+
|
393 |
+
|
394 |
+
|
395 |
+
default:
|
396 |
+
|
397 |
+
|
398 |
+
|
399 |
+
if(strpos($attribute_code, 'custom:') === 0){
|
400 |
+
|
401 |
+
|
402 |
+
|
403 |
+
$custom_code = trim(str_replace('custom:', '', $attribute_code));
|
404 |
+
|
405 |
+
|
406 |
+
|
407 |
+
if($custom_attribute = $custom_attributes->getItemByColumnValue('code', $custom_code)){
|
408 |
+
|
409 |
+
|
410 |
+
|
411 |
+
$options = Zend_Json::decode($custom_attribute->getData('data'));
|
412 |
+
|
413 |
+
|
414 |
+
|
415 |
+
foreach($options as $option){
|
416 |
+
|
417 |
+
|
418 |
+
|
419 |
+
foreach($option['condition'] as $condition){
|
420 |
+
|
421 |
+
|
422 |
+
|
423 |
+
switch($condition['attribute_code']):
|
424 |
+
|
425 |
+
|
426 |
+
|
427 |
+
case ('product_type'):
|
428 |
+
|
429 |
+
$attr_value = $_product->getTypeId();
|
430 |
+
|
431 |
+
break;
|
432 |
+
|
433 |
+
|
434 |
+
|
435 |
+
case ('price'):
|
436 |
+
|
437 |
+
|
438 |
+
|
439 |
+
if(in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)))
|
440 |
+
|
441 |
+
$attr_value = $store->convertPrice($_product->getMinimalPrice(), false, false);
|
442 |
+
|
443 |
+
else
|
444 |
+
|
445 |
+
$attr_value = $store->convertPrice($_product->getPrice(), false, false);
|
446 |
+
|
447 |
+
|
448 |
+
|
449 |
+
break;
|
450 |
+
|
451 |
+
|
452 |
+
|
453 |
+
case ('store_price'):
|
454 |
+
|
455 |
+
|
456 |
+
|
457 |
+
$attr_value = $store->convertPrice($_product->getFinalPrice(), false, false);
|
458 |
+
|
459 |
+
|
460 |
+
|
461 |
+
break;
|
462 |
+
|
463 |
+
|
464 |
+
|
465 |
+
|
466 |
+
|
467 |
+
case ('parent_url'):
|
468 |
+
|
469 |
+
|
470 |
+
|
471 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
472 |
+
|
473 |
+
|
474 |
+
|
475 |
+
$attr_value = $parent_product->getProductUrl(false);
|
476 |
+
|
477 |
+
|
478 |
+
|
479 |
+
break;
|
480 |
+
|
481 |
+
|
482 |
+
|
483 |
+
}
|
484 |
+
|
485 |
+
|
486 |
+
|
487 |
+
$attr_value = $_product->getProductUrl(false);
|
488 |
+
|
489 |
+
|
490 |
+
|
491 |
+
break;
|
492 |
+
|
493 |
+
|
494 |
+
|
495 |
+
case('image'):
|
496 |
+
|
497 |
+
case('gallery'):
|
498 |
+
|
499 |
+
case('media_gallery'):
|
500 |
+
|
501 |
+
|
502 |
+
|
503 |
+
if (!$_product->hasData('product_base_image'))
|
504 |
+
|
505 |
+
{
|
506 |
+
|
507 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
508 |
+
|
509 |
+
|
510 |
+
|
511 |
+
try{
|
512 |
+
|
513 |
+
if ($image_width || $image_height){
|
514 |
+
|
515 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
516 |
+
|
517 |
+
}else{
|
518 |
+
|
519 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
520 |
+
|
521 |
+
}
|
522 |
+
|
523 |
+
|
524 |
+
|
525 |
+
}catch(Exception $e){
|
526 |
+
|
527 |
+
$image_url = '';
|
528 |
+
|
529 |
+
}
|
530 |
+
|
531 |
+
$_product->setData('product_base_image', $image_url);
|
532 |
+
|
533 |
+
$attr_value = $image_url;
|
534 |
+
|
535 |
+
|
536 |
+
|
537 |
+
}
|
538 |
+
|
539 |
+
else
|
540 |
+
|
541 |
+
{
|
542 |
+
|
543 |
+
$attr_value = $_product->getData('product_base_image');
|
544 |
+
|
545 |
+
}
|
546 |
+
|
547 |
+
|
548 |
+
|
549 |
+
break;
|
550 |
+
|
551 |
+
case('url'):
|
552 |
+
|
553 |
+
$attr_value = $_product->getProductUrl(false);
|
554 |
+
|
555 |
+
break;
|
556 |
+
|
557 |
+
case('qty'):
|
558 |
+
|
559 |
+
|
560 |
+
|
561 |
+
if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){
|
562 |
+
|
563 |
+
|
564 |
+
|
565 |
+
$attr_value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty());
|
566 |
+
|
567 |
+
|
568 |
+
|
569 |
+
}else{
|
570 |
+
|
571 |
+
|
572 |
+
|
573 |
+
$attr_value = 0;
|
574 |
+
|
575 |
+
|
576 |
+
|
577 |
+
}
|
578 |
+
|
579 |
+
break;
|
580 |
+
|
581 |
+
case('is_in_stock'):
|
582 |
+
|
583 |
+
if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){
|
584 |
+
|
585 |
+
|
586 |
+
|
587 |
+
$attr_value = $stock_collection->getItemByColumnValue('product_id', $_product->getId())->getData('is_in_stock');
|
588 |
+
|
589 |
+
|
590 |
+
|
591 |
+
}else{
|
592 |
+
|
593 |
+
|
594 |
+
|
595 |
+
$attr_value = 0;
|
596 |
+
|
597 |
+
|
598 |
+
|
599 |
+
}
|
600 |
+
|
601 |
+
break;
|
602 |
+
|
603 |
+
case('category'):
|
604 |
+
|
605 |
+
$attr_value = $product->getCategory();
|
606 |
+
|
607 |
+
break;
|
608 |
+
|
609 |
+
case('category_id'):
|
610 |
+
|
611 |
+
$attr_value = $_product->getCategoryIds();
|
612 |
+
|
613 |
+
break;
|
614 |
+
|
615 |
+
default:
|
616 |
+
|
617 |
+
$attr_value = $_product->getData($condition['attribute_code']);
|
618 |
+
|
619 |
+
endswitch;
|
620 |
+
|
621 |
+
|
622 |
+
|
623 |
+
$cond_value = $condition['value'];
|
624 |
+
|
625 |
+
|
626 |
+
|
627 |
+
$is_multi = false;
|
628 |
+
|
629 |
+
|
630 |
+
|
631 |
+
if($product_attribute = $_product->getResource()->getAttribute($condition['attribute_code'])){
|
632 |
+
|
633 |
+
|
634 |
+
|
635 |
+
if($product_attribute->getFrontendInput() == 'multiselect'){
|
636 |
+
|
637 |
+
|
638 |
+
|
639 |
+
$is_multi = true;
|
640 |
+
|
641 |
+
$attr_value = explode(',', $attr_value);
|
642 |
+
|
643 |
+
|
644 |
+
|
645 |
+
}
|
646 |
+
|
647 |
+
|
648 |
+
|
649 |
+
}
|
650 |
+
|
651 |
+
|
652 |
+
|
653 |
+
if ($condition['attribute_code'] == 'category_id')
|
654 |
+
|
655 |
+
{
|
656 |
+
|
657 |
+
$is_multi = true;
|
658 |
+
|
659 |
+
}
|
660 |
+
|
661 |
+
|
662 |
+
|
663 |
+
switch($condition['condition']):
|
664 |
+
|
665 |
+
|
666 |
+
|
667 |
+
case('eq'):
|
668 |
+
|
669 |
+
|
670 |
+
|
671 |
+
if(!$is_multi && $attr_value == $cond_value || $is_multi && in_array($cond_value, $attr_value)){
|
672 |
+
|
673 |
+
|
674 |
+
|
675 |
+
continue 2;
|
676 |
+
|
677 |
+
|
678 |
+
|
679 |
+
}else{
|
680 |
+
|
681 |
+
|
682 |
+
|
683 |
+
continue 3;
|
684 |
+
|
685 |
+
|
686 |
+
|
687 |
+
}
|
688 |
+
|
689 |
+
|
690 |
+
|
691 |
+
break;
|
692 |
+
|
693 |
+
|
694 |
+
|
695 |
+
case('neq'):
|
696 |
+
|
697 |
+
|
698 |
+
|
699 |
+
if(!$is_multi && $attr_value != $cond_value || $is_multi && !in_array($cond_value, $attr_value)){
|
700 |
+
|
701 |
+
|
702 |
+
|
703 |
+
continue 2;
|
704 |
+
|
705 |
+
|
706 |
+
|
707 |
+
}else{
|
708 |
+
|
709 |
+
|
710 |
+
|
711 |
+
continue 3;
|
712 |
+
|
713 |
+
|
714 |
+
|
715 |
+
}
|
716 |
+
|
717 |
+
|
718 |
+
|
719 |
+
break;
|
720 |
+
|
721 |
+
|
722 |
+
|
723 |
+
case('gt'):
|
724 |
+
|
725 |
+
|
726 |
+
|
727 |
+
if($attr_value > $cond_value){
|
728 |
+
|
729 |
+
|
730 |
+
|
731 |
+
continue 2;
|
732 |
+
|
733 |
+
|
734 |
+
|
735 |
+
}else{
|
736 |
+
|
737 |
+
|
738 |
+
|
739 |
+
continue 3;
|
740 |
+
|
741 |
+
|
742 |
+
|
743 |
+
}
|
744 |
+
|
745 |
+
|
746 |
+
|
747 |
+
break;
|
748 |
+
|
749 |
+
|
750 |
+
|
751 |
+
case('lt'):
|
752 |
+
|
753 |
+
|
754 |
+
|
755 |
+
if($attr_value < $cond_value){
|
756 |
+
|
757 |
+
|
758 |
+
|
759 |
+
continue 2;
|
760 |
+
|
761 |
+
|
762 |
+
|
763 |
+
}else{
|
764 |
+
|
765 |
+
|
766 |
+
|
767 |
+
continue 3;
|
768 |
+
|
769 |
+
|
770 |
+
|
771 |
+
}
|
772 |
+
|
773 |
+
|
774 |
+
|
775 |
+
break;
|
776 |
+
|
777 |
+
|
778 |
+
|
779 |
+
case('gteq'):
|
780 |
+
|
781 |
+
|
782 |
+
|
783 |
+
if($attr_value >= $cond_value){
|
784 |
+
|
785 |
+
|
786 |
+
|
787 |
+
continue 2;
|
788 |
+
|
789 |
+
|
790 |
+
|
791 |
+
}else{
|
792 |
+
|
793 |
+
|
794 |
+
|
795 |
+
continue 3;
|
796 |
+
|
797 |
+
|
798 |
+
|
799 |
+
}
|
800 |
+
|
801 |
+
|
802 |
+
|
803 |
+
break;
|
804 |
+
|
805 |
+
|
806 |
+
|
807 |
+
case('lteq'):
|
808 |
+
|
809 |
+
|
810 |
+
|
811 |
+
if($attr_value <= $cond_value){
|
812 |
+
|
813 |
+
|
814 |
+
|
815 |
+
continue 2;
|
816 |
+
|
817 |
+
|
818 |
+
|
819 |
+
}else{
|
820 |
+
|
821 |
+
|
822 |
+
|
823 |
+
continue 3;
|
824 |
+
|
825 |
+
|
826 |
+
|
827 |
+
}
|
828 |
+
|
829 |
+
|
830 |
+
|
831 |
+
break;
|
832 |
+
|
833 |
+
|
834 |
+
|
835 |
+
case('like'):
|
836 |
+
|
837 |
+
|
838 |
+
|
839 |
+
if(strpos($attr_value, $cond_value) !== false){
|
840 |
+
|
841 |
+
|
842 |
+
|
843 |
+
continue 2;
|
844 |
+
|
845 |
+
|
846 |
+
|
847 |
+
}else{
|
848 |
+
|
849 |
+
|
850 |
+
|
851 |
+
continue 3;
|
852 |
+
|
853 |
+
|
854 |
+
|
855 |
+
}
|
856 |
+
|
857 |
+
|
858 |
+
|
859 |
+
break;
|
860 |
+
|
861 |
+
|
862 |
+
|
863 |
+
case('nlike'):
|
864 |
+
|
865 |
+
|
866 |
+
|
867 |
+
if(strpos($attr_value, $cond_value) === false){
|
868 |
+
|
869 |
+
|
870 |
+
|
871 |
+
continue 2;
|
872 |
+
|
873 |
+
|
874 |
+
|
875 |
+
}else{
|
876 |
+
|
877 |
+
|
878 |
+
|
879 |
+
continue 3;
|
880 |
+
|
881 |
+
|
882 |
+
|
883 |
+
}
|
884 |
+
|
885 |
+
|
886 |
+
|
887 |
+
break;
|
888 |
+
|
889 |
+
|
890 |
+
|
891 |
+
endswitch;
|
892 |
+
|
893 |
+
|
894 |
+
|
895 |
+
|
896 |
+
|
897 |
+
}
|
898 |
+
|
899 |
+
|
900 |
+
|
901 |
+
if (in_array($option['value_type'], array('percent', 'attribute'))){
|
902 |
+
|
903 |
+
|
904 |
+
|
905 |
+
switch($option['value_type_attribute']):
|
906 |
+
|
907 |
+
|
908 |
+
|
909 |
+
case ('price'):
|
910 |
+
|
911 |
+
|
912 |
+
|
913 |
+
if(in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)))
|
914 |
+
|
915 |
+
$attribute_value = $store->convertPrice($_product->getMinimalPrice(), false, false);
|
916 |
+
|
917 |
+
else
|
918 |
+
|
919 |
+
$attribute_value = $store->convertPrice($_product->getPrice(), false, false);
|
920 |
+
|
921 |
+
|
922 |
+
|
923 |
+
break;
|
924 |
+
|
925 |
+
|
926 |
+
|
927 |
+
case ('store_price'):
|
928 |
+
|
929 |
+
|
930 |
+
|
931 |
+
$attribute_value = $store->convertPrice($_product->getFinalPrice(), false, false);
|
932 |
+
|
933 |
+
|
934 |
+
|
935 |
+
break;
|
936 |
+
|
937 |
+
|
938 |
+
|
939 |
+
|
940 |
+
|
941 |
+
case ('parent_url'):
|
942 |
+
|
943 |
+
|
944 |
+
|
945 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
946 |
+
|
947 |
+
|
948 |
+
|
949 |
+
$attribute_value = $parent_product->getProductUrl(false);
|
950 |
+
|
951 |
+
|
952 |
+
|
953 |
+
break;
|
954 |
+
|
955 |
+
|
956 |
+
|
957 |
+
}
|
958 |
+
|
959 |
+
|
960 |
+
|
961 |
+
$attribute_value = $_product->getProductUrl(false);
|
962 |
+
|
963 |
+
|
964 |
+
|
965 |
+
break;
|
966 |
+
|
967 |
+
|
968 |
+
|
969 |
+
case('image'):
|
970 |
+
|
971 |
+
case('gallery'):
|
972 |
+
|
973 |
+
case('media_gallery'):
|
974 |
+
|
975 |
+
|
976 |
+
|
977 |
+
if (!$_product->hasData('product_base_image'))
|
978 |
+
|
979 |
+
{
|
980 |
+
|
981 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
982 |
+
|
983 |
+
|
984 |
+
|
985 |
+
try{
|
986 |
+
|
987 |
+
if ($image_width || $image_height){
|
988 |
+
|
989 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
990 |
+
|
991 |
+
}else{
|
992 |
+
|
993 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
994 |
+
|
995 |
+
}
|
996 |
+
|
997 |
+
|
998 |
+
|
999 |
+
}catch(Exception $e){
|
1000 |
+
|
1001 |
+
$image_url = '';
|
1002 |
+
|
1003 |
+
}
|
1004 |
+
|
1005 |
+
$_product->setData('product_base_image', $image_url);
|
1006 |
+
|
1007 |
+
$attribute_value = $image_url;
|
1008 |
+
|
1009 |
+
|
1010 |
+
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
else
|
1014 |
+
|
1015 |
+
{
|
1016 |
+
|
1017 |
+
$attribute_value = $_product->getData('product_base_image');
|
1018 |
+
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
|
1022 |
+
|
1023 |
+
break;
|
1024 |
+
|
1025 |
+
case('url'):
|
1026 |
+
|
1027 |
+
$attribute_value = $_product->getProductUrl(false);
|
1028 |
+
|
1029 |
+
break;
|
1030 |
+
|
1031 |
+
case('qty'):
|
1032 |
+
|
1033 |
+
|
1034 |
+
|
1035 |
+
if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){
|
1036 |
+
|
1037 |
+
|
1038 |
+
|
1039 |
+
$attribute_value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty());
|
1040 |
+
|
1041 |
+
|
1042 |
+
|
1043 |
+
}else{
|
1044 |
+
|
1045 |
+
|
1046 |
+
|
1047 |
+
$attribute_value = 0;
|
1048 |
+
|
1049 |
+
|
1050 |
+
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
break;
|
1054 |
+
|
1055 |
+
case('category'):
|
1056 |
+
|
1057 |
+
$attribute_value = $product->getCategory();
|
1058 |
+
|
1059 |
+
break;
|
1060 |
+
|
1061 |
+
default:
|
1062 |
+
|
1063 |
+
$attribute_value = $_product->getData($option['value_type_attribute']);
|
1064 |
+
|
1065 |
+
endswitch;
|
1066 |
+
|
1067 |
+
|
1068 |
+
|
1069 |
+
}
|
1070 |
+
|
1071 |
+
|
1072 |
+
|
1073 |
+
if($option['value_type'] == 'percent'){
|
1074 |
+
|
1075 |
+
|
1076 |
+
|
1077 |
+
$value = floatval($attribute_value)/100*floatval($option['value']);
|
1078 |
+
|
1079 |
+
|
1080 |
+
|
1081 |
+
}elseif($option['value_type'] == 'attribute'){
|
1082 |
+
|
1083 |
+
|
1084 |
+
|
1085 |
+
$value = $attribute_value;
|
1086 |
+
|
1087 |
+
|
1088 |
+
|
1089 |
+
}else{
|
1090 |
+
|
1091 |
+
|
1092 |
+
|
1093 |
+
$value = $option['value'];
|
1094 |
+
|
1095 |
+
|
1096 |
+
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
|
1100 |
+
|
1101 |
+
break;
|
1102 |
+
|
1103 |
+
|
1104 |
+
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
|
1108 |
+
|
1109 |
+
if($value === null && $custom_attribute->getDefaultValue()){
|
1110 |
+
|
1111 |
+
|
1112 |
+
|
1113 |
+
switch($custom_attribute->getDefaultValue()):
|
1114 |
+
|
1115 |
+
|
1116 |
+
|
1117 |
+
case ('price'):
|
1118 |
+
|
1119 |
+
|
1120 |
+
|
1121 |
+
if(in_array($_product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, Mage_Catalog_Model_Product_Type::TYPE_BUNDLE)))
|
1122 |
+
|
1123 |
+
$value = $store->convertPrice($_product->getMinimalPrice(), false, false);
|
1124 |
+
|
1125 |
+
else
|
1126 |
+
|
1127 |
+
$value = $store->convertPrice($_product->getPrice(), false, false);
|
1128 |
+
|
1129 |
+
|
1130 |
+
|
1131 |
+
break;
|
1132 |
+
|
1133 |
+
|
1134 |
+
|
1135 |
+
case ('store_price'):
|
1136 |
+
|
1137 |
+
|
1138 |
+
|
1139 |
+
$value = $store->convertPrice($_product->getFinalPrice(), false, false);
|
1140 |
+
|
1141 |
+
|
1142 |
+
|
1143 |
+
break;
|
1144 |
+
|
1145 |
+
|
1146 |
+
|
1147 |
+
|
1148 |
+
|
1149 |
+
case ('parent_url'):
|
1150 |
+
|
1151 |
+
|
1152 |
+
|
1153 |
+
if(($parent_product = $this->getFeed()->getParentProduct($_product, $products)) && $parent_product->getEntityId() > 0){
|
1154 |
+
|
1155 |
+
|
1156 |
+
|
1157 |
+
$value = $parent_product->getProductUrl(false);
|
1158 |
+
|
1159 |
+
|
1160 |
+
|
1161 |
+
break;
|
1162 |
+
|
1163 |
+
|
1164 |
+
|
1165 |
+
}
|
1166 |
+
|
1167 |
+
|
1168 |
+
|
1169 |
+
$value = $_product->getProductUrl(false);
|
1170 |
+
|
1171 |
+
|
1172 |
+
|
1173 |
+
break;
|
1174 |
+
|
1175 |
+
|
1176 |
+
|
1177 |
+
case('image'):
|
1178 |
+
|
1179 |
+
case('gallery'):
|
1180 |
+
|
1181 |
+
case('media_gallery'):
|
1182 |
+
|
1183 |
+
|
1184 |
+
|
1185 |
+
if (!$_product->hasData('product_base_image'))
|
1186 |
+
|
1187 |
+
{
|
1188 |
+
|
1189 |
+
$_prod = Mage::getModel('catalog/product')->load($_product->getId());
|
1190 |
+
|
1191 |
+
|
1192 |
+
|
1193 |
+
try{
|
1194 |
+
|
1195 |
+
if ($image_width || $image_height){
|
1196 |
+
|
1197 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image')->resize($image_width, $image_height);
|
1198 |
+
|
1199 |
+
}else{
|
1200 |
+
|
1201 |
+
$image_url = (string)Mage::helper('catalog/image')->init($_prod, 'image');
|
1202 |
+
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
|
1206 |
+
|
1207 |
+
}catch(Exception $e){
|
1208 |
+
|
1209 |
+
$image_url = '';
|
1210 |
+
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
$_product->setData('product_base_image', $image_url);
|
1214 |
+
|
1215 |
+
$value = $image_url;
|
1216 |
+
|
1217 |
+
|
1218 |
+
|
1219 |
+
}
|
1220 |
+
|
1221 |
+
else
|
1222 |
+
|
1223 |
+
{
|
1224 |
+
|
1225 |
+
$value = $_product->getData('product_base_image');
|
1226 |
+
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
|
1230 |
+
|
1231 |
+
break;
|
1232 |
+
|
1233 |
+
case('url'):
|
1234 |
+
|
1235 |
+
$value = $_product->getProductUrl(false);
|
1236 |
+
|
1237 |
+
break;
|
1238 |
+
|
1239 |
+
case('qty'):
|
1240 |
+
|
1241 |
+
|
1242 |
+
|
1243 |
+
if($stock_item = $stock_collection->getItemByColumnValue('product_id', $_product->getId())){
|
1244 |
+
|
1245 |
+
|
1246 |
+
|
1247 |
+
$value = ceil($stock_collection->getItemByColumnValue('product_id', $_product->getId())->getQty());
|
1248 |
+
|
1249 |
+
|
1250 |
+
|
1251 |
+
}else{
|
1252 |
+
|
1253 |
+
|
1254 |
+
|
1255 |
+
$value = 0;
|
1256 |
+
|
1257 |
+
|
1258 |
+
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
break;
|
1262 |
+
|
1263 |
+
case('category'):
|
1264 |
+
|
1265 |
+
$value = $product->getCategory();
|
1266 |
+
|
1267 |
+
break;
|
1268 |
+
|
1269 |
+
default:
|
1270 |
+
|
1271 |
+
$value = $_product->getData($custom_attribute->getDefaultValue());
|
1272 |
+
|
1273 |
+
endswitch;
|
1274 |
+
|
1275 |
+
|
1276 |
+
|
1277 |
+
}
|
1278 |
+
|
1279 |
+
|
1280 |
+
|
1281 |
+
}
|
1282 |
+
|
1283 |
+
|
1284 |
+
|
1285 |
+
|
1286 |
+
|
1287 |
+
|
1288 |
+
|
1289 |
+
}elseif($attribute_model = $_product->getResource()->getAttribute($attribute_code)){
|
1290 |
+
|
1291 |
+
|
1292 |
+
|
1293 |
+
switch($attribute_model->getFrontendInput()):
|
1294 |
+
|
1295 |
+
|
1296 |
+
|
1297 |
+
case ('select'): case ('multiselect'):
|
1298 |
+
|
1299 |
+
|
1300 |
+
|
1301 |
+
$value = implode(', ', (array)$_product->getAttributeText($attribute_code));
|
1302 |
+
|
1303 |
+
|
1304 |
+
|
1305 |
+
break;
|
1306 |
+
|
1307 |
+
|
1308 |
+
|
1309 |
+
default:
|
1310 |
+
|
1311 |
+
|
1312 |
+
|
1313 |
+
$value = $_product->getData($attribute_code);
|
1314 |
+
|
1315 |
+
|
1316 |
+
|
1317 |
+
break;
|
1318 |
+
|
1319 |
+
|
1320 |
+
|
1321 |
+
endswitch;
|
1322 |
+
|
1323 |
+
|
1324 |
+
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
|
1328 |
+
|
1329 |
+
break;
|
1330 |
+
|
1331 |
+
|
1332 |
+
|
1333 |
+
endswitch;
|
1334 |
+
|
1335 |
+
|
1336 |
+
|
1337 |
+
if($value && !$product->getData($attribute_code)){
|
1338 |
+
|
1339 |
+
$product->setData($attribute_code, $value);
|
1340 |
+
|
1341 |
+
}
|
1342 |
+
|
1343 |
+
|
1344 |
+
|
1345 |
+
}
|
1346 |
+
|
1347 |
+
|
1348 |
+
|
1349 |
+
$product->setDescription(strip_tags(preg_replace('/<br.*?>/s', "\r\n", $_product->getDescription())));
|
1350 |
+
|
1351 |
+
$product->setShortDescription(strip_tags(preg_replace('/<br.*?>/s', "\r\n", $_product->getShortDescription())));
|
1352 |
+
|
1353 |
+
|
1354 |
+
|
1355 |
+
$product->setQty(ceil(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()));
|
1356 |
+
|
1357 |
+
|
1358 |
+
|
1359 |
+
fwrite($fp, parent::setVars($content, $product)."\r\n");
|
1360 |
+
|
1361 |
+
|
1362 |
+
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
|
1366 |
+
|
1367 |
+
|
1368 |
+
|
1369 |
+
fclose($fp);
|
1370 |
+
|
1371 |
+
|
1372 |
+
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
|
1376 |
+
|
1377 |
+
public function setVars($content = null, $dataObject=null, $remove_empty=false){
|
1378 |
+
|
1379 |
+
|
1380 |
+
|
1381 |
+
$template_temp_file = $this->getFeed()->getDirPath().'/feed-'.$this->getFeed()->getId().'-xml-product-block-template.tmp';
|
1382 |
+
|
1383 |
+
|
1384 |
+
|
1385 |
+
file_put_contents($template_temp_file, $content);
|
1386 |
+
|
1387 |
+
|
1388 |
+
|
1389 |
+
$collection = $this->getFeed()->getProductsCollection();
|
1390 |
+
|
1391 |
+
$total_products = $collection->getSize();
|
1392 |
+
|
1393 |
+
|
1394 |
+
|
1395 |
+
$per_page = intval($this->getFeed()->getIterationLimit());
|
1396 |
+
|
1397 |
+
|
1398 |
+
|
1399 |
+
if($per_page){
|
1400 |
+
|
1401 |
+
|
1402 |
+
|
1403 |
+
$pages = ceil($total_products/$per_page);
|
1404 |
+
|
1405 |
+
|
1406 |
+
|
1407 |
+
}else{
|
1408 |
+
|
1409 |
+
|
1410 |
+
|
1411 |
+
$pages = 1;
|
1412 |
+
|
1413 |
+
$per_page = 0;
|
1414 |
+
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
|
1418 |
+
|
1419 |
+
file_put_contents(sprintf('%s/productsfeed', Mage::getBaseDir('media')).'/log-'.$this->getFeed()->getId().'.txt', "started at:".date("F j, Y, g:i:s a").", pages:{$pages}, per_page:{$per_page} \n");
|
1420 |
+
|
1421 |
+
|
1422 |
+
|
1423 |
+
for($i = 0;$i<$pages;$i++){
|
1424 |
+
|
1425 |
+
|
1426 |
+
|
1427 |
+
if ($_fp = fopen(Mage::getSingleton('core/store')->load($this->getFeed()->getStoreId())->getUrl('feed/index/index', array('id'=>$this->getFeed()->getId(), 'start'=>$i, 'length'=>$per_page, '_nosid' => true)), 'r')){
|
1428 |
+
|
1429 |
+
|
1430 |
+
|
1431 |
+
$contents = '';
|
1432 |
+
|
1433 |
+
while (!feof($_fp)) {
|
1434 |
+
|
1435 |
+
$contents .= fread($_fp, 8192);
|
1436 |
+
|
1437 |
+
}
|
1438 |
+
|
1439 |
+
|
1440 |
+
|
1441 |
+
$response = Zend_Json::decode($contents);
|
1442 |
+
|
1443 |
+
|
1444 |
+
|
1445 |
+
if(!isset($response['result']) || !$response['result']){
|
1446 |
+
|
1447 |
+
|
1448 |
+
|
1449 |
+
throw new Mage_Core_Exception(Mage::helper('ranvii_feed')->__('There was an error while generating file. Change "Number of Products" in the Advanced Settings.
|
1450 |
+
|
1451 |
+
Try to change "Number of Products" in the Advanced Settings.
|
1452 |
+
|
1453 |
+
For example: set "Number of Products" equal 50 or 100.'));
|
1454 |
+
|
1455 |
+
|
1456 |
+
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
|
1460 |
+
|
1461 |
+
}else{
|
1462 |
+
|
1463 |
+
|
1464 |
+
|
1465 |
+
throw new Mage_Core_Exception(Mage::helper('ranvii_feed')->__('Cant open temp file'));
|
1466 |
+
|
1467 |
+
|
1468 |
+
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
|
1472 |
+
|
1473 |
+
|
1474 |
+
|
1475 |
+
fclose($_fp);
|
1476 |
+
|
1477 |
+
|
1478 |
+
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
|
1482 |
+
|
1483 |
+
$content = file_get_contents($this->getFeed()->getTempFilePath());
|
1484 |
+
|
1485 |
+
|
1486 |
+
|
1487 |
+
unlink($template_temp_file);
|
1488 |
+
|
1489 |
+
unlink($this->getFeed()->getTempFilePath());
|
1490 |
+
|
1491 |
+
|
1492 |
+
|
1493 |
+
return $content;
|
1494 |
+
|
1495 |
+
|
1496 |
+
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
|
1500 |
+
|
1501 |
+
}
|
app/code/community/Ranvii/Feed/Model/Mysql4/Custom/Attribute.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Mysql4_Custom_Attribute extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function _construct()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
$this->_init('ranvii_feed/custom_attribute', 'id');
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
}
|
app/code/community/Ranvii/Feed/Model/Mysql4/Custom/Attribute/Collection.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Mysql4_Custom_Attribute_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function _construct()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
parent::_construct();
|
12 |
+
|
13 |
+
$this->_init('ranvii_feed/custom_attribute');
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
}
|
app/code/community/Ranvii/Feed/Model/Mysql4/Item.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Mysql4_Item extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function _construct()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
$this->_init('ranvii_feed/item', 'id');
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
}
|
app/code/community/Ranvii/Feed/Model/Mysql4/Item/Collection.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
|
5 |
+
{
|
6 |
+
|
7 |
+
public function _construct()
|
8 |
+
|
9 |
+
{
|
10 |
+
|
11 |
+
parent::_construct();
|
12 |
+
|
13 |
+
$this->_init('ranvii_feed/item');
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
}
|
app/code/community/Ranvii/Feed/Model/Observer.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Observer{
|
4 |
+
|
5 |
+
public function proccessFeeds(){
|
6 |
+
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
|
7 |
+
$result = $write->query("SELECT vartimestamp FROM ranvii_feed WHERE id=1");
|
8 |
+
while ($row = $result->fetch() ) {
|
9 |
+
$prev_timestamp=$row['vartimestamp']+(60*4);
|
10 |
+
}
|
11 |
+
if ($prev_timestamp > time()) {
|
12 |
+
// Handle the exit
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
|
16 |
+
//mail('___CHANGEME___','Proceefeeds START','Proceefeeds calls '. date('r') ."\n===============================================\n");
|
17 |
+
$collection = Mage::getResourceModel('ranvii_feed/item_collection')->addFieldToFilter('restart_cron','1');
|
18 |
+
|
19 |
+
$collection->getSelect()->where('upload_day like "%'.strtolower(date('D')).'%"');
|
20 |
+
$prev_timestamp=0;
|
21 |
+
$cron_started_at=0;
|
22 |
+
foreach($collection as $feed){
|
23 |
+
|
24 |
+
try{
|
25 |
+
/*Mage::app()->setCurrentStore($feed->getStoreId());*/
|
26 |
+
/*
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
if (($prev_timestamp > time()) {
|
31 |
+
// Handle the exit
|
32 |
+
return;
|
33 |
+
} else {
|
34 |
+
$cron_started_at = date('Y-m-j H:i:s', time());
|
35 |
+
$feed->setData('cron_started_at', $cron_started_at);
|
36 |
+
|
37 |
+
$feed->save();
|
38 |
+
//mail('___CHANGEME___',"CRON FEED START $prev_timestamp",$cron_started_at . ' - '. date('r') ."\n===============================================\n");
|
39 |
+
|
40 |
+
$feed = Mage::getModel('ranvii_feed/item')->load($feed->getId());*/
|
41 |
+
$feed->generateFeed(); $feed->clearInstance(); unset($feed);
|
42 |
+
// }
|
43 |
+
}catch(Exception $e){
|
44 |
+
|
45 |
+
$feed->setData('restart_cron', intval($feed->getData('restart_cron')) + 1);
|
46 |
+
|
47 |
+
$feed->save();
|
48 |
+
continue;
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
//mail('___CHANGEME___','Proceefeeds DONE', date('r') ."\n===============================================\n". 'Proceefeeds DONE calls');
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
static function generateAll(){
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
$collection = Mage::getResourceModel('ranvii_feed/item_collection');
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
foreach($collection as $feed){
|
71 |
+
|
72 |
+
try{
|
73 |
+
|
74 |
+
Mage::app()->setCurrentStore($feed->getStoreId());
|
75 |
+
|
76 |
+
$feed->generate();
|
77 |
+
|
78 |
+
}catch(Exception $e){
|
79 |
+
|
80 |
+
continue;
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
}
|
app/code/community/Ranvii/Feed/Model/Product/Collection.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Model_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_feed_categories = array();
|
7 |
+
protected $_prepared_feed_categories = array(
|
8 |
+
'inclusion' => array(),
|
9 |
+
'exclusion' => array());
|
10 |
+
|
11 |
+
public function isEnabledFlat()
|
12 |
+
{
|
13 |
+
return false;
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function _productLimitationJoinPrice()
|
17 |
+
{
|
18 |
+
$filters = $this->_productLimitationFilters;
|
19 |
+
if (empty($filters['use_price_index'])) {
|
20 |
+
return $this;
|
21 |
+
}
|
22 |
+
|
23 |
+
$connection = $this->getConnection();
|
24 |
+
|
25 |
+
$joinCond = $joinCond = join(' AND ', array(
|
26 |
+
'price_index.entity_id = e.entity_id',
|
27 |
+
$connection->quoteInto('price_index.website_id = ?', $filters['website_id']),
|
28 |
+
$connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])
|
29 |
+
));
|
30 |
+
|
31 |
+
$fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM);
|
32 |
+
if (!isset($fromPart['price_index'])) {
|
33 |
+
$minimalExpr = new Zend_Db_Expr(
|
34 |
+
'IF(`price_index`.`tier_price`, LEAST(`price_index`.`min_price`, `price_index`.`tier_price`), `price_index`.`min_price`)'
|
35 |
+
);
|
36 |
+
$this->getSelect()->joinLeft(
|
37 |
+
array('price_index' => $this->getTable('catalog/product_index_price')),
|
38 |
+
$joinCond,
|
39 |
+
array('price', 'tax_class_id', 'final_price', 'minimal_price'=>$minimalExpr , 'min_price', 'max_price', 'tier_price')
|
40 |
+
);
|
41 |
+
|
42 |
+
// Set additional field filters
|
43 |
+
if (isset($this->_priceDataFieldFilters) && is_array($this->_priceDataFieldFilters))
|
44 |
+
{
|
45 |
+
foreach ($this->_priceDataFieldFilters as $filterData) {
|
46 |
+
$this->getSelect()->where(call_user_func_array('sprintf', $filterData));
|
47 |
+
}
|
48 |
+
}
|
49 |
+
} else {
|
50 |
+
$fromPart['price_index']['joinCondition'] = $joinCond;
|
51 |
+
$this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart);
|
52 |
+
}
|
53 |
+
|
54 |
+
return $this;
|
55 |
+
}
|
56 |
+
|
57 |
+
protected function _applyProductLimitations()
|
58 |
+
{
|
59 |
+
$this->_prepareProductLimitationFilters();
|
60 |
+
$this->_productLimitationJoinWebsite();
|
61 |
+
$this->_productLimitationJoinPrice();
|
62 |
+
$filters = $this->_productLimitationFilters;
|
63 |
+
|
64 |
+
if (!(isset($filters['category_id']) || count($this->_feed_categories)) && !isset($filters['visibility'])) {
|
65 |
+
return $this;
|
66 |
+
}
|
67 |
+
|
68 |
+
$conditions = array(
|
69 |
+
'cat_index.product_id=e.entity_id',
|
70 |
+
$this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id'])
|
71 |
+
);
|
72 |
+
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
|
73 |
+
$conditions[] = $this->getConnection()
|
74 |
+
->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
|
75 |
+
}
|
76 |
+
|
77 |
+
if (count($this->_feed_categories)){
|
78 |
+
$conditions[] = $this->getConnection()
|
79 |
+
->quoteInto('cat_index.category_id IN(?)', $this->_feed_categories);
|
80 |
+
$this->getSelect()->distinct();
|
81 |
+
}
|
82 |
+
else
|
83 |
+
$conditions[] = $this->getConnection()
|
84 |
+
->quoteInto('cat_index.category_id=?', $filters['category_id']);
|
85 |
+
|
86 |
+
|
87 |
+
if (isset($filters['category_is_anchor'])) {
|
88 |
+
$conditions[] = $this->getConnection()
|
89 |
+
->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
|
90 |
+
}
|
91 |
+
|
92 |
+
$joinCond = join(' AND ', $conditions);
|
93 |
+
$fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM);
|
94 |
+
if (isset($fromPart['cat_index'])) {
|
95 |
+
$fromPart['cat_index']['joinCondition'] = $joinCond;
|
96 |
+
$this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart);
|
97 |
+
}
|
98 |
+
else {
|
99 |
+
$this->getSelect()->join(
|
100 |
+
array('cat_index' => $this->getTable('catalog/category_product_index')),
|
101 |
+
$joinCond,
|
102 |
+
array('cat_index_position' => 0)
|
103 |
+
);
|
104 |
+
}
|
105 |
+
|
106 |
+
if (method_exists($this, '_productLimitationJoinStore'))
|
107 |
+
$this->_productLimitationJoinStore();
|
108 |
+
|
109 |
+
Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array(
|
110 |
+
'collection' => $this
|
111 |
+
));
|
112 |
+
|
113 |
+
return $this;
|
114 |
+
}
|
115 |
+
|
116 |
+
public function prepareFeedCategoryFilter($condition, $value){
|
117 |
+
|
118 |
+
$categories = Mage::getResourceModel('catalog/category_collection')
|
119 |
+
->addIsActiveFilter();
|
120 |
+
|
121 |
+
$exclusion = in_array($condition, array('neq', 'nlike', 'nin'));
|
122 |
+
if ($exclusion){
|
123 |
+
switch($condition){
|
124 |
+
case 'neq':
|
125 |
+
$condition = 'eq';
|
126 |
+
break;
|
127 |
+
case 'nlike':
|
128 |
+
$condition = 'like';
|
129 |
+
break;
|
130 |
+
case 'nin':
|
131 |
+
$condition = 'in';
|
132 |
+
break;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
if ($condition == 'like' || $condition == 'nlike'){
|
136 |
+
$category = Mage::getModel('catalog/category')->load($value);
|
137 |
+
$categories->addFieldToFilter('name', array($condition=>'%'.$category->getName().'%'));
|
138 |
+
}
|
139 |
+
else{
|
140 |
+
$categories->addFieldToFilter('entity_id', array($condition=>$value));
|
141 |
+
}
|
142 |
+
|
143 |
+
foreach ($categories as $_cat){
|
144 |
+
if ($exclusion){
|
145 |
+
$this->_prepared_feed_categories['exclusion'][] = intval($_cat->getId());
|
146 |
+
}else{
|
147 |
+
$this->_prepared_feed_categories['inclusion'][] = intval($_cat->getId());
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
return $this;
|
152 |
+
}
|
153 |
+
|
154 |
+
public function addFeedCategoryFilter(){
|
155 |
+
|
156 |
+
$categories = Mage::getResourceModel('catalog/category_collection')
|
157 |
+
->addIsActiveFilter();
|
158 |
+
|
159 |
+
$all_categories_ids = array();
|
160 |
+
|
161 |
+
foreach ($categories as $_cat){
|
162 |
+
$all_categories_ids[] = intval($_cat->getId());
|
163 |
+
}
|
164 |
+
|
165 |
+
if (count($this->_prepared_feed_categories['exclusion'])){
|
166 |
+
$all_categories_ids = array_diff($all_categories_ids, $this->_prepared_feed_categories['exclusion']);
|
167 |
+
}
|
168 |
+
if (count($this->_prepared_feed_categories['inclusion'])){
|
169 |
+
$all_categories_ids = array_intersect($all_categories_ids, $this->_prepared_feed_categories['inclusion']);
|
170 |
+
}
|
171 |
+
|
172 |
+
$this->_feed_categories = $all_categories_ids;
|
173 |
+
|
174 |
+
$this->_applyProductLimitations();
|
175 |
+
|
176 |
+
return $this;
|
177 |
+
}
|
178 |
+
|
179 |
+
|
180 |
+
}
|
app/code/community/Ranvii/Feed/controllers/Adminhtml/ItemsController.php
ADDED
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_Adminhtml_ItemsController extends Mage_Adminhtml_Controller_Action{
|
4 |
+
|
5 |
+
protected function _initAction() {
|
6 |
+
$this->loadLayout()
|
7 |
+
->_setActiveMenu('ranvii_feed')
|
8 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Feed Manager'), Mage::helper('adminhtml')->__('Feed Manager'));
|
9 |
+
|
10 |
+
return $this;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function indexAction() {
|
14 |
+
$this->_initAction();
|
15 |
+
$this->renderLayout();
|
16 |
+
|
17 |
+
}
|
18 |
+
|
19 |
+
/* public function writeTempData(){
|
20 |
+
if($feed_id = $this->getRequest()->getParam('id')){
|
21 |
+
|
22 |
+
$feed = Mage::getModel('ranvii_feed/item')->load($feed_id);
|
23 |
+
$start = intval($this->getRequest()->getParam('start'));
|
24 |
+
$length = intval($this->getRequest()->getParam('length'));
|
25 |
+
$feed->writeTempFile($start, $length);
|
26 |
+
}
|
27 |
+
|
28 |
+
}*/
|
29 |
+
|
30 |
+
public function saveAction(){
|
31 |
+
|
32 |
+
if ($data = $this->getRequest()->getPost()) {
|
33 |
+
|
34 |
+
try{
|
35 |
+
$id = $this->getRequest()->getParam('id');
|
36 |
+
|
37 |
+
$model = Mage::getModel('ranvii_feed/item');
|
38 |
+
|
39 |
+
|
40 |
+
if(isset($data['field'])){
|
41 |
+
$content_data = array();
|
42 |
+
$content_data_sorted = array();
|
43 |
+
|
44 |
+
foreach($data['field'] as $field){
|
45 |
+
if(intval($field['order']) && !isset($content_data_sorted[$field['order']])){
|
46 |
+
|
47 |
+
$content_data_sorted[intval($field['order'])] = $field;
|
48 |
+
|
49 |
+
}else{
|
50 |
+
|
51 |
+
$field['order'] = 0;
|
52 |
+
$content_data[] = $field;
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
ksort($content_data_sorted);
|
58 |
+
|
59 |
+
$data['content'] = json_encode(array_merge($content_data, $content_data_sorted));
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
/*if(isset($data['filter']) && is_array($data['filter'])){
|
64 |
+
|
65 |
+
$data['filter'] = json_encode(array_merge($data['filter'], array()));
|
66 |
+
|
67 |
+
}else{
|
68 |
+
$data['filter'] = json_encode(array());
|
69 |
+
}*/
|
70 |
+
|
71 |
+
if(isset($data['upload_day']) && is_array($data['upload_day'])){
|
72 |
+
|
73 |
+
$data['upload_day'] = implode(',',$data['upload_day']);
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
/* if (isset($data['upload_interval']) && in_array($data['upload_interval'], array(12,24))){
|
78 |
+
$data['upload_hour_to'] = null;
|
79 |
+
}
|
80 |
+
*/
|
81 |
+
$model->setData($data)->setId($id)->save();
|
82 |
+
|
83 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('core')->__('Data successfully saved'));
|
84 |
+
|
85 |
+
if ($this->getRequest()->getParam('back')) {
|
86 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
|
90 |
+
}catch(Mage_Core_Exception $e){
|
91 |
+
|
92 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
93 |
+
|
94 |
+
Mage::getSingleton('core/session')->setFeedData($data);
|
95 |
+
|
96 |
+
if($model->getId()>0){
|
97 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
98 |
+
}else{
|
99 |
+
$this->_redirect('*/*/new', array('type' => $model->getType()));
|
100 |
+
}
|
101 |
+
return false;
|
102 |
+
|
103 |
+
}catch(Exception $e){
|
104 |
+
|
105 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('Can’t save data'));
|
106 |
+
|
107 |
+
Mage::getSingleton('core/session')->setFeedData($data);
|
108 |
+
|
109 |
+
if($model->getId()>0){
|
110 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
111 |
+
}else{
|
112 |
+
$this->_redirect('*/*/new', array('type' => $model->getType()));
|
113 |
+
}
|
114 |
+
return false;
|
115 |
+
|
116 |
+
}
|
117 |
+
$this->_redirect('*/*/');
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
public function deleteAction(){
|
122 |
+
|
123 |
+
if($id = intval($this->getRequest()->getParam('id'))){
|
124 |
+
|
125 |
+
$this->_deleteItems(array($id));
|
126 |
+
|
127 |
+
}
|
128 |
+
$this->_redirect('*/*/');
|
129 |
+
}
|
130 |
+
|
131 |
+
public function massDeleteAction(){
|
132 |
+
|
133 |
+
if($ids = $this->getRequest()->getParam('id')){
|
134 |
+
if(is_array($ids) && !empty($ids)){
|
135 |
+
$this->_deleteItems($ids);
|
136 |
+
}
|
137 |
+
|
138 |
+
}
|
139 |
+
|
140 |
+
$this->_redirect('*/*/');
|
141 |
+
|
142 |
+
}
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
protected function _deleteItems($ids){
|
147 |
+
if(is_array($ids) && !empty($ids)){
|
148 |
+
foreach($ids as $id){
|
149 |
+
|
150 |
+
$item = Mage::getModel('ranvii_feed/item')->load($id);
|
151 |
+
$item->delete();
|
152 |
+
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
public function newAction(){
|
158 |
+
$this->_initAction();
|
159 |
+
|
160 |
+
if($data = Mage::getSingleton('core/session')->getFeedData()){
|
161 |
+
Mage::register('ranvii_feed', Mage::getModel('ranvii_feed/item')->addData($data));
|
162 |
+
Mage::getSingleton('core/session')->setFeedData(null);
|
163 |
+
}
|
164 |
+
|
165 |
+
$this->_addContent($this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit'))
|
166 |
+
->_addLeft($this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tabs'));
|
167 |
+
|
168 |
+
$this->renderLayout();
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
public function editAction(){
|
173 |
+
|
174 |
+
$this->_initAction();
|
175 |
+
|
176 |
+
if($id = $this->getRequest()->getParam('id')){
|
177 |
+
Mage::register('ranvii_feed', Mage::getModel('ranvii_feed/item')->load($id));
|
178 |
+
}
|
179 |
+
|
180 |
+
$this->_addContent($this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit'))
|
181 |
+
->_addLeft($this->getLayout()->createBlock('ranvii_feed/adminhtml_items_edit_tabs'));
|
182 |
+
|
183 |
+
$this->renderLayout();
|
184 |
+
|
185 |
+
}
|
186 |
+
|
187 |
+
public function uploadAction(){
|
188 |
+
|
189 |
+
if($id = $this->getRequest()->getParam('id')){
|
190 |
+
|
191 |
+
$item = Mage::getModel('ranvii_feed/item')->load($id);
|
192 |
+
|
193 |
+
try{
|
194 |
+
|
195 |
+
if($item->ftpUpload()){
|
196 |
+
|
197 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('core')->__('File "%s" was uploaded!', $item->getFilename()));
|
198 |
+
|
199 |
+
}
|
200 |
+
|
201 |
+
}catch(Mage_Core_Exception $e){
|
202 |
+
|
203 |
+
Mage::getSingleton('adminhtml/session')->addError($item->getFilename() . ' - ' . $e->getMessage());
|
204 |
+
|
205 |
+
}catch(Exception $e){
|
206 |
+
|
207 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('%s - Can\'t upload. Please, check your FTP Settings or Hosting Settings', $item->getFilename()));
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
return $this->_redirect('*/*/edit', array('id'=>$id));
|
212 |
+
|
213 |
+
}
|
214 |
+
|
215 |
+
$this->_redirect('*/*/index');
|
216 |
+
|
217 |
+
}
|
218 |
+
public function generateAction(){
|
219 |
+
|
220 |
+
if($id = $this->getRequest()->getParam('id')){
|
221 |
+
|
222 |
+
try{
|
223 |
+
|
224 |
+
$feed = Mage::getModel('ranvii_feed/item')->load($id);
|
225 |
+
Mage::app()->setCurrentStore($feed->getStoreId());
|
226 |
+
$feed->setRestartCron(1);
|
227 |
+
$feed->save();
|
228 |
+
// $feed->generateFeed();
|
229 |
+
|
230 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('core')->__('Your feed will be generated in a few minutes.'));
|
231 |
+
|
232 |
+
}catch(Mage_Core_Exception $e){
|
233 |
+
|
234 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
235 |
+
|
236 |
+
}catch(Exception $e){
|
237 |
+
|
238 |
+
if (!ini_get('allow_url_fopen'))
|
239 |
+
{
|
240 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('Check the "allow_url_fopen" option.
|
241 |
+
Check that the "allow_url_fopen" option it enabled.
|
242 |
+
This option enables the URL-aware fopen wrappers that enable accessing URL object like files.
|
243 |
+
Learn more at <a target="_blank" href="http://php.net/manual/en/filesystem.configuration.php">http://php.net/manual/en/filesystem.configuration.php</a>'));
|
244 |
+
}
|
245 |
+
elseif (strpos(strtolower($e->getMessage()), 'permission'))
|
246 |
+
{
|
247 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('Check the Permission for the "Media" directory.
|
248 |
+
Check that the "media" directory of your Magento has permission equal to 777 or 0777.'));
|
249 |
+
}
|
250 |
+
else
|
251 |
+
{
|
252 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('Can\'t generate feed file'));
|
253 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('If "Time out" error.
|
254 |
+
Please ask your server administrator to increase script run times. Learn more at <a target="_blank" href="http://php.net/manual/en/function.set-time-limit.php">http://php.net/manual/en/function.set-time-limit.php</a>'));
|
255 |
+
}
|
256 |
+
|
257 |
+
|
258 |
+
}
|
259 |
+
|
260 |
+
return $this->_redirect('*/*/edit', array('id'=>$id));
|
261 |
+
|
262 |
+
}
|
263 |
+
|
264 |
+
return $this->_redirect('*/*/index');
|
265 |
+
|
266 |
+
}
|
267 |
+
public function getattributevaluefieldAction(){
|
268 |
+
|
269 |
+
if($code = $this->getRequest()->getParam('attribute_code')){
|
270 |
+
|
271 |
+
$name = $this->getRequest()->getParam('element_name');
|
272 |
+
$store_id = $this->getRequest()->getParam('store_id');
|
273 |
+
$iterator = $this->getRequest()->getParam('iterator');
|
274 |
+
|
275 |
+
if ($code == 'product_type'){
|
276 |
+
$condition = Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Filter::getConditionSelectLight($iterator);
|
277 |
+
}else{
|
278 |
+
$condition = Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Filter::getConditionSelect($iterator);
|
279 |
+
}
|
280 |
+
|
281 |
+
$this->getResponse()->setBody(
|
282 |
+
Zend_Json::encode(
|
283 |
+
array(
|
284 |
+
'attributevalue' => Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Filter::getAttributeValueField($code, $name, null, $store_id),
|
285 |
+
'condition' => $condition,
|
286 |
+
'iterator' => $iterator
|
287 |
+
)
|
288 |
+
)
|
289 |
+
);
|
290 |
+
}
|
291 |
+
|
292 |
+
}
|
293 |
+
|
294 |
+
}
|
app/code/community/Ranvii/Feed/controllers/IndexController.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ranvii_Feed_IndexController extends Mage_Core_Controller_Front_Action{
|
4 |
+
|
5 |
+
public function indexAction(){
|
6 |
+
|
7 |
+
$response = array('result'=>0);
|
8 |
+
|
9 |
+
if($feed_id = $this->getRequest()->getParam('id')){
|
10 |
+
|
11 |
+
$feed = Mage::getModel('ranvii_feed/item')->load($feed_id);
|
12 |
+
$start = intval($this->getRequest()->getParam('start'));
|
13 |
+
$length = intval($this->getRequest()->getParam('length'));
|
14 |
+
|
15 |
+
|
16 |
+
if($start >= 0 && $length >= 0){
|
17 |
+
|
18 |
+
if($feed->getType() == 'csv'){
|
19 |
+
|
20 |
+
$feed->writeTempFile($start, $length);
|
21 |
+
|
22 |
+
}else{
|
23 |
+
|
24 |
+
Mage::getModel('ranvii_feed/item_block_product', array('feed'=>$feed, 'content'=>''))->writeTempFile($start, $length);
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
$response['result'] = 1;
|
29 |
+
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
$this->getResponse()->setBody(Zend_Json::encode($response));
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
app/code/community/Ranvii/Feed/etc/adminhtml.xml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<acl>
|
5 |
+
<resources>
|
6 |
+
<admin>
|
7 |
+
<children>
|
8 |
+
<system>
|
9 |
+
<children>
|
10 |
+
<config>
|
11 |
+
<children>
|
12 |
+
<ranvii_feedpro>
|
13 |
+
<title>Product Feed</title>
|
14 |
+
</ranvii_feedpro>
|
15 |
+
</children>
|
16 |
+
</config>
|
17 |
+
</children>
|
18 |
+
</system>
|
19 |
+
</children>
|
20 |
+
</admin>
|
21 |
+
</resources>
|
22 |
+
</acl>
|
23 |
+
</config>
|
app/code/community/Ranvii/Feed/etc/config.xml
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<modules>
|
5 |
+
<Ranvii_Feed>
|
6 |
+
<version>2.2.5</version>
|
7 |
+
</Ranvii_Feed>
|
8 |
+
</modules>
|
9 |
+
<frontend>
|
10 |
+
<routers>
|
11 |
+
<ranvii_feed>
|
12 |
+
<use>standard</use>
|
13 |
+
<args>
|
14 |
+
<module>Ranvii_Feed</module>
|
15 |
+
<frontName>feed</frontName>
|
16 |
+
</args>
|
17 |
+
</ranvii_feed>
|
18 |
+
</routers>
|
19 |
+
</frontend>
|
20 |
+
<admin>
|
21 |
+
<routers>
|
22 |
+
<ranvii_feed>
|
23 |
+
<use>admin</use>
|
24 |
+
<args>
|
25 |
+
<module>Ranvii_Feed</module>
|
26 |
+
<frontName>ranvii_feed</frontName>
|
27 |
+
</args>
|
28 |
+
</ranvii_feed>
|
29 |
+
</routers>
|
30 |
+
</admin>
|
31 |
+
<adminhtml>
|
32 |
+
<menu>
|
33 |
+
<ranvii_feed>
|
34 |
+
<title>Product Feeds</title>
|
35 |
+
<action>ranvii_feed/adminhtml_items</action>
|
36 |
+
<sort_order>10</sort_order>
|
37 |
+
</ranvii_feed>
|
38 |
+
</menu>
|
39 |
+
<acl>
|
40 |
+
<resources>
|
41 |
+
<admin>
|
42 |
+
<children>
|
43 |
+
<system>
|
44 |
+
<children>
|
45 |
+
<config>
|
46 |
+
<children>
|
47 |
+
<ranvii_feedpro>
|
48 |
+
<title>Product Feeds</title>
|
49 |
+
</ranvii_feedpro>
|
50 |
+
</children>
|
51 |
+
</config>
|
52 |
+
</children>
|
53 |
+
</system>
|
54 |
+
</children>
|
55 |
+
</admin>
|
56 |
+
</resources>
|
57 |
+
</acl>
|
58 |
+
|
59 |
+
<acl>
|
60 |
+
<resources>
|
61 |
+
<admin>
|
62 |
+
<children>
|
63 |
+
<catalog>
|
64 |
+
<children>
|
65 |
+
<ranvii_feed translate="title">
|
66 |
+
<title>Product Feeds</title>
|
67 |
+
</ranvii_feed>
|
68 |
+
</children>
|
69 |
+
</catalog>
|
70 |
+
</children>
|
71 |
+
</admin>
|
72 |
+
</resources>
|
73 |
+
</acl>
|
74 |
+
<layout>
|
75 |
+
<updates>
|
76 |
+
<ranvii_feed>
|
77 |
+
<file>ranvii-feed.xml</file>
|
78 |
+
</ranvii_feed>
|
79 |
+
</updates>
|
80 |
+
</layout>
|
81 |
+
</adminhtml>
|
82 |
+
<global>
|
83 |
+
<models>
|
84 |
+
<ranvii_feed>
|
85 |
+
<class>Ranvii_Feed_Model</class>
|
86 |
+
<resourceModel>ranvii_feed_mysql4</resourceModel>
|
87 |
+
</ranvii_feed>
|
88 |
+
<ranvii_feed_mysql4>
|
89 |
+
<class>Ranvii_Feed_Model_Mysql4</class>
|
90 |
+
<entities>
|
91 |
+
<item>
|
92 |
+
<table>ranvii_feed_entity</table>
|
93 |
+
</item>
|
94 |
+
</entities>
|
95 |
+
</ranvii_feed_mysql4>
|
96 |
+
</models>
|
97 |
+
<blocks>
|
98 |
+
<ranvii_feed>
|
99 |
+
<class>Ranvii_Feed_Block</class>
|
100 |
+
</ranvii_feed>
|
101 |
+
</blocks>
|
102 |
+
<resources>
|
103 |
+
<ranvii_feed_setup>
|
104 |
+
<setup>
|
105 |
+
<module>Ranvii_Feed</module>
|
106 |
+
</setup>
|
107 |
+
<connection>
|
108 |
+
<use>core_setup</use>
|
109 |
+
</connection>
|
110 |
+
</ranvii_feed_setup>
|
111 |
+
<ranvii_feed_write>
|
112 |
+
<connection>
|
113 |
+
<use>core_write</use>
|
114 |
+
</connection>
|
115 |
+
</ranvii_feed_write>
|
116 |
+
<ranvii_feed_read>
|
117 |
+
<connection>
|
118 |
+
<use>core_read</use>
|
119 |
+
</connection>
|
120 |
+
</ranvii_feed_read>
|
121 |
+
</resources>
|
122 |
+
<helpers>
|
123 |
+
<ranvii_feed><class>Ranvii_Feed_Helper</class></ranvii_feed>
|
124 |
+
</helpers>
|
125 |
+
</global>
|
126 |
+
<crontab>
|
127 |
+
<jobs>
|
128 |
+
<ranvii_feed_generate_all>
|
129 |
+
<schedule><cron_expr>* * * * *</cron_expr></schedule>
|
130 |
+
<run><model>ranvii_feed/observer::proccessFeeds</model></run>
|
131 |
+
</ranvii_feed_generate_all>
|
132 |
+
</jobs>
|
133 |
+
</crontab>
|
134 |
+
</config>
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.0.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
CREATE TABLE IF NOT EXISTS `{$this->getTable('ranvii_feed_entity')}` (
|
9 |
+
`id` smallint(6) NOT NULL auto_increment,
|
10 |
+
`name` varchar(255) NOT NULL,
|
11 |
+
`store_id` smallint(6) NOT NULL,
|
12 |
+
`type` smallint(1) NOT NULL,
|
13 |
+
`status` smallint(1) NOT NULL,
|
14 |
+
`filename` varchar(255) NOT NULL,
|
15 |
+
`content` text NOT NULL,
|
16 |
+
`filter` text,
|
17 |
+
`generated_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
18 |
+
PRIMARY KEY (`id`)
|
19 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Ranvi Catalog Feed' AUTO_INCREMENT=1;
|
20 |
+
");
|
21 |
+
|
22 |
+
$installer->endSetup();
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.3.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
CREATE TABLE `{$this->getTable('ranvii_feed_entity')}` (
|
9 |
+
`id` smallint(6) NOT NULL auto_increment,
|
10 |
+
`name` varchar(255) NOT NULL,
|
11 |
+
`store_id` smallint(6) NOT NULL,
|
12 |
+
`type` varchar(32) NOT NULL,
|
13 |
+
`status` smallint(1) NOT NULL,
|
14 |
+
`filename` varchar(255) NOT NULL,
|
15 |
+
`content` text NOT NULL,
|
16 |
+
`filter` text,
|
17 |
+
`generated_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
18 |
+
`show_headers` tinyint(1) default NULL,
|
19 |
+
`enclosure` varchar(32) default NULL,
|
20 |
+
`delimiter` varchar(32) default NULL,
|
21 |
+
`remove_lb` tinyint(1) DEFAULT '0',
|
22 |
+
PRIMARY KEY (`id`)
|
23 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Ranvi Catalog Feed' AUTO_INCREMENT=1;
|
24 |
+
");
|
25 |
+
|
26 |
+
$installer->endSetup();
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-1.4.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
CREATE TABLE `{$this->getTable('ranvii_feed_entity')}` (
|
9 |
+
`id` smallint(6) NOT NULL auto_increment,
|
10 |
+
`name` varchar(255) NOT NULL,
|
11 |
+
`store_id` smallint(6) NOT NULL,
|
12 |
+
`type` varchar(32) NOT NULL,
|
13 |
+
`status` smallint(1) NOT NULL,
|
14 |
+
`filename` varchar(255) NOT NULL,
|
15 |
+
`content` text NOT NULL,
|
16 |
+
`filter` text,
|
17 |
+
`generated_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
18 |
+
`cron_started_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
19 |
+
`uploaded_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
20 |
+
`show_headers` tinyint(1) default NULL,
|
21 |
+
`enclosure` varchar(32) default NULL,
|
22 |
+
`delimiter` varchar(32) default NULL,
|
23 |
+
`remove_lb` tinyint(1) DEFAULT '0',
|
24 |
+
`iteration_limit` int(32) default '0',
|
25 |
+
`use_layer` tinyint(1) NOT NULL default '1',
|
26 |
+
PRIMARY KEY (`id`)
|
27 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Ranvi Catalog Feed' AUTO_INCREMENT=1;
|
28 |
+
");
|
29 |
+
$installer->endSetup();
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-install-2.0.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
CREATE TABLE `{$this->getTable('ranvii_feed_entity')}` (
|
9 |
+
`id` smallint(6) NOT NULL auto_increment,
|
10 |
+
`name` varchar(255) NOT NULL,
|
11 |
+
`store_id` smallint(6) NOT NULL,
|
12 |
+
`type` varchar(32) NOT NULL,
|
13 |
+
`status` smallint(1) NOT NULL,
|
14 |
+
`filename` varchar(255) NOT NULL,
|
15 |
+
`content` text NOT NULL,
|
16 |
+
`filter` text,
|
17 |
+
`generated_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
18 |
+
`cron_started_at` datetime NOT NULL default '0000-00-00 00:00:00',
|
19 |
+
`show_headers` tinyint(1) default NULL,
|
20 |
+
`enclosure` varchar(32) default NULL,
|
21 |
+
`delimiter` varchar(32) default NULL,
|
22 |
+
`remove_lb` tinyint(1) DEFAULT '0',
|
23 |
+
`iteration_limit` int(32) default '0',
|
24 |
+
`upload_day` varchar(32) default NULL,
|
25 |
+
`upload_hour` smallint(6) default NULL,
|
26 |
+
`upload_hour_to` smallint(6) default NULL,
|
27 |
+
`upload_interval` smallint(6) default NULL,
|
28 |
+
`use_layer` tinyint(1) NOT NULL default '1',
|
29 |
+
`use_disabled` tinyint(1) NOT NULL default '1',
|
30 |
+
`restart_cron` smallint(6) default NULL,
|
31 |
+
PRIMARY KEY (`id`)
|
32 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Ranvi Catalog Feed' AUTO_INCREMENT=1;
|
33 |
+
");
|
34 |
+
$installer->endSetup();
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-upgrade-1.3-1.4.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
ALTER TABLE `{$this->getTable('ranvii_feed_entity')}`
|
9 |
+
ADD COLUMN `iteration_limit` int(32) default '0';
|
10 |
+
");
|
11 |
+
$installer->run("
|
12 |
+
ALTER TABLE `{$this->getTable('ranvii_feed_entity')}`
|
13 |
+
ADD COLUMN `use_layer` tinyint(1) NOT NULL default '1';
|
14 |
+
");
|
15 |
+
|
16 |
+
|
17 |
+
$installer->endSetup();
|
app/code/community/Ranvii/Feed/sql/ranvii_feed_setup/mysql4-upgrade-1.4-2.0.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
$installer->run("
|
8 |
+
ALTER TABLE `{$this->getTable('ranvii_feed_entity')}`
|
9 |
+
ADD COLUMN `use_disabled` tinyint(1) NOT NULL default '1';
|
10 |
+
");
|
11 |
+
|
12 |
+
|
13 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/ranvii-feed.xml
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<layout version="1.0">
|
4 |
+
<ranvii_feed_adminhtml_items_index>
|
5 |
+
<reference name="content">
|
6 |
+
<block type="ranvii_feed/adminhtml_items" name="ranvii_feed.admin.items" />
|
7 |
+
</reference>
|
8 |
+
</ranvii_feed_adminhtml_items_index>
|
9 |
+
<ranvii_feed_adminhtml_attributes_index>
|
10 |
+
<reference name="content">
|
11 |
+
<block type="ranvii_feed/adminhtml_attributes" name="ranvii_feed.admin.attributes" />
|
12 |
+
</reference>
|
13 |
+
</ranvii_feed_adminhtml_attributes_index>
|
14 |
+
<ranvii_feed_adminhtml_attributes_edit>
|
15 |
+
<reference name="head">
|
16 |
+
<action method="addItem"><type>skin_css</type><name>ranvii/feed.css</name><params>media="screen, projection"</params></action>
|
17 |
+
</reference>
|
18 |
+
</ranvii_feed_adminhtml_attributes_edit>
|
19 |
+
<ranvii_feed_adminhtml_attributes_new>
|
20 |
+
<reference name="head">
|
21 |
+
<action method="addItem"><type>skin_css</type><name>ranvii/feed.css</name><params>media="screen, projection"</params></action>
|
22 |
+
</reference>
|
23 |
+
</ranvii_feed_adminhtml_attributes_new>
|
24 |
+
<ranvii_feed_adminhtml_items_edit>
|
25 |
+
<reference name="head">
|
26 |
+
<action method="addJs"><script>ranvii/feed-admin.js</script></action>
|
27 |
+
<action method="addJs"><script>lib/flex.js</script></action>
|
28 |
+
<action method="addJs"><script>lib/FABridge.js</script></action>
|
29 |
+
<action method="addJs"><script>mage/adminhtml/flexuploader.js</script></action>
|
30 |
+
<action method="addJs"><script>mage/adminhtml/uploader.js</script></action>
|
31 |
+
</reference>
|
32 |
+
</ranvii_feed_adminhtml_items_edit>
|
33 |
+
<ranvii_feed_adminhtml_items_new>
|
34 |
+
<reference name="head">
|
35 |
+
<action method="addJs"><script>ranvii/feed-admin.js</script></action>
|
36 |
+
<action method="addJs"><script>lib/flex.js</script></action>
|
37 |
+
<action method="addJs"><script>lib/FABridge.js</script></action>
|
38 |
+
<action method="addJs"><script>mage/adminhtml/flexuploader.js</script></action>
|
39 |
+
<action method="addJs"><script>mage/adminhtml/uploader.js</script></action>
|
40 |
+
</reference>
|
41 |
+
</ranvii_feed_adminhtml_items_new>
|
42 |
+
</layout>
|
app/design/adminhtml/default/default/template/ranvii/feed/item/edit/content.phtml
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$feed = $this->getFeed();
|
4 |
+
|
5 |
+
$type=$this->getRequest()->getParam('type');
|
6 |
+
|
7 |
+
if($data = $this->getFeed()->getContent()){
|
8 |
+
|
9 |
+
$data = json_decode($data, true);
|
10 |
+
|
11 |
+
}else if($type == 'amazon'){
|
12 |
+
|
13 |
+
$data = Mage::helper('ranvii_feed')->getAmazonContentJson();
|
14 |
+
$data=json_decode($data, true);
|
15 |
+
|
16 |
+
}else if($type == 'google'){
|
17 |
+
|
18 |
+
$data = Mage::helper('ranvii_feed')->getGoogleContentJson();
|
19 |
+
$data=json_decode($data, true);
|
20 |
+
|
21 |
+
}else{
|
22 |
+
|
23 |
+
$data = array();
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
?>
|
28 |
+
<div class="entry-edit">
|
29 |
+
|
30 |
+
<div class="entry-edit-head">
|
31 |
+
<h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Fields Mapping')?></h4>
|
32 |
+
</div>
|
33 |
+
<div id="content_fieldset" class="fieldset ">
|
34 |
+
|
35 |
+
<div class="left">
|
36 |
+
<p style="clear:both;padding-bottom:5px;overflow:hidden;">
|
37 |
+
<input type='hidden' name='show_headers' value='1' />
|
38 |
+
|
39 |
+
<label style="float:left;margin-right:20px; "><span style="float:left;margin-right:10px;"><?php echo $this->__('Delimiter')?></span>
|
40 |
+
<select style="width:100px;" name="delimiter">
|
41 |
+
|
42 |
+
<option value="comma" <?php if(($feed->getDelimiter()) == 'comma' || !$feed->getDelimiter()):?> selected="selected" <?php endif;?>><?php echo $this->__('Comma');?></option>
|
43 |
+
<option value="tab" <?php if(($feed->getDelimiter()) == 'tab' ):?> selected="selected" <?php endif;?>><?php echo $this->__('Tab');?></option>
|
44 |
+
<option value="colon" <?php if(($feed->getDelimiter()) == 'colon' ):?> selected="selected" <?php endif;?>><?php echo $this->__('Colon');?></option>
|
45 |
+
<option value="space" <?php if(($feed->getDelimiter()) == 'space' ):?> selected="selected" <?php endif;?>><?php echo $this->__('Space');?></option>
|
46 |
+
<option value="vertical pipe" <?php if(($feed->getDelimiter()) == 'vertical pipe' || ($type == 'amazon' && !$feed->getDelimiter())):?> selected="selected" <?php endif;?>><?php echo $this->__('Vertical pipe');?></option>
|
47 |
+
<option value="semi-colon" <?php if(($feed->getDelimiter()) == 'semi-colon' ):?> selected="selected" <?php endif;?>><?php echo $this->__('Semi-colon');?></option>
|
48 |
+
|
49 |
+
</select>
|
50 |
+
</label>
|
51 |
+
|
52 |
+
<?php if($type == 'amazon' || $feed->getType() == 'amazon' ) { ?>
|
53 |
+
|
54 |
+
<input type='hidden' name='enclosure' value='3' />
|
55 |
+
|
56 |
+
<?php } else { ?>
|
57 |
+
|
58 |
+
<input type='hidden' name='enclosure' value='2' />
|
59 |
+
|
60 |
+
<?php } ?>
|
61 |
+
|
62 |
+
|
63 |
+
<!--
|
64 |
+
Enclosure are
|
65 |
+
value 2 is for Double quote (")
|
66 |
+
value 1 is for Double quote (')
|
67 |
+
value 3 is for Blank ()
|
68 |
+
-->
|
69 |
+
</p>
|
70 |
+
<!--
|
71 |
+
Remove line break symbols
|
72 |
+
You can use this option for shopzilla.com if your uploaded feed file doesn't work correctly.
|
73 |
+
|
74 |
+
<p style="clear:both">
|
75 |
+
<label><span style="float:left; width: 170px;"><?php echo $this->__('Remove line break symbols')?></span>
|
76 |
+
<select style="width:50px;" name="remove_lb">
|
77 |
+
<option value="1" <?php if(intval($feed->getRemoveLb()) == 1 ):?> selected="selected" <?php endif;?>><?php echo $this->__('Yes');?></option>
|
78 |
+
<option value="0" <?php if(intval($feed->getRemoveLb()) == 0 ):?> selected="selected" <?php endif;?>><?php echo $this->__('No');?></option>
|
79 |
+
</select>
|
80 |
+
</label><br/>
|
81 |
+
<small><?php echo $this->__('This is the specific option that allows to remove line break symbols from a data feed.')?></small>
|
82 |
+
</p>
|
83 |
+
-->
|
84 |
+
</div>
|
85 |
+
<div class="grid" style="clear:both">
|
86 |
+
<style>
|
87 |
+
.grid table td {vertical-align:middle;text-align: center;}
|
88 |
+
</style>
|
89 |
+
<table cellspacing="0" cellpadding="0" class="data" style="width:100%;">
|
90 |
+
<thead>
|
91 |
+
<tr class="headings">
|
92 |
+
<th width="20"><?php echo $this->__('Order')?></th>
|
93 |
+
<th style="width:160px;"><?php echo $this->__('Field Name')?></th>
|
94 |
+
<th width="40%"><?php echo $this->__('Value')?></th>
|
95 |
+
<th style="width:66px;text-align: center;"><?php echo $this->__('Action')?></th>
|
96 |
+
</tr>
|
97 |
+
</thead>
|
98 |
+
<tbody id="mapping-table-body">
|
99 |
+
<?php
|
100 |
+
if(empty($data)){
|
101 |
+
$rows_count = 5;
|
102 |
+
}else{
|
103 |
+
$rows_count = count($data);
|
104 |
+
}
|
105 |
+
echo $this->getLayout()->createBlock('adminhtml/template')
|
106 |
+
->setData('feed', $this->getFeed())
|
107 |
+
->setTemplate('ranvii/feed/item/edit/content/mapping.phtml')->toHtml();
|
108 |
+
?>
|
109 |
+
</tbody>
|
110 |
+
</table>
|
111 |
+
<div class="button-set">
|
112 |
+
<script type="text/javascript">
|
113 |
+
|
114 |
+
var mappingTotalRows = <?php echo $rows_count?>;
|
115 |
+
|
116 |
+
function removeMappingRow(e){
|
117 |
+
e.parentNode.parentNode.parentNode.removeChild(e.parentNode.parentNode);
|
118 |
+
}
|
119 |
+
|
120 |
+
function addColumn(tr, content){
|
121 |
+
|
122 |
+
td = document.createElement('td');
|
123 |
+
td.innerHTML = content;
|
124 |
+
tr.appendChild(td);
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
function addMappingRow(){
|
129 |
+
|
130 |
+
var i = ++mappingTotalRows;
|
131 |
+
var tr = document.createElement('tr');
|
132 |
+
|
133 |
+
var attribute = '<?php echo addslashes($this->getAttributeSelect("[iterator]"));?>';
|
134 |
+
|
135 |
+
addColumn(tr, '<div style="padding:0 2px;border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;border-style:solid;border-width:1px;"><input style="width:100%;border:0;padding:0;" class="input-text" name="field['+i+'][order]" value="" /></div>');
|
136 |
+
addColumn(tr, '<div style="padding:0 2px;border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;border-style:solid;border-width:1px;"><input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="field['+i+'][name]" value="" /></div>');
|
137 |
+
addColumn(tr, '<input style="width:98%; display:none;" id="mapping-'+i+'-static-value" type="text" class="input-text" name="field['+i+'][static_value]" value="" />'+attribute.replace(/\[iterator\]/g, i));
|
138 |
+
addColumn(tr, '<button onclick="removeMappingRow(this);return false;" class="button"><span><span><?php echo $this->__('Remove')?></span></span></button>');
|
139 |
+
|
140 |
+
$('mapping-table-body').appendChild(tr);
|
141 |
+
|
142 |
+
}
|
143 |
+
|
144 |
+
</script>
|
145 |
+
<p style="margin-top:10px;"><button onclick="addMappingRow();return false;" class="button"><span><span><?php echo $this->__('Add New Row')?></span></span></button></p>
|
146 |
+
</div>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
</div>
|
150 |
+
|
151 |
+
<?php if($feed->getId()>0):?>
|
152 |
+
<script type="text/javascript">
|
153 |
+
//<![CDATA[
|
154 |
+
|
155 |
+
var maxUploadFileSizeInBytes = <?php echo $this->getDataMaxSizeInBytes() ?>;
|
156 |
+
var maxUploadFileSize = '<?php echo $this->getDataMaxSize() ?>';
|
157 |
+
|
158 |
+
<?php echo $this->getJsObjectName() ?> = new Flex.Uploader('<?php echo $this->getHtmlId() ?>', '<?php echo $this->getUploaderUrl('media/uploader.swf') ?>', <?php echo $this->getConfigJson() ?>);
|
159 |
+
|
160 |
+
<?php echo $this->getJsObjectName() ?>.onFilesComplete = function(completedFiles){
|
161 |
+
completedFiles.each(function(file){
|
162 |
+
RanviFeedAdmin.submit(0, file.name);
|
163 |
+
<?php echo $this->getJsObjectName() ?>.removeFile(file.id);
|
164 |
+
});
|
165 |
+
$('<?php echo $this->getHtmlId() ?>-flash').setStyle({display:'none'});
|
166 |
+
}
|
167 |
+
|
168 |
+
if ($('<?php echo $this->getHtmlId() ?>-flash') != undefined) {
|
169 |
+
$('<?php echo $this->getHtmlId() ?>-flash').setStyle({display:'none'});
|
170 |
+
}
|
171 |
+
|
172 |
+
//]]>
|
173 |
+
</script>
|
174 |
+
<?php endif; ?>
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
|
186 |
+
|
187 |
+
|
app/design/adminhtml/default/default/template/ranvii/feed/item/edit/content/mapping.phtml
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$feed = $this->getFeed();
|
4 |
+
|
5 |
+
$type=$this->getRequest()->getParam('type');
|
6 |
+
|
7 |
+
if($data = $this->getFeed()->getContent()){
|
8 |
+
|
9 |
+
$data = json_decode($data, true);
|
10 |
+
|
11 |
+
}else if($type == 'amazon'){
|
12 |
+
|
13 |
+
$data = Mage::helper('ranvii_feed')->getAmazonContentJson();
|
14 |
+
$data =json_decode($data, true);
|
15 |
+
|
16 |
+
}else if($type == 'google'){
|
17 |
+
|
18 |
+
$data = Mage::helper('ranvii_feed')->getGoogleContentJson();
|
19 |
+
$data =json_decode($data, true);
|
20 |
+
|
21 |
+
}else{
|
22 |
+
|
23 |
+
$data = array();
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
if(empty($data)){
|
28 |
+
$rows_count = 5;
|
29 |
+
}else{
|
30 |
+
$rows_count = count($data);
|
31 |
+
}
|
32 |
+
|
33 |
+
?>
|
34 |
+
<?php for($i=0;$i<$rows_count;$i++):?>
|
35 |
+
<tr>
|
36 |
+
<td><div style="padding:0 2px;border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;border-style:solid;border-width:1px;"><input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="field[<?php echo $i;?>][order]" value="<?php echo @$data[$i]['order'];?>" /></div></td>
|
37 |
+
<td ><div style="padding:0 2px;border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;border-style:solid;border-width:1px;"><input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="field[<?php echo $i;?>][name]" value="<?php echo @$data[$i]['name'];?>" /></div></td>
|
38 |
+
<td>
|
39 |
+
<input style="width:98%;display:<?php echo isset($data[$i]['type']) && $data[$i]['type'] == 'static' ? 'block' : 'none';?>;" id="mapping-<?php echo $i;?>-static-value" type="text" class="input-text" name="field[<?php echo $i;?>][static_value]" value="<?php echo @$data[$i]['static_value'] ?>" />
|
40 |
+
<?php echo Ranvii_Feed_Block_Adminhtml_Items_Edit_Tab_Content_Csv::getAttributeSelect($i, @$data[$i]['attribute_value'], (isset($data[$i]['type']) && $data[$i]['type'] == 'attribute' || !isset($data[$i]['type'])))?>
|
41 |
+
</td>
|
42 |
+
<td><button onclick="removeMappingRow(this);return false;" class="button"><span><span><?php echo $this->__('Remove')?></span></span></button></td>
|
43 |
+
</tr>
|
44 |
+
<?php endfor;?>
|
app/design/adminhtml/default/default/template/ranvii/feed/item/import/form.phtml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$helper = Mage::helper('ranvii_feed');
|
4 |
+
|
5 |
+
?>
|
6 |
+
<div style="" id="ranvii_feed_tabs_import_section_content"><div class="entry-edit">
|
7 |
+
<div class="entry-edit-head">
|
8 |
+
<h4 class="icon-head head-edit-form fieldset-legend"><?php echo $helper->__('Import Mapping');?></h4>
|
9 |
+
<div class="form-buttons"></div>
|
10 |
+
</div>
|
11 |
+
<div id="main_fieldset" class="fieldset ">
|
12 |
+
<div class="hor-scroll">
|
13 |
+
<table cellspacing="0" class="form-list">
|
14 |
+
<tbody>
|
15 |
+
<tr>
|
16 |
+
<td class="label"><label for="mappingfile"><?php echo $helper->__('Mapping File');?><span class="required">*</span></label></td>
|
17 |
+
<td class="value" style="width:230px">
|
18 |
+
<input type="file" class=" required-entry" title="<?php echo $helper->__('Mapping File');?>" value="" name="mappingfile" id="mappingfile">
|
19 |
+
</td>
|
20 |
+
<td class="value"><span id="continue_button"><button style="" onclick="editForm.submit();return false;" class="scalable save" type="submit" id="id_944658684ee4dd3285bd2f1c924b3fc9"><span><?php echo $helper->__('Import');?></span></button></span></td>
|
21 |
+
</tr>
|
22 |
+
</tbody>
|
23 |
+
</table>
|
24 |
+
</div>
|
25 |
+
</div>
|
26 |
+
</div>
|
27 |
+
</div>
|
app/etc/modules/Ranvii_Feed.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<modules>
|
5 |
+
<Ranvii_Feed>
|
6 |
+
<active>true</active>
|
7 |
+
<codePool>community</codePool>
|
8 |
+
</Ranvii_Feed>
|
9 |
+
</modules>
|
10 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Ranvii_Feed</name>
|
4 |
+
<version>2.2.5</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Export Your Magento Store To Popular Feed Formats (csv, txt) for Google Shopping, and other CSEs</summary>
|
10 |
+
<description>Export Your Magento Store To Popular Feed Formats (csv, txt) for Google Shopping, and other CSEs</description>
|
11 |
+
<notes>Export Your Magento Store To Popular Feed Formats (csv, txt) for Google Shopping, and other CSEs</notes>
|
12 |
+
<authors><author><name>Ranvi</name><user>auto-converted</user><email>ravindra.palkonda@gmail.com</email></author></authors>
|
13 |
+
<date>2013-08-03</date>
|
14 |
+
<time>09:32:35</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Ranvii"><dir name="Feed"><dir name="Block"><dir name="Adminhtml"><dir name="Config"><dir name="Form"><dir name="Renderer"><file name="Website.php" hash="23688bbb9d653d8310a41f8742c7e324"/></dir></dir></dir><dir name="Items"><dir name="Edit"><dir name="Tab"><dir name="Content"><file name="Csv.php" hash="3428e1ab197f6f8104261e2bb31ad991"/></dir><file name="Advanced.php" hash="81ad09b1a0fa08a09db8c9da33be313b"/><file name="Main.php" hash="7f4c7ad074254526fb7ffa759e19c3c9"/><file name="Type.php" hash="87fa928e1e7fe4c20189cba17c6e6793"/></dir><file name="Form.php" hash="5207fb8d2982f5cf896c1467f5f1427e"/><file name="Tabs.php" hash="4a8d7f3d430934fe297d6359f8094fde"/></dir><dir name="Grid"><dir name="Renderer"><file name="AccessUrl.php" hash="a43e64e6a0c4071a87d4fae721f48e85"/><file name="Datetime.php" hash="6514ed7da7aaf54fff2bb8d248f77a4e"/></dir></dir><file name="Edit.php" hash="37ef974494f8c6375597dd426fd8bd22"/><file name="Grid.php" hash="84bfb068e187495ca545148de891e5c9"/></dir><file name="Items.php" hash="ba94a0d72450c0a837aeb491f9f7cb2d"/></dir></dir><dir name="Helper"><file name="Data.php" hash="64ef258595feb7fe1ec0048e5f56f799"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Store.php" hash="c30bffe54e62e886bf9d876e3b707940"/></dir></dir></dir></dir><dir name="Custom"><file name="Attribute.php" hash="23edde310743d2a093db8307da6e5845"/></dir><dir name="Item"><dir name="Block"><file name="Category.php" hash="42e996b9d7a4ed9da647ab056273c120"/><file name="Product.php" hash="ba216e1bc70cc7ef3a42895c24a52224"/></dir><file name="Block.php" hash="4f3df01a6a68e31171991432124e1222"/></dir><dir name="Mysql4"><dir name="Custom"><dir name="Attribute"><file name="Collection.php" hash="ce91d0191b073d0e04e2c5eb9f3294c0"/></dir><file name="Attribute.php" hash="973debd0290a6aff5ee6a564f466a50b"/></dir><dir name="Item"><file name="Collection.php" hash="c33842defd04c7699d4896f78b50cd7a"/></dir><file name="Item.php" hash="1b85ac77a916616f9fe9e0abd40e13e6"/></dir><dir name="Product"><file name="Collection.php" hash="7bc6ff9043d595ee83f912eed2198ce0"/></dir><file name="Item.php" hash="cbf630866c3711a9d1a0496a1c103d84"/><file name="Observer.php" hash="4b434477773399cc75f8383b786bf684"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ItemsController.php" hash="a983268293ec1410d03d9f333c29e301"/></dir><file name="IndexController.php" hash="250e529bb5521b2bdf3bab9ca9377cb9"/></dir><dir name="etc"><file name="adminhtml.xml" hash="33331e005d12dea27b04acb3b582ddf2"/><file name="config.xml" hash="776d9b74e89178d8f044b5da85a05108"/></dir><dir name="sql"><dir name="ranvii_feed_setup"><file name="mysql4-install-1.0.php" hash="df126f5c6dffb5cb19a6f34b3792045c"/><file name="mysql4-install-1.3.php" hash="7bdc8c07b8c93a893bd78a81f1771ce1"/><file name="mysql4-install-1.4.php" hash="666c423d6522e0ddfded14de306e75ac"/><file name="mysql4-install-2.0.php" hash="0f7b33a2552cd77be4b148d38140d727"/><file name="mysql4-upgrade-1.3-1.4.php" hash="72ce88e923886175387617119ae9f6b6"/><file name="mysql4-upgrade-1.4-2.0.php" hash="82a9d3e6f5929e224a45ef428180fd46"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ranvii_Feed.xml" hash="7d6d8f5f5706d13e167ac5813839ef67"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="ranvii"><dir name="feed"><dir name="item"><dir name="edit"><dir name="content"><file name="mapping.phtml" hash="f3f90f631cecfb7fdd8dcc56178db748"/></dir><file name="content.phtml" hash="39cda8185ffd70237d25a1b7519a0848"/></dir><dir name="import"><file name="form.phtml" hash="c41605115b3925a70369388b9f832225"/></dir></dir></dir></dir></dir><dir name="layout"><file name="ranvii-feed.xml" hash="299ed21a842abad1e7dad5d2ac59b14a"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="ranvii"><file name="feed.css" hash="e422627c523a3e101d71991defe4a3ae"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies/>
|
18 |
+
</package>
|
skin/adminhtml/default/default/ranvii/feed.css
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.grid .condition-grid,
|
2 |
+
.grid .condition-grid td{
|
3 |
+
border:0;
|
4 |
+
line-height:17px;
|
5 |
+
}
|
6 |
+
.grid .condition-grid td{
|
7 |
+
padding:1px 1px 1px 0 !important;
|
8 |
+
}
|
9 |
+
td.result-column,
|
10 |
+
td.type-column,
|
11 |
+
td.action-column{
|
12 |
+
padding-top:5px;
|
13 |
+
}
|
14 |
+
.condition-value-wraper{
|
15 |
+
width:140px;
|
16 |
+
/*padding:0 2px;
|
17 |
+
border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;
|
18 |
+
border-style:solid;
|
19 |
+
border-width:1px;*/
|
20 |
+
clear:both;
|
21 |
+
overflow:hidden;
|
22 |
+
zoom:1;
|
23 |
+
}
|
24 |
+
.condition-value-wraper input,
|
25 |
+
.condition-value-wraper select{
|
26 |
+
float:left;
|
27 |
+
}
|
28 |
+
.condition-value-wraper input,
|
29 |
+
.condition-value-wraper select{
|
30 |
+
padding:1px !important;
|
31 |
+
width:136px !important;
|
32 |
+
border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA !important;
|
33 |
+
border-style:solid !important;
|
34 |
+
border-width:1px !important;
|
35 |
+
}
|
36 |
+
.condition-value-wraper select{
|
37 |
+
padding:0 !important;
|
38 |
+
width:136px !important;
|
39 |
+
}
|
40 |
+
.condition-actions .delete span{
|
41 |
+
padding-left:15px;
|
42 |
+
}
|
43 |
+
.type-field-wrapper{
|
44 |
+
float:left;
|
45 |
+
}
|
46 |
+
.grid td.result-column input.input-text{
|
47 |
+
width:99%;
|
48 |
+
float:left;
|
49 |
+
height:16px;
|
50 |
+
padding:0;
|
51 |
+
}
|
52 |
+
.grid table td.feed-row-first{
|
53 |
+
width:466px;
|
54 |
+
}
|
55 |
+
.grid table td.type-column{
|
56 |
+
width:140px;
|
57 |
+
}
|
58 |
+
.grid table td.action-column{
|
59 |
+
width:191px;
|
60 |
+
}
|
61 |
+
.type-attribute-field-wrapper{
|
62 |
+
float:left;
|
63 |
+
margin:3px 0 0;
|
64 |
+
display:none;
|
65 |
+
}
|
66 |
+
.type-attribute-field-wrapper select,
|
67 |
+
.grid table td.type-column .type-field-wrapper select{
|
68 |
+
width:140px !important;
|
69 |
+
}
|
70 |
+
.grid table td.action-column .button{
|
71 |
+
width:94px;
|
72 |
+
}
|
73 |
+
.grid table td.action-column .delete{
|
74 |
+
width:94px;
|
75 |
+
}
|
76 |
+
.value-field-wrapper{
|
77 |
+
padding:0 2px;
|
78 |
+
border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;
|
79 |
+
border-style:solid;
|
80 |
+
border-width:1px;
|
81 |
+
clear:both;
|
82 |
+
overflow:hidden;
|
83 |
+
zoom:1;
|
84 |
+
}
|
85 |
+
.value-field-wrapper input{
|
86 |
+
width:99%;
|
87 |
+
float:left;
|
88 |
+
height:16px;
|
89 |
+
border:0;
|
90 |
+
padding:0;
|
91 |
+
}
|
92 |
+
.result-wrapper{
|
93 |
+
padding:0 2px;
|
94 |
+
border-color:#AAAAAA #C8C8C8 #C8C8C8 #AAAAAA;
|
95 |
+
border-style:solid;
|
96 |
+
border-width:1px;
|
97 |
+
clear:both;
|
98 |
+
overflow:hidden;
|
99 |
+
zoom:1;
|
100 |
+
}
|
101 |
+
.result-wrapper input{
|
102 |
+
width:100%;
|
103 |
+
border:0;
|
104 |
+
padding:0;
|
105 |
+
}
|