straker-translations-easy-translation-platform - Version 1.3.4

Version Notes

Bug fix release

Download this release

Release Info

Developer Chris
Extension straker-translations-easy-translation-platform
Version 1.3.4
Comparing to
See all releases


Code changes from version 1.3.3 to 1.3.4

Files changed (44) hide show
  1. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Cms/Block/Grid.php +3 -3
  2. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Cms/Page/Grid.php +3 -3
  3. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Attribute/Grid.php +12 -11
  4. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Category/Grid.php +36 -28
  5. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Cms/Block/Grid.php +1 -1
  6. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Cms/Page/Grid.php +1 -1
  7. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Grid.php +9 -2
  8. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Product/Grid.php +36 -28
  9. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Attribute/Grid.php +38 -11
  10. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Category/Confirm/Grid.php +32 -3
  11. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Cms/Page/Grid.php +3 -1
  12. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Confirm.php +42 -0
  13. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Confirm/Grid.php +150 -0
  14. app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Products/Grid.php +34 -10
  15. app/code/community/StrakerTranslations/EasyTranslationPlatform/Helper/Data.php +28 -0
  16. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Api.php +7 -1
  17. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Attribute/Translate.php +106 -45
  18. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Cms/Block/Translate.php +22 -14
  19. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Cms/Page/Translate.php +24 -13
  20. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Job.php +470 -304
  21. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Resource/Job.php +4 -3
  22. app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/System/Config/Source/SiteMode.php +59 -0
  23. app/code/community/StrakerTranslations/EasyTranslationPlatform/controllers/Adminhtml/Straker/AttributeController.php +11 -0
  24. app/code/community/StrakerTranslations/EasyTranslationPlatform/controllers/Adminhtml/Straker/CategoryController.php +10 -0
  25. app/code/community/StrakerTranslations/EasyTranslationPlatform/controllers/Adminhtml/Straker/JobController.php +13 -0
  26. app/code/community/StrakerTranslations/EasyTranslationPlatform/controllers/Adminhtml/Straker/NewController.php +61 -49
  27. app/code/community/StrakerTranslations/EasyTranslationPlatform/controllers/Adminhtml/Straker/ProductController.php +10 -0
  28. app/code/community/StrakerTranslations/EasyTranslationPlatform/data/strakertranslations_easytranslationplatform_setup/data-install-1.2.0.php +22 -0
  29. app/code/community/StrakerTranslations/EasyTranslationPlatform/data/strakertranslations_easytranslationplatform_setup/data-upgrade-1.2.0-1.3.0.php +11 -0
  30. app/code/community/StrakerTranslations/EasyTranslationPlatform/etc/config.xml +9 -9
  31. app/code/community/StrakerTranslations/EasyTranslationPlatform/etc/system.xml +117 -100
  32. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/install-1.2.0.php +752 -0
  33. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/mysql4-install-1.0.0.php +0 -179
  34. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/mysql4-upgrade-1.0.0-1.1.0.php +0 -53
  35. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/mysql4-upgrade-1.1.0-1.2.0.php +0 -218
  36. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/mysql4-upgrade-1.3.0-1.3.1.php +0 -127
  37. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/upgrade-1.2.0-1.3.0.php +358 -0
  38. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/upgrade-1.3.0-1.3.1.php +91 -0
  39. app/code/community/StrakerTranslations/EasyTranslationPlatform/sql/strakertranslations_easytranslationplatform_setup/upgrade-1.3.3-1.3.4.php +80 -0
  40. app/design/adminhtml/default/straker/template/straker/new/attribute/confirm.phtml +1 -1
  41. app/design/adminhtml/default/straker/template/straker/new/attributes.phtml +31 -0
  42. app/design/adminhtml/default/straker/template/straker/new/products/confirm.phtml +1 -1
  43. js/straker/translations.js +7 -3
  44. package.xml +7 -7
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Cms/Block/Grid.php CHANGED
@@ -2,11 +2,11 @@
2
class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Cms_Block_Grid extends Mage_Adminhtml_Block_Cms_Block_Grid {
3
protected function _prepareCollection()
4
{
5
$collection = Mage::getModel('cms/block')->getCollection();
6
- /* @var $collection Mage_Cms_Model_Mysql4_Block_Collection */
7
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
8
$collection->getSelect()->joinLeft(
9
- array('straker' => $prefix.'straker_job_cmsblock'),
10
'straker.new_entity_id = main_table.block_id',
11
array('straker_translated' => 'straker.version')
12
);
2
class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Cms_Block_Grid extends Mage_Adminhtml_Block_Cms_Block_Grid {
3
protected function _prepareCollection()
4
{
5
+ /* @var $collection Mage_Cms_Model_Resource_Block_Collection */
6
$collection = Mage::getModel('cms/block')->getCollection();
7
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
8
$collection->getSelect()->joinLeft(
9
+ array('straker' => $collection->getTable('strakertranslations_easytranslationplatform/job_cmsblock')),
10
'straker.new_entity_id = main_table.block_id',
11
array('straker_translated' => 'straker.version')
12
);
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Cms/Page/Grid.php CHANGED
@@ -2,11 +2,11 @@
2
class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Cms_Page_Grid extends Mage_Adminhtml_Block_Cms_Page_Grid {
3
protected function _prepareCollection()
4
{
5
$collection = Mage::getModel('cms/page')->getCollection();
6
- /* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */
7
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
8
$collection->getSelect()->joinLeft(
9
- array('straker' => $prefix.'straker_job_cmspage'),
10
'straker.new_entity_id = main_table.page_id',
11
array('straker_translated' => 'straker.version')
12
);
2
class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Cms_Page_Grid extends Mage_Adminhtml_Block_Cms_Page_Grid {
3
protected function _prepareCollection()
4
{
5
+ /* @var $collection Mage_Cms_Model_Resource_Page_Collection */
6
$collection = Mage::getModel('cms/page')->getCollection();
7
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
8
$collection->getSelect()->joinLeft(
9
+ array('straker' => $collection->getTable('strakertranslations_easytranslationplatform/job_cmspage')),
10
'straker.new_entity_id = main_table.page_id',
11
array('straker_translated' => 'straker.version')
12
);
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Attribute/Grid.php CHANGED
@@ -23,22 +23,23 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Attribute_
23
}
24
25
protected function _prepareCollection() {
26
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
27
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
28
29
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_attribute')->getCollection()
30
->addFieldToFilter('main_table.job_id', $job->getId());
31
32
- $collection->getSelect()->joinLeft(
33
- array('ea' => $prefix.'eav_attribute'),
34
- 'ea.attribute_id = main_table.attribute_id',
35
- array('attribute_code' => 'attribute_code')
36
- );
37
- $collection->getSelect()->joinLeft(
38
- array('translate' => $prefix.'straker_attribute_translate'),
39
- 'translate.attribute_id = main_table.attribute_id AND translate.job_id = '.$job->getId(),
40
- array('original' => 'original', 'translate' => 'translate')
41
- );
42
43
44
//echo $collection->getSelect();
23
}
24
25
protected function _prepareCollection() {
26
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
27
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
28
29
+ /** @var StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Attribute_Collection $collection */
30
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_attribute')->getCollection()
31
->addFieldToFilter('main_table.job_id', $job->getId());
32
33
+ $collection->getSelect()
34
+ ->joinLeft(
35
+ array('ea' => $collection->getTable('eav/attribute')),
36
+ 'ea.attribute_id = main_table.attribute_id',
37
+ array('attribute_code' => 'attribute_code')
38
+ )->joinLeft(
39
+ array('translate' => $collection->getTable('strakertranslations_easytranslationplatform/straker_attribute_translate')),
40
+ 'translate.attribute_id = main_table.attribute_id AND translate.job_id = '.$job->getId(),
41
+ array('original' => 'original', 'translate' => 'translate')
42
+ );
43
44
45
//echo $collection->getSelect();
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Category/Grid.php CHANGED
@@ -1,8 +1,10 @@
1
<?php
2
3
- class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid {
4
5
- public function __construct() {
6
parent::__construct();
7
$this->setId('strakerJobCategoryGrid');
8
$this->setSaveParametersInSession(true);
@@ -13,9 +15,9 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
13
$this->setChild('dispute_button',
14
$this->getLayout()->createBlock('adminhtml/widget_button')
15
->setData(array(
16
- 'label' => Mage::helper('catalog')->__('Feedback'),
17
- 'onclick' => 'disputeForm.show(\''.$this->getRequest()->getParam('job_id').'\')',
18
- 'class' => 'feedback'
19
))
20
);
21
@@ -23,20 +25,24 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
23
return parent::_prepareLayout();
24
}
25
26
- protected function _prepareCollection() {
27
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
28
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
29
- $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
30
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_category')->getCollection()->addFieldToFilter('main_table.job_id', $job->getId());
31
32
//loop through this job's attributes and join them to the collection
33
- foreach($jobAttributes as $jobAttribute){
34
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
35
$collection->getSelect()->joinLeft(
36
- array($attributeCode => $prefix.'straker_category_translate'),
37
- $attributeCode.'.category_id = main_table.category_id AND '.$attributeCode.'.attribute_id = '.$jobAttribute->getAttributeId(). ' AND '
38
- .$attributeCode.'.job_id = '.$job->getId(),
39
- array($attributeCode.'_original' => 'original', $attributeCode.'_translate' => 'translate')
40
);
41
}
42
//echo $collection->getSelect()->__toString();
@@ -45,7 +51,8 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
45
return parent::_prepareCollection();
46
}
47
48
- protected function _prepareColumns() {
49
// $this->addColumn('id', array(
50
// 'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('ID'),
51
// 'align' => 'right',
@@ -66,32 +73,32 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
66
// ));
67
68
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
69
- $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
70
71
//loop through this job's attributes and add columns to the grid
72
- foreach($jobAttributes as $jobAttribute){
73
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
74
$attrModel = Mage::getModel('eav/entity_attribute')->loadByCode(3, $attributeCode);
75
- $this->addColumn($attributeCode.'_original', array(
76
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Source', $attrModel->getFrontendLabel()),
77
'align' => 'left',
78
- 'index' => $attributeCode.'_original',
79
));
80
81
- $this->addColumn($attributeCode.'_translate', array(
82
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Target', $attrModel->getFrontendLabel()),
83
'align' => 'left',
84
- 'index' => $attributeCode.'_translate',
85
));
86
}
87
88
- if ($this->getStatusId() == '4'){
89
$this->addColumn('version', array(
90
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('Published'),
91
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Version',
92
'align' => 'center',
93
'index' => false,
94
- 'filter' => false,
95
));
96
}
97
@@ -100,7 +107,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
100
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Frontend',
101
'align' => 'center',
102
'index' => false,
103
- 'filter' => false,
104
));
105
106
$this->addColumn('view_backend', array(
@@ -108,13 +115,14 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
108
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Backend',
109
'align' => 'center',
110
'index' => false,
111
- 'filter' => false,
112
));
113
114
return parent::_prepareColumns();
115
}
116
117
- public function getRowUrl($row) {
118
// return $this->getUrl('*/*/edit', array('id' => $row->getId()));
119
return '';
120
}
@@ -179,9 +187,9 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_G
179
if ($this->getStatusId() == '4') {
180
$html .= $this->getChildHtml('dispute_button');
181
}
182
- if($this->getFilterVisibility()){
183
- $html.= $this->getResetFilterButtonHtml();
184
- $html.= $this->getSearchButtonHtml();
185
}
186
return $html;
187
}
1
<?php
2
3
+ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
6
+ public function __construct()
7
+ {
8
parent::__construct();
9
$this->setId('strakerJobCategoryGrid');
10
$this->setSaveParametersInSession(true);
15
$this->setChild('dispute_button',
16
$this->getLayout()->createBlock('adminhtml/widget_button')
17
->setData(array(
18
+ 'label' => Mage::helper('catalog')->__('Feedback'),
19
+ 'onclick' => 'disputeForm.show(\'' . $this->getRequest()->getParam('job_id') . '\')',
20
+ 'class' => 'feedback'
21
))
22
);
23
25
return parent::_prepareLayout();
26
}
27
28
+ protected function _prepareCollection()
29
+ {
30
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
31
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
32
+ $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
33
+
34
+ /** @var StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Category_Collection $collection */
35
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_category')->getCollection()->addFieldToFilter('main_table.job_id', $job->getId());
36
37
//loop through this job's attributes and join them to the collection
38
+ foreach ($jobAttributes as $jobAttribute) {
39
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
40
$collection->getSelect()->joinLeft(
41
+ array($attributeCode => $collection->getTable('strakertranslations_easytranslationplatform/category_translate')),
42
+ $attributeCode . '.category_id = main_table.category_id
43
+ AND ' . $attributeCode . '.attribute_id = ' . $jobAttribute->getAttributeId() . '
44
+ AND ' . $attributeCode . '.job_id = ' . $job->getId(),
45
+ array($attributeCode . '_original' => 'original', $attributeCode . '_translate' => 'translate')
46
);
47
}
48
//echo $collection->getSelect()->__toString();
51
return parent::_prepareCollection();
52
}
53
54
+ protected function _prepareColumns()
55
+ {
56
// $this->addColumn('id', array(
57
// 'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('ID'),
58
// 'align' => 'right',
73
// ));
74
75
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
76
+ $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
77
78
//loop through this job's attributes and add columns to the grid
79
+ foreach ($jobAttributes as $jobAttribute) {
80
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
81
$attrModel = Mage::getModel('eav/entity_attribute')->loadByCode(3, $attributeCode);
82
+ $this->addColumn($attributeCode . '_original', array(
83
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Source', $attrModel->getFrontendLabel()),
84
'align' => 'left',
85
+ 'index' => $attributeCode . '_original',
86
));
87
88
+ $this->addColumn($attributeCode . '_translate', array(
89
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Target', $attrModel->getFrontendLabel()),
90
'align' => 'left',
91
+ 'index' => $attributeCode . '_translate',
92
));
93
}
94
95
+ if ($this->getStatusId() == '4') {
96
$this->addColumn('version', array(
97
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('Published'),
98
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Version',
99
'align' => 'center',
100
'index' => false,
101
+ 'filter' => false,
102
));
103
}
104
107
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Frontend',
108
'align' => 'center',
109
'index' => false,
110
+ 'filter' => false,
111
));
112
113
$this->addColumn('view_backend', array(
115
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Backend',
116
'align' => 'center',
117
'index' => false,
118
+ 'filter' => false,
119
));
120
121
return parent::_prepareColumns();
122
}
123
124
+ public function getRowUrl($row)
125
+ {
126
// return $this->getUrl('*/*/edit', array('id' => $row->getId()));
127
return '';
128
}
187
if ($this->getStatusId() == '4') {
188
$html .= $this->getChildHtml('dispute_button');
189
}
190
+ if ($this->getFilterVisibility()) {
191
+ $html .= $this->getResetFilterButtonHtml();
192
+ $html .= $this->getSearchButtonHtml();
193
}
194
return $html;
195
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Cms/Block/Grid.php CHANGED
@@ -25,7 +25,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Cms_Block_
25
}
26
27
protected function _prepareCollection() {
28
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
29
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
30
31
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_cms_block')->getCollection()
25
}
26
27
protected function _prepareCollection() {
28
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
29
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
30
31
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_cms_block')->getCollection()
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Cms/Page/Grid.php CHANGED
@@ -25,7 +25,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Cms_Page_G
25
}
26
27
protected function _prepareCollection() {
28
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
29
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
30
31
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_cms_page')->getCollection()
25
}
26
27
protected function _prepareCollection() {
28
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
29
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
30
31
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_cms_page')->getCollection()
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Grid.php CHANGED
@@ -11,6 +11,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Grid exten
11
}
12
13
protected function _prepareCollection() {
14
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job')->getCollection();
15
16
foreach($collection as $jobModel){
@@ -19,9 +20,16 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Grid exten
19
}
20
}
21
22
-
23
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job')->getCollection();
24
25
$collection->getSelect()->joinLeft(
26
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_type'),
27
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_type').'.type_id = main_table.type_id',
@@ -31,7 +39,6 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Grid exten
31
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_status'),
32
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_status').'.status_id = main_table.status_id',
33
'status_name'
34
-
35
);
36
$collection->getSelect()->joinLeft(
37
Mage::getSingleton('core/resource')->getTableName('core/store'),
11
}
12
13
protected function _prepareCollection() {
14
+ /** @var $collection StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Collection*/
15
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job')->getCollection();
16
17
foreach($collection as $jobModel){
20
}
21
}
22
23
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job')->getCollection();
24
25
+ /** @var $helper StrakerTranslations_EasyTranslationPlatform_Helper_Data */
26
+ $helper = Mage::helper('strakertranslations_easytranslationplatform');
27
+ if($helper->isSandboxMode()){
28
+ $collection->addFieldToFilter('is_test_job', ['eq' => true]);
29
+ }else{
30
+ $collection->addFieldToFilter('is_test_job', ['eq' => false]);
31
+ }
32
+
33
$collection->getSelect()->joinLeft(
34
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_type'),
35
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_type').'.type_id = main_table.type_id',
39
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_status'),
40
Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_status').'.status_id = main_table.status_id',
41
'status_name'
42
);
43
$collection->getSelect()->joinLeft(
44
Mage::getSingleton('core/resource')->getTableName('core/store'),
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/Job/Product/Grid.php CHANGED
@@ -1,8 +1,10 @@
1
<?php
2
3
- class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid {
4
5
- public function __construct() {
6
parent::__construct();
7
$this->setId('strakerJobProductGrid');
8
$this->setSaveParametersInSession(true);
@@ -13,9 +15,9 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
13
$this->setChild('dispute_button',
14
$this->getLayout()->createBlock('adminhtml/widget_button')
15
->setData(array(
16
- 'label' => Mage::helper('catalog')->__('Feedback'),
17
- 'onclick' => 'disputeForm.show(\''.$this->getRequest()->getParam('job_id').'\')',
18
- 'class' => 'feedback'
19
))
20
);
21
@@ -23,20 +25,24 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
23
return parent::_prepareLayout();
24
}
25
26
- protected function _prepareCollection() {
27
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
28
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
29
- $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
30
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_product')->getCollection()->addFieldToFilter('main_table.job_id', $job->getId());
31
32
//loop through this job's attributes and join them to the collection
33
- foreach($jobAttributes as $jobAttribute){
34
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
35
$collection->getSelect()->joinLeft(
36
- array($attributeCode => $prefix.'straker_product_translate'),
37
- $attributeCode.'.product_id = main_table.product_id AND '.$attributeCode.'.attribute_id = '.$jobAttribute->getAttributeId(). ' AND '
38
- .$attributeCode.'.job_id = '.$job->getId(),
39
- array($attributeCode.'_original' => 'original', $attributeCode.'_translate' => 'translate')
40
);
41
}
42
//echo $collection->getSelect()->__toString();
@@ -45,7 +51,8 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
45
return parent::_prepareCollection();
46
}
47
48
- protected function _prepareColumns() {
49
$this->addColumn('id', array(
50
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('ID'),
51
'align' => 'right',
@@ -66,32 +73,32 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
66
// ));
67
68
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
69
- $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
70
71
//loop through this job's attributes and add columns to the grid
72
- foreach($jobAttributes as $jobAttribute){
73
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
74
$attrModel = Mage::getModel('eav/entity_attribute')->loadByCode(4, $attributeCode);
75
- $this->addColumn($attributeCode.'_original', array(
76
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Source', $attrModel->getFrontendLabel()),
77
'align' => 'left',
78
- 'index' => $attributeCode.'_original',
79
));
80
81
- $this->addColumn($attributeCode.'_translate', array(
82
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Target', $attrModel->getFrontendLabel()),
83
'align' => 'left',
84
- 'index' => $attributeCode.'_translate',
85
));
86
}
87
88
- if ($this->getStatusId() == '4'){
89
$this->addColumn('version', array(
90
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('Published'),
91
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Version',
92
'align' => 'center',
93
'index' => false,
94
- 'filter' => false,
95
));
96
}
97
@@ -100,7 +107,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
100
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Frontend',
101
'align' => 'center',
102
'index' => false,
103
- 'filter' => false,
104
));
105
106
$this->addColumn('view_backend', array(
@@ -108,13 +115,14 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
108
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Backend',
109
'align' => 'center',
110
'index' => false,
111
- 'filter' => false,
112
));
113
114
return parent::_prepareColumns();
115
}
116
117
- public function getRowUrl($row) {
118
// return $this->getUrl('*/*/edit', array('id' => $row->getId()));
119
return '';
120
}
@@ -179,9 +187,9 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Gr
179
if ($this->getStatusId() == '4') {
180
$html .= $this->getChildHtml('dispute_button');
181
}
182
- if($this->getFilterVisibility()){
183
- $html.= $this->getResetFilterButtonHtml();
184
- $html.= $this->getSearchButtonHtml();
185
}
186
return $html;
187
}
1
<?php
2
3
+ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Job_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
6
+ public function __construct()
7
+ {
8
parent::__construct();
9
$this->setId('strakerJobProductGrid');
10
$this->setSaveParametersInSession(true);
15
$this->setChild('dispute_button',
16
$this->getLayout()->createBlock('adminhtml/widget_button')
17
->setData(array(
18
+ 'label' => Mage::helper('catalog')->__('Feedback'),
19
+ 'onclick' => 'disputeForm.show(\'' . $this->getRequest()->getParam('job_id') . '\')',
20
+ 'class' => 'feedback'
21
))
22
);
23
25
return parent::_prepareLayout();
26
}
27
28
+ protected function _prepareCollection()
29
+ {
30
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
31
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
32
+ $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
33
+
34
+ /** @var StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Product_Collection $collection */
35
$collection = Mage::getModel('strakertranslations_easytranslationplatform/job_product')->getCollection()->addFieldToFilter('main_table.job_id', $job->getId());
36
37
//loop through this job's attributes and join them to the collection
38
+ foreach ($jobAttributes as $jobAttribute) {
39
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
40
$collection->getSelect()->joinLeft(
41
+ array($attributeCode => $collection->getTable('strakertranslations_easytranslationplatform/product_translate')),
42
+ $attributeCode . '.product_id = main_table.product_id
43
+ AND ' . $attributeCode . '.attribute_id = ' . $jobAttribute->getAttributeId() . '
44
+ AND ' . $attributeCode . '.job_id = ' . $job->getId(),
45
+ array($attributeCode . '_original' => 'original', $attributeCode . '_translate' => 'translate')
46
);
47
}
48
//echo $collection->getSelect()->__toString();
51
return parent::_prepareCollection();
52
}
53
54
+ protected function _prepareColumns()
55
+ {
56
$this->addColumn('id', array(
57
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('ID'),
58
'align' => 'right',
73
// ));
74
75
$job = Mage::getModel('strakertranslations_easytranslationplatform/job')->load($this->getRequest()->getParam('job_id'));
76
+ $jobAttributes = Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')->getCollection()->addFieldToFilter('job_id', $job->getId());
77
78
//loop through this job's attributes and add columns to the grid
79
+ foreach ($jobAttributes as $jobAttribute) {
80
$attributeCode = Mage::getModel('eav/entity_attribute')->load($jobAttribute->getAttributeId())->getAttributeCode();
81
$attrModel = Mage::getModel('eav/entity_attribute')->loadByCode(4, $attributeCode);
82
+ $this->addColumn($attributeCode . '_original', array(
83
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Source', $attrModel->getFrontendLabel()),
84
'align' => 'left',
85
+ 'index' => $attributeCode . '_original',
86
));
87
88
+ $this->addColumn($attributeCode . '_translate', array(
89
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('%s - Target', $attrModel->getFrontendLabel()),
90
'align' => 'left',
91
+ 'index' => $attributeCode . '_translate',
92
));
93
}
94
95
+ if ($this->getStatusId() == '4') {
96
$this->addColumn('version', array(
97
'header' => Mage::helper('strakertranslations_easytranslationplatform')->__('Published'),
98
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Version',
99
'align' => 'center',
100
'index' => false,
101
+ 'filter' => false,
102
));
103
}
104
107
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Frontend',
108
'align' => 'center',
109
'index' => false,
110
+ 'filter' => false,
111
));
112
113
$this->addColumn('view_backend', array(
115
'renderer' => 'StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_Template_Grid_Renderer_Backend',
116
'align' => 'center',
117
'index' => false,
118
+ 'filter' => false,
119
));
120
121
return parent::_prepareColumns();
122
}
123
124
+ public function getRowUrl($row)
125
+ {
126
// return $this->getUrl('*/*/edit', array('id' => $row->getId()));
127
return '';
128
}
187
if ($this->getStatusId() == '4') {
188
$html .= $this->getChildHtml('dispute_button');
189
}
190
+ if ($this->getFilterVisibility()) {
191
+ $html .= $this->getResetFilterButtonHtml();
192
+ $html .= $this->getSearchButtonHtml();
193
}
194
return $html;
195
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Attribute/Grid.php CHANGED
@@ -22,24 +22,51 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Attribute_
22
*/
23
protected function _prepareCollection()
24
{
25
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
26
->addVisibleFilter();
27
28
$store = $this->_getStore();
29
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
30
- $jobAttributeQuery = 'select a.`version`, a.`attribute_id` from `'.$prefix.'straker_job_attribute` as a
31
- left join `'.$prefix.'straker_job` as b on a.`job_id`=b.`id`
32
- where b.`store_id` ='.$store->getId().' and a.`version` =1
33
- GROUP BY a.`attribute_id`';
34
35
- //join straker job product table to get version for each product
36
$collection->getSelect()->joinLeft(
37
-
38
- new Zend_Db_Expr('('.$jobAttributeQuery.')'),
39
- 'main_table.attribute_id = t.attribute_id',
40
- array('version')
41
-
42
);
43
$this->setCollection($collection);
44
45
return parent::_prepareCollection();
22
*/
23
protected function _prepareCollection()
24
{
25
+ /** @var \Mage_Catalog_Model_Resource_Product_Attribute_Collection $collection */
26
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
27
->addVisibleFilter();
28
29
$store = $this->_getStore();
30
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
31
+ // $jobAttributeQuery = 'select a.`version`, a.`attribute_id` from `'.$prefix.'straker_job_attribute` as a
32
+ // left join `'.$prefix.'straker_job` as b on a.`job_id`=b.`id`
33
+ // where b.`store_id` ='.$store->getId().' and a.`version` =1
34
+ // GROUP BY a.`attribute_id`';
35
+ //
36
+ // //join straker job product table to get version for each product
37
+ // $collection->getSelect()->joinLeft(
38
+ //
39
+ // new Zend_Db_Expr('('.$jobAttributeQuery.')'),
40
+ // 'main_table.attribute_id = t.attribute_id',
41
+ // array('version')
42
+ //
43
+ // );
44
+ /** @var StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Attribute_Collection $strakerJobProductCollection */
45
+ $strakerJobAttributeCollection = Mage::getModel('strakertranslations_easytranslationplatform/job_attribute')->getCollection();
46
+ $strakerJobAttributeCollection->getSelect()
47
+ ->reset(Zend_Db_Select::COLUMNS)
48
+ ->joinLeft(
49
+ ['b' => $strakerJobAttributeCollection->getTable('strakertranslations_easytranslationplatform/job')],
50
+ '`main_table`.`job_id` = `b`.`id`',
51
+ []
52
+ )->where(
53
+ '`b`.`store_id` = ?', $store->getId()
54
+ )->where(
55
+ '`main_table`.`version` = ?', 1
56
+ )->group(
57
+ 'main_table.attribute_id'
58
+ )->columns(
59
+ ['version' => 'version', 'attribute_id' => 'attribute_id']
60
+ );
61
+
62
+ $jobAttributeQuery = $strakerJobAttributeCollection->getSelect();
63
64
$collection->getSelect()->joinLeft(
65
+ $jobAttributeQuery,
66
+ 'main_table.attribute_id = t.attribute_id',
67
+ array('version')
68
);
69
+
70
$this->setCollection($collection);
71
72
return parent::_prepareCollection();
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Category/Confirm/Grid.php CHANGED
@@ -23,8 +23,35 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Category_C
23
{
24
return $this;
25
}
26
protected function _prepareCollection()
27
{
28
$collection = Mage::getModel('catalog/category')->getCollection()
29
->addAttributeToSelect('path')
30
->addAttributeToSelect('name');
@@ -34,11 +61,13 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Category_C
34
$collection->addAttributeToSelect($attr);
35
}
36
37
//join straker job product table to get version for each product
38
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
39
$collection->getSelect()->joinLeft(
40
- $prefix.'straker_job_category',
41
- $prefix.'straker_job_category.category_id = e.entity_id',
42
'version'
43
);
44
23
{
24
return $this;
25
}
26
+ // protected function _prepareCollection()
27
+ // {
28
+ // $collection = Mage::getModel('catalog/category')->getCollection()
29
+ // ->addAttributeToSelect('path')
30
+ // ->addAttributeToSelect('name');
31
+ // $collection->addAttributeToFilter('entity_id', array('in' => $this->getCategory()));
32
+ //
33
+ // foreach ($this->getAttrArray() as $attr){
34
+ // $collection->addAttributeToSelect($attr);
35
+ // }
36
+ //
37
+ // //join straker job product table to get version for each product
38
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
39
+ // $collection->getSelect()->joinLeft(
40
+ // $prefix.'straker_job_category',
41
+ // $prefix.'straker_job_category.category_id = e.entity_id',
42
+ // 'version'
43
+ // );
44
+ //
45
+ // $this->setCollection($collection);
46
+ //
47
+ // parent::_prepareCollection();
48
+ //// $this->getCollection()->addWebsiteNamesToResult();
49
+ // return $this;
50
+ // }
51
+
52
protected function _prepareCollection()
53
{
54
+ /** @var Mage_Catalog_Model_Resource_Category_Collection $collection */
55
$collection = Mage::getModel('catalog/category')->getCollection()
56
->addAttributeToSelect('path')
57
->addAttributeToSelect('name');
61
$collection->addAttributeToSelect($attr);
62
}
63
64
+ $strakerJobCategoryTable = $collection->getResource()->getTable('strakertranslations_easytranslationplatform/job_category');
65
+
66
//join straker job product table to get version for each product
67
+
68
$collection->getSelect()->joinLeft(
69
+ ['a' => $strakerJobCategoryTable ],
70
+ 'a.category_id = e.entity_id AND a.version = 1',
71
'version'
72
);
73
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Cms/Page/Grid.php CHANGED
@@ -14,9 +14,11 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Cms_Page_G
14
15
protected function _prepareCollection()
16
{
17
- $collection = Mage::getModel('cms/page')->getCollection();
18
/* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */
19
$collection->setFirstStoreFlag(true);
20
$this->setCollection($collection);
21
22
return parent::_prepareCollection();
14
15
protected function _prepareCollection()
16
{
17
/* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */
18
+ $collection = Mage::getModel('cms/page')->getCollection();
19
+ //todo: should add $collection->addStoreFilter(sourceStoreId);
20
$collection->setFirstStoreFlag(true);
21
+ //var_dump($collection->getSelect()->__toString());exit;
22
$this->setCollection($collection);
23
24
return parent::_prepareCollection();
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Confirm.php ADDED
@@ -0,0 +1,42 @@
1
+ <?php
2
+ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Confirm extends Mage_Adminhtml_Block_Widget_Container
3
+ {
4
+ /**
5
+ * Set template
6
+ */
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setTemplate('straker/new/confirm.phtml');
11
+ }
12
+
13
+ /**
14
+ * Prepare button and grid
15
+ *
16
+ * @return Mage_Adminhtml_Block_Catalog_Product
17
+ */
18
+ protected function _prepareLayout()
19
+ {
20
+ $this->_addButton('submit', array(
21
+ 'label' => Mage::helper('catalog')->__('Submit'),
22
+ 'onclick' => "$('submit-new-job-form').submit();",
23
+ // 'onclick' => "setLocation('{$this->getUrl('*/*/submit')}')",
24
+ 'class' => 'task'
25
+ ));
26
+
27
+ $this->setChild('grid', $this->getLayout()->createBlock('strakertranslations_easytranslationplatform/adminhtml_new_confirm_grid', 'product.grid', array('store' => $this->getStore(), 'attr' => $this->getAttr(), 'product' => $this->getProduct())));
28
+ return parent::_prepareLayout();
29
+ }
30
+
31
+
32
+ /**
33
+ * Render grid
34
+ *
35
+ * @return string
36
+ */
37
+ public function getGridHtml()
38
+ {
39
+ return $this->getChildHtml('grid');
40
+ }
41
+
42
+ }
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Confirm/Grid.php ADDED
@@ -0,0 +1,150 @@
1
+ <?php
2
+ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Confirm_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('strakerProducts');
9
+ $this->setDefaultSort('entity_id');
10
+ $this->setDefaultDir('DESC');
11
+ $this->setSaveParametersInSession(true);
12
+ $this->setUseAjax(false);
13
+ $this->setVarNameFilter('product_filter');
14
+ }
15
+
16
+ protected function _getStore()
17
+ {
18
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
19
+ return Mage::app()->getStore($storeId);
20
+ }
21
+ protected function _prepareLayout()
22
+ {
23
+ return $this;
24
+ }
25
+ protected function _prepareCollection()
26
+ {
27
+ $store = $this->_getStore();
28
+ $collection = Mage::getModel('catalog/product')->getCollection()
29
+ ->addAttributeToSelect('sku')
30
+ ->addAttributeToSelect('name')
31
+ ->addAttributeToSelect('type_id');
32
+ $collection->addAttributeToFilter('entity_id', array('in' => $this->getProduct()));
33
+
34
+ foreach ($this->getAttrArray() as $attr){
35
+ $collection->addAttributeToSelect($attr);
36
+ }
37
+ if ($store->getId()) {
38
+ //$collection->setStoreId($store->getId());
39
+ $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
40
+ $collection->addStoreFilter($store);
41
+ $collection->joinAttribute(
42
+ 'name',
43
+ 'catalog_product/name',
44
+ 'entity_id',
45
+ null,
46
+ 'inner',
47
+ $adminStore
48
+ );
49
+ $collection->joinAttribute(
50
+ 'status',
51
+ 'catalog_product/status',
52
+ 'entity_id',
53
+ null,
54
+ 'inner',
55
+ $store->getId()
56
+ );
57
+ $collection->joinAttribute(
58
+ 'visibility',
59
+ 'catalog_product/visibility',
60
+ 'entity_id',
61
+ null,
62
+ 'inner',
63
+ $store->getId()
64
+ );
65
+ }
66
+ else {
67
+ $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
68
+ $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
69
+ }
70
+
71
+ $this->setCollection($collection);
72
+
73
+ parent::_prepareCollection();
74
+ $this->getCollection()->addWebsiteNamesToResult();
75
+ return $this;
76
+ }
77
+
78
+ protected function _addColumnFilterToCollection($column)
79
+ {
80
+ if ($this->getCollection()) {
81
+ if ($column->getId() == 'websites') {
82
+ $this->getCollection()->joinField('websites',
83
+ 'catalog/product_website',
84
+ 'website_id',
85
+ 'product_id=entity_id',
86
+ null,
87
+ 'left');
88
+ }
89
+ }
90
+ return parent::_addColumnFilterToCollection($column);
91
+ }
92
+
93
+ protected function _prepareColumns()
94
+ {
95
+
96
+ $this->addColumn('entity_id',
97
+ array(
98
+ 'header'=> Mage::helper('catalog')->__('ID'),
99
+ 'width' => '50px',
100
+ 'type' => 'number',
101
+ 'index' => 'entity_id',
102
+ 'filter' => false,
103
+ ));
104
+
105
+ if (in_array('name',$this->getAttrArray())) {
106
+ $this->addColumn('name',
107
+ array(
108
+ 'header' => Mage::helper('catalog')->__('Name to translate'),
109
+ 'index' => 'name',
110
+ 'filter' => false,
111
+ ));
112
+ }
113
+ else{
114
+ $this->addColumn('name',
115
+ array(
116
+ 'header' => Mage::helper('catalog')->__('Name'),
117
+ 'index' => 'name',
118
+ 'filter' => false,
119
+ ));
120
+ }
121
+
122
+ foreach ($this->getAttrArray() as $attr){
123
+ if ($attr!='name') {
124
+ $attrModel = Mage::getModel('eav/entity_attribute')->loadByCode(4, $attr);
125
+ $this->addColumn($attr,
126
+ array(
127
+ 'header' => Mage::helper('catalog')->__($attrModel->getFrontendLabel()) .' to Translate',
128
+ 'index' => $attr,
129
+ 'filter' => false,
130
+ ));
131
+ }
132
+ }
133
+
134
+ return parent::_prepareColumns();
135
+ }
136
+
137
+ public function getGridUrl()
138
+ {
139
+ return $this->getUrl('*/*/addtoconfirm', array('_current'=>true));
140
+ }
141
+
142
+ public function getRowUrl($row)
143
+ {
144
+ return '';
145
+ }
146
+
147
+ public function getAttrArray(){
148
+ return explode(',', $this->getAttr());
149
+ }
150
+ }
app/code/community/StrakerTranslations/EasyTranslationPlatform/Block/Adminhtml/New/Products/Grid.php CHANGED
@@ -22,6 +22,7 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Products_G
22
protected function _prepareCollection()
23
{
24
$store = $this->_getStore();
25
$collection = Mage::getModel('catalog/product')->getCollection()
26
->addAttributeToSelect('sku')
27
->addAttributeToSelect('name')
@@ -63,19 +64,42 @@ class StrakerTranslations_EasyTranslationPlatform_Block_Adminhtml_New_Products_G
63
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
64
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
65
}
66
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
67
- $jobProductQuery = 'select a.`version`, a.`product_id` from `'.$prefix.'straker_job_product` as a
68
- left join `'.$prefix.'straker_job` as b on a.`job_id`=b.`id`
69
- where b.`store_id` = '.$store->getId().' and a.`version` =1
70
- GROUP BY a.`product_id`';
71
72
//join straker job product table to get version for each product
73
$collection->getSelect()->joinLeft(
74
-
75
- new Zend_Db_Expr('('.$jobProductQuery.')'),
76
- 'e.entity_id = t.product_id',
77
- array('version')
78
-
79
);
80
81
$this->setCollection($collection);
22
protected function _prepareCollection()
23
{
24
$store = $this->_getStore();
25
+ /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
26
$collection = Mage::getModel('catalog/product')->getCollection()
27
->addAttributeToSelect('sku')
28
->addAttributeToSelect('name')
64
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
65
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
66
}
67
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
68
+ // $jobProductQuery = 'select a.`version`, a.`product_id` from `'.$prefix.'straker_job_product` as a
69
+ // left join `'.$prefix.'straker_job` as b on a.`job_id`=b.`id`
70
+ // where b.`store_id` = '.$store->getId().' and a.`version` =1
71
+ // GROUP BY a.`product_id`';
72
73
//join straker job product table to get version for each product
74
+ // $collection->getSelect()->joinLeft(
75
+ //
76
+ // new Zend_Db_Expr('('.$jobProductQuery.')'),
77
+ // 'e.entity_id = t.product_id',
78
+ // array('version')
79
+ //
80
+ // );
81
+ /** @var StrakerTranslations_EasyTranslationPlatform_Model_Resource_Job_Product_Collection $strakerJobProductCollection */
82
+ $strakerJobProductCollection = Mage::getModel('strakertranslations_easytranslationplatform/job_product')->getCollection();
83
+ $strakerJobProductCollection->getSelect()
84
+ ->reset(Zend_Db_Select::COLUMNS)
85
+ ->joinLeft(
86
+ ['b' => $collection->getTable('strakertranslations_easytranslationplatform/job')],
87
+ '`main_table`.`job_id` = `b`.`id`',
88
+ []
89
+ )->where(
90
+ '`b`.`store_id` = ?', $store->getId()
91
+ )->where(
92
+ '`main_table`.`version` = ?', 1
93
+ )->group(
94
+ 'main_table.product_id'
95
+ )->columns(
96
+ ['version' => 'version', 'product_id' => 'product_id']
97
+ );
98
+ $jobProductQuery = $strakerJobProductCollection->getSelect();
99
$collection->getSelect()->joinLeft(
100
+ $jobProductQuery,
101
+ 'e.entity_id = t.product_id',
102
+ array('version')
103
);
104
105
$this->setCollection($collection);
app/code/community/StrakerTranslations/EasyTranslationPlatform/Helper/Data.php CHANGED
@@ -58,4 +58,32 @@ class StrakerTranslations_EasyTranslationPlatform_Helper_Data extends Mage_Core_
58
}
59
return $message;
60
}
61
}
58
}
59
return $message;
60
}
61
+
62
+ public function isSandboxMode(){
63
+ // return (Mage::getStoreConfig('straker/general/site_mode') == 0);
64
+ return false;
65
+ }
66
+
67
+ public function getSandboxMessage(){
68
+ return
69
+ '<p>
70
+ <h1>Sandbox Mode Enabled.</h1>
71
+ </p>
72
+ <p>
73
+ Thank you for installing our plugin. We have enabled the Sandbox testing mode for you. Jobs you create while this is enabled
74
+ will not be received by Straker Translations, and content will not be translated by a human - rather it will only be sample
75
+ text. To change the Sandbox Mode, go to
76
+ <a href="'. Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit', ['section' => 'straker']).'">Straker Configuration</a>
77
+ </p>';
78
+ }
79
+
80
+ public function checkSiteMode(){
81
+ if($this->isSandboxMode()){
82
+ Mage::getSingleton('adminhtml/session')->addNotice($this->getSandboxMessage());
83
+ }
84
+ }
85
+
86
+ public function clearSiteMode(){
87
+ return Mage::getModel('core/config')->deleteConfig('straker/general/site_mode', 'default', 0);
88
+ }
89
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Api.php CHANGED
@@ -161,7 +161,13 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Api extends Mage_Core_Mo
161
}
162
163
protected function _getTranslateUrl(){
164
- return Mage::getStoreConfig('straker/api_url/translate');
165
}
166
167
protected function _getQuoteUrl(){
161
}
162
163
protected function _getTranslateUrl(){
164
+ /** @var $helper StrakerTranslations_EasyTranslationPlatform_Helper_Data */
165
+ $helper = Mage::helper('strakertranslations_easytranslationplatform');
166
+ if( $helper->isSandboxMode() ){
167
+ return Mage::getStoreConfig('straker/api_url/translate_sandbox');
168
+ }else{
169
+ return Mage::getStoreConfig('straker/api_url/translate');
170
+ }
171
}
172
173
protected function _getQuoteUrl(){
app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Attribute/Translate.php CHANGED
@@ -14,72 +14,133 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Attribute_Translate exte
14
}
15
16
public function importTranslation(){
17
-
18
19
if ($this->getTranslate()){
20
-
21
$dataInJson = json_encode(simplexml_load_string($this->getTranslate()));
22
$data = json_decode($dataInJson,true);
23
-
24
- $writeConnection = $this->_getConnection();
25
- $prefix = Mage::getConfig()->getTablePrefix()->__toString();
26
$storeId = (int) $this->getStoreId();
27
-
28
foreach ($data as $k => $attribute ){
29
if ($k == 'title' && $attribute){
30
-
31
$attributeId = (int) $this->getAttributeId();
32
-
33
- $writeConnection->query("
34
- INSERT INTO `" . $prefix . "eav_attribute_label` ( `attribute_id`, `store_id`, `value`)
35
- SELECT {$attributeId}, {$storeId}, '{$attribute}'
36
- FROM (select 1) as a
37
- WHERE NOT EXISTS(
38
- select `attribute_label_id`
39
- from `" . $prefix . "eav_attribute_label`
40
- where `attribute_id`={$attributeId} and `store_id` ={$storeId});");
41
-
42
- $writeConnection->query("
43
- UPDATE `" . $prefix . "eav_attribute_label` SET `value` = '{$attribute}'
44
- where `attribute_id`={$attributeId} and `store_id` ={$storeId} limit 1;");
45
-
46
}
47
48
- if ($k = 'option'){
49
- foreach ($attribute as $optionId => $optionValue) {
50
51
- $optionId = str_replace('id_', '',$optionId);
52
53
- $writeConnection->query("
54
- INSERT INTO `" . $prefix . "eav_attribute_option_value` ( `option_id`, `store_id`, `value`)
55
- SELECT {$optionId}, {$storeId}, '{$optionValue}'
56
- FROM (select 1) as a
57
- WHERE NOT EXISTS(
58
- select `value_id`
59
- from `" . $prefix . "eav_attribute_option_value`
60
- where `option_id`={$optionId} and `store_id` ={$storeId});");
61
62
63
- $writeConnection->query("
64
- UPDATE `" . $prefix . "eav_attribute_option_value` SET `value` = '{$optionValue}'
65
- where `option_id`={$optionId} and `store_id` ={$storeId} limit 1;");
66
67
}
68
-
69
}
70
-
71
}
72
-
73
-
74
}
75
-
76
-
77
$this->setIsImported(1)->save();
78
-
79
}
80
81
- private function _getConnection() {
82
- return Mage::getSingleton('core/resource')->getConnection('core_write');
83
- }
84
85
}
14
}
15
16
public function importTranslation(){
17
+ // if ($this->getTranslate()){
18
+ //
19
+ // $dataInJson = json_encode(simplexml_load_string($this->getTranslate()));
20
+ // $data = json_decode($dataInJson,true);
21
+ //
22
+ // $writeConnection = $this->_getConnection();
23
+ // $prefix = Mage::getConfig()->getTablePrefix()->__toString();
24
+ // $storeId = (int) $this->getStoreId();
25
+ //
26
+ // foreach ($data as $k => $attribute ){
27
+ // if ($k == 'title' && $attribute){
28
+ //
29
+ // $attributeId = (int) $this->getAttributeId();
30
+ //
31
+ // $writeConnection->query("
32
+ // INSERT INTO `" . $prefix . "eav_attribute_label` ( `attribute_id`, `store_id`, `value`)
33
+ // SELECT {$attributeId}, {$storeId}, '{$attribute}'
34
+ // FROM (select 1) as a
35
+ // WHERE NOT EXISTS(
36
+ // select `attribute_label_id`
37
+ // from `" . $prefix . "eav_attribute_label`
38
+ // where `attribute_id`={$attributeId} and `store_id` ={$storeId});");
39
+ //
40
+ // $writeConnection->query("
41
+ // UPDATE `" . $prefix . "eav_attribute_label` SET `value` = '{$attribute}'
42
+ // where `attribute_id`={$attributeId} and `store_id` ={$storeId} limit 1;");
43
+ //
44
+ // }
45
+ //
46
+ // if ($k = 'option'){
47
+ // foreach ($attribute as $optionId => $optionValue) {
48
+ //
49
+ // $optionId = str_replace('id_', '',$optionId);
50
+ //
51
+ // $writeConnection->query("
52
+ // INSERT INTO `" . $prefix . "eav_attribute_option_value` ( `option_id`, `store_id`, `value`)
53
+ // SELECT {$optionId}, {$storeId}, '{$optionValue}'
54
+ // FROM (select 1) as a
55
+ // WHERE NOT EXISTS(
56
+ // select `value_id`
57
+ // from `" . $prefix . "eav_attribute_option_value`
58
+ // where `option_id`={$optionId} and `store_id` ={$storeId});");
59
+ //
60
+ //
61
+ // $writeConnection->query("
62
+ // UPDATE `" . $prefix . "eav_attribute_option_value` SET `value` = '{$optionValue}'
63
+ // where `option_id`={$optionId} and `store_id` ={$storeId} limit 1;");
64
+ //
65
+ // }
66
+ //
67
+ // }
68
+ //
69
+ // }
70
+ //
71
+ //
72
+ // }
73
74
if ($this->getTranslate()){
75
$dataInJson = json_encode(simplexml_load_string($this->getTranslate()));
76
$data = json_decode($dataInJson,true);
77
$storeId = (int) $this->getStoreId();
78
+ /** @var Mage_Eav_Model_Attribute $eavAttributeModel */
79
+ $eavAttributeModel = Mage::getModel('eav/entity_attribute');
80
foreach ($data as $k => $attribute ){
81
if ($k == 'title' && $attribute){
82
$attributeId = (int) $this->getAttributeId();
83
+ $newLabel = [$storeId => $attribute];
84
+ $eavAttributeModel->load($attributeId);
85
+ if(!empty($eavAttributeModel->getId())){
86
+ $storeLabels = $eavAttributeModel->getStoreLabels();
87
+ if(is_array($storeLabels)){
88
+ //get all current stores
89
+ $stores = array_keys($storeLabels);
90
+ if(!in_array($storeId, $stores)){
91
+ array_push($storeLabels, $newLabel);
92
+ $eavAttributeModel->setData('store_labels', $storeLabels)->save();
93
+ }
94
+ }
95
+ }
96
}
97
98
+ if ($k == 'option' && $attribute){
99
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
100
101
+ /* @var $model Mage_Catalog_Model_Entity_Attribute */
102
+ $attrModel = Mage::getModel('catalog/resource_eav_attribute');
103
+ $attrModel->load($this->getAttributeId());
104
105
+ /** @var $valuesCollection Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection */
106
+ $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
107
+ ->setStoreFilter(4, false)
108
+ ->setAttributeFilter($attrModel->getId());
109
110
+ //0 => ['option_id' => '20', 'attribute_id' => '92', 'sort_order' => '0', 'value' => 'Black' ]
111
+ $optionData = $valuesCollection->getData();
112
+ $optionIds = array_column($optionData, 'option_id');
113
114
+ $optionValueTable = $setup->getTable('eav/attribute_option_value');
115
116
+ $newOptionData = [];
117
+ foreach ($attribute as $optionId => $optionValue) {
118
+ $optionId = str_replace('id_', '',$optionId);
119
+ /** @var Mage_Eav_Model_Entity_Attribute_Option $optionModel */
120
+ $optionModel = Mage::getModel('eav/entity_attribute_option');
121
+ $optionModel->load($optionId);
122
+ if( !in_array($optionId, $optionIds)){
123
+ array_push(
124
+ $newOptionData,
125
+ [
126
+ 'option_id' => $optionId,
127
+ 'store_id' => $storeId,
128
+ 'value' => $optionValue
129
+ ]
130
+ );
131
+ }
132
+ }
133
+ if($newOptionData){
134
+ $setup->getConnection()->insertMultiple($optionValueTable, $newOptionData);
135
}
136
}
137
}
138
}
139
$this->setIsImported(1)->save();
140
}
141
142
+ // private function _getConnection() {
143
+ // return Mage::getSingleton('core/resource')->getConnection('core_write');
144
+ // }
145
146
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Cms/Block/Translate.php CHANGED
@@ -19,25 +19,33 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Cms_Block_Translate exte
19
->getNewEntityId();
20
21
22
- if ($this->getTranslate()){
23
-
24
- $writeConnection = $this->_getConnection();
25
-
26
- $query = 'UPDATE `'.Mage::getSingleton('core/resource')->getTableName('cms/block')
27
- . '` SET '.$this->getColumnName() .' = \''.addslashes($this->getTranslate()).' \' WHERE block_id = '.$newEntityId;
28
-
29
-
30
- $writeConnection->query($query);
31
-
32
33
}
34
35
$this->setIsImported(1)->save();
36
37
}
38
-
39
- private function _getConnection() {
40
- return Mage::getSingleton('core/resource')->getConnection('core_write');
41
- }
42
43
}
19
->getNewEntityId();
20
21
22
+ // if ($this->getTranslate()){
23
+ //
24
+ // $writeConnection = $this->_getConnection();
25
+ //
26
+ // $query = 'UPDATE `'.Mage::getSingleton('core/resource')->getTableName('cms/block')
27
+ // . '` SET '.$this->getColumnName() .' = \''.addslashes($this->getTranslate()).' \' WHERE block_id = '.$newEntityId;
28
+ //
29
+ //
30
+ // $writeConnection->query($query);
31
+ //
32
+ //
33
+ // }
34
35
+ if ($this->getTranslate()){
36
+ $model = Mage::getModel('cms/block')->load($newEntityId);
37
+ if($model->getId()){
38
+ $model->setData($this->getColumnName(), $this->getTranslate());
39
+ $model->save();
40
+ }
41
}
42
43
$this->setIsImported(1)->save();
44
45
}
46
+ //
47
+ // private function _getConnection() {
48
+ // return Mage::getSingleton('core/resource')->getConnection('core_write');
49
+ // }
50
51
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Cms/Page/Translate.php CHANGED
@@ -19,25 +19,36 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Cms_Page_Translate exten
19
->getNewEntityId();
20
21
22
- if ($this->getTranslate()){
23
-
24
- $writeConnection = $this->_getConnection();
25
-
26
- $query = 'UPDATE `'.Mage::getSingleton('core/resource')->getTableName('cms/page')
27
- . '` SET '.$this->getColumnName() .' = \''.addslashes($this->getTranslate()).' \' WHERE page_id = '.$newEntityId;
28
-
29
-
30
- $writeConnection->query($query);
31
32
33
}
34
35
$this->setIsImported(1)->save();
36
37
}
38
-
39
- private function _getConnection() {
40
- return Mage::getSingleton('core/resource')->getConnection('core_write');
41
- }
42
43
}
19
->getNewEntityId();
20
21
22
+ // if ($this->getTranslate()){
23
+ //
24
+ // $writeConnection = $this->_getConnection();
25
+ //
26
+ // $query = 'UPDATE `'.Mage::getSingleton('core/resource')->getTableName('cms/page')
27
+ // . '` SET '.$this->getColumnName() .' = \''.addslashes($this->getTranslate()).' \' WHERE page_id = '.$newEntityId;
28
+ //
29
+ //
30
+ // $writeConnection->query($query);
31
+ //
32
+ //
33
+ // }
34
+ //
35
+ // $this->setIsImported(1)->save();
36
37
+ if ($this->getTranslate()){
38
39
+ $model = Mage::getModel('cms/page')->load($newEntityId);
40
+ if($model->getId()){
41
+ $model->setData($this->getColumnName(), $this->getTranslate());
42
+ $model->save();
43
+ }
44
}
45
46
$this->setIsImported(1)->save();
47
48
}
49
+ //
50
+ // private function _getConnection() {
51
+ // return Mage::getSingleton('core/resource')->getConnection('core_write');
52
+ // }
53
54
}
app/code/community/StrakerTranslations/EasyTranslationPlatform/Model/Job.php CHANGED
@@ -1,4 +1,5 @@
1
<?php
2
/**
3
* Created by PhpStorm.
4
* User: WlliamZhao
@@ -16,209 +17,257 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
16
$this->_init('strakertranslations_easytranslationplatform/job');
17
}
18
19
- protected function addProductAttributes($productAttributeIds){
20
-
21
foreach ($productAttributeIds as $productAttributeId) {
22
$this->_attributes[] =
23
Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')
24
->setJobId($this->getId())
25
- ->setAttributeId((int) $productAttributeId)
26
->save();
27
}
28
return $this;
29
}
30
31
-
32
- protected function addProductIds($productIds){
33
-
34
- $writeConnection = $this->getWriteAdapter();
35
-
36
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_product').'` (`product_id`, `job_id`) VALUES ';
37
- $queryVals = array();
38
foreach ($productIds as $productId) {
39
- $queryVals[] = '(' . (int) $productId . ', ' . $this->getId() . ')';
40
}
41
-
42
- $writeConnection->query( $query . implode(',', $queryVals));
43
-
44
return $this;
45
-
46
}
47
48
- protected function addProductTranslateOriginal($productAttributeId, $productCollection){
49
-
50
-
51
- $writeConnection = $this->getWriteAdapter();
52
-
53
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/product_translate').'` (`job_id`, `product_id`, `attribute_id`, `original`) VALUES ';
54
- $queryVals = array();
55
$productAttributeCode = Mage::getModel('eav/entity_attribute')->load($productAttributeId)->getAttributeCode();
56
foreach ($productCollection as $product) {
57
- $queryVals[] = '(' . $this->getId() . ', ' . $product->getId() . ', ' . $productAttributeId . ', \'' . addslashes($product->getData($productAttributeCode)). '\')';
58
}
59
-
60
- $writeConnection->query( $query . implode(',', $queryVals));
61
-
62
return $this;
63
}
64
65
- protected function addCategoryAttributes($categoryAttributeIds){
66
-
67
foreach ($categoryAttributeIds as $categoryAttributeId) {
68
$this->_attributes[] =
69
Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')
70
->setJobId($this->getId())
71
- ->setAttributeId((int) $categoryAttributeId)
72
->save();
73
}
74
return $this;
75
}
76
77
78
- protected function addCategoryIds($categoryIds){
79
-
80
- $writeConnection = $this->getWriteAdapter();
81
-
82
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_category').'` (`category_id`, `job_id`) VALUES ';
83
- $queryVals = array();
84
foreach ($categoryIds as $categoryId) {
85
- $queryVals[] = '(' . (int) $categoryId . ', ' . $this->getId() . ')';
86
}
87
-
88
- $writeConnection->query( $query . implode(',', $queryVals));
89
-
90
return $this;
91
-
92
}
93
94
- protected function addCategoryTranslateOriginal($categoryAttributeId, $categoryCollection){
95
-
96
-
97
- $writeConnection = $this->getWriteAdapter();
98
-
99
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/category_translate').'` (`job_id`, `category_id`, `attribute_id`, `original`) VALUES ';
100
- $queryVals = array();
101
$categoryAttributeCode = Mage::getModel('eav/entity_attribute')->load($categoryAttributeId)->getAttributeCode();
102
foreach ($categoryCollection as $category) {
103
- $queryVals[] = '(' . $this->getId() . ', ' . $category->getId() . ', ' . $categoryAttributeId . ', \'' . addslashes($category->getData($categoryAttributeCode)). '\')';
104
}
105
-
106
- $writeConnection->query( $query . implode(',', $queryVals));
107
-
108
return $this;
109
}
110
111
- protected function addCmsTranslateOriginal($Column, $cmsDataCollection, $type='page',$jobCmsIds) {
112
-
113
- $writeConnection = $this->getWriteAdapter();
114
115
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/cms_'.$type.'_translate').'` (`job_id`, `cms_'.$type.'_id`, `column_name`, `original` , `job_cms_id`) VALUES ';
116
- $queryVals = array();
117
foreach ($cmsDataCollection as $cmsData) {
118
-
119
- foreach ($jobCmsIds as $k => $v){
120
- if ($cmsData[$type.'_id'] == $v){
121
- $jobCmsId = $k;
122
break;
123
}
124
}
125
-
126
- $queryVals[] = '(' . $this->getId() . ', ' . $cmsData[$type.'_id'] . ', \'' . addslashes($Column). '\', \'' . addslashes($cmsData[$Column]).'\', ' . $jobCmsId . ')';
127
}
128
129
- $writeConnection->query( $query . implode(',', $queryVals));
130
-
131
return $this;
132
}
133
134
- public function array_to_xml( $data, &$xml_data ) {
135
- foreach( $data as $key => $value ) {
136
- if( is_array($value) ) {
137
- if( is_numeric($key) ){
138
- $key = 'item'.$key; //dealing with <0/>..<n/> issues
139
}
140
$subnode = $xml_data->addChild($key);
141
$this->array_to_xml($value, $subnode);
142
} else {
143
- $xml_data->addChild("$key",htmlspecialchars("$value"));
144
}
145
}
146
}
147
148
- protected function addAttributeTranslateOriginal($attributeData){
149
-
150
- $writeConnection = $this->getWriteAdapter();
151
152
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/straker_attribute_translate').'` (`job_id`, `attribute_id`, `original`) VALUES ';
153
- $queryVals = array();
154
155
foreach ($attributeData as $attributeId => $translate) {
156
-
157
$original = array();
158
-
159
$original['title'] = $translate['label'] ? Mage::getModel('catalog/resource_eav_attribute')->load($attributeId)->getStoreLabel($this->getSourceStore()) : '';
160
-
161
-
162
- if ($translate['option'] ){
163
$attributeOptioinCollection = Mage::getModel('eav/entity_attribute_option')
164
->getCollection()
165
->setStoreFilter($this->getSourceStore())
166
->setAttributeFilter($attributeId);
167
-
168
foreach ($attributeOptioinCollection as $attributeOptioin) {
169
- $original['option']['id_'.$attributeOptioin->getoptionId()] = $attributeOptioin->getValue();
170
}
171
}
172
-
173
$xml = new SimpleXMLElement('<attribute/>');
174
-
175
$this->array_to_xml($original, $xml);
176
-
177
-
178
- $queryVals[] = '(' . $this->getId() . ', ' . $attributeId . ', \'' . addslashes($xml->asXML()). '\')';
179
-
180
-
181
-
182
}
183
184
- $writeConnection->query( $query . implode(',', $queryVals));
185
186
return $this;
187
188
189
-
190
}
191
192
193
194
195
- protected function addAttributeIds($attributeData){
196
-
197
198
- $writeConnection = $this->getWriteAdapter();
199
200
- $query = 'INSERT INTO `'.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_attribute').'` (`attribute_id`, `translate_lable`, `translate_option`, `job_id` ) VALUES ';
201
- $queryVals = array();
202
203
foreach ($attributeData as $attributeId => $translate) {
204
-
205
- $queryVals[] = '(' . (int) $attributeId . ', '. $translate['label'] .', '. $translate['option'] .', '. $this->getId() . ')';
206
}
207
208
- $writeConnection->query( $query . implode(',', $queryVals));
209
-
210
return $this;
211
212
}
213
214
215
- public function addProducts($productAttributeIds,$productIds){
216
217
- if (!$this->getId()){
218
- if (!$this->getStoreId()){
219
Mage::throwException('Error: Missing Store Id');
220
}
221
- $this->setSourceStore(Mage::getStoreConfig('straker/general/source',$this->getStoreId()));
222
$this->save();
223
}
224
@@ -227,8 +276,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
227
$countProducts = sizeof($productIds);
228
$buffer = 1000;
229
$_productIdSet = array();
230
- for ($i = 0; $i < $countProducts; $i = $i + $buffer){
231
- $_productIdSet[] = array_slice($productIds,$i,$buffer);
232
}
233
234
foreach ($_productIdSet as $_productIds) {
@@ -245,22 +294,23 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
245
$productCollection->addAttributeToSelect($productAttributeCode);
246
}
247
248
- $productCollection->addFieldToFilter('entity_id', array('in'=> $_productIds));
249
250
- foreach ( $productAttributeIds as $productAttributeId){
251
$this->addProductTranslateOriginal($productAttributeId, $productCollection);
252
}
253
}
254
return $this;
255
}
256
257
- public function addCategories($categoryAttributeIds,$categoryIds){
258
259
- if (!$this->getId()){
260
- if (!$this->getStoreId()){
261
Mage::throwException('Error: Missing Store Id');
262
}
263
- $this->setSourceStore(Mage::getStoreConfig('straker/general/source',$this->getStoreId()));
264
$this->save();
265
}
266
@@ -269,8 +319,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
269
$countCategories = sizeof($categoryIds);
270
$buffer = 1000;
271
$_categoryIdSet = array();
272
- for ($i = 0; $i < $countCategories; $i = $i + $buffer){
273
- $_categoryIdSet[] = array_slice($categoryIds,$i,$buffer);
274
}
275
276
foreach ($_categoryIdSet as $_categoryIds) {
@@ -287,22 +337,23 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
287
$categoryCollection->addAttributeToSelect($categoryAttributeCode);
288
}
289
290
- $categoryCollection->addFieldToFilter('entity_id', array('in'=> $_categoryIds));
291
292
- foreach ( $categoryAttributeIds as $categoryAttributeId){
293
$this->addCategoryTranslateOriginal($categoryAttributeId, $categoryCollection);
294
}
295
}
296
return $this;
297
}
298
299
- public function addAttributes($attributeData){
300
301
- if (!$this->getId()){
302
- if (!$this->getStoreId()){
303
Mage::throwException('Error: Missing Store Id');
304
}
305
- $this->setSourceStore(Mage::getStoreConfig('straker/general/source',$this->getStoreId()));
306
$this->save();
307
}
308
@@ -314,228 +365,330 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
314
}
315
316
317
- public function addCmsEntities($ids, $Columns = array(), $type = 'page'){
318
319
- if (!$this->getId()){
320
- if (!$this->getStoreId()){
321
Mage::throwException('Error: Missing Store Id');
322
}
323
- $this->setSourceStore(Mage::getStoreConfig('straker/general/source',$this->getStoreId()));
324
$this->save();
325
}
326
327
foreach ($Columns as $Column) {
328
$this->_attributes[] =
329
- Mage::getModel('strakertranslations_easytranslationplatform/cms_'.$type.'_attributes')
330
- ->setJobId($this->getId())
331
- ->setColumnName($Column)
332
- ->save();
333
}
334
335
- $writeConnection = $this->getWriteAdapter();
336
-
337
- $searchQuery = 'SELECT * FROM ' .Mage::getSingleton('core/resource')->getTableName('cms/'.$type)
338
- .' WHERE '.$type.'_id IN ('.implode(',',$ids).')';
339
-
340
- $cmsDataCollection = $writeConnection->fetchAll($searchQuery);
341
-
342
- $query = 'INSERT INTO `'
343
- .Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_cms'.$type)
344
- .'` (`'.$type.'_id`, `job_id` , `origin`) VALUES ';
345
-
346
- $queryVals = array();
347
348
foreach ($cmsDataCollection as $cmsData) {
349
- $id = $cmsData[$type.'_id'];
350
-
351
- unset($cmsData[$type.'_id']);
352
-
353
-
354
- $queryVals[] = "(" . (int) $id . ", ". $this->getId() . ", '". addslashes(json_encode($cmsData)) . "')";
355
}
356
357
- $writeConnection->query( $query . implode(',', $queryVals));
358
359
- $query = 'SELECT id, '.$type.'_id FROM '.Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_cms'.$type)
360
- .' WHERE job_id = '. $this->getId();
361
362
- $jobCmsIds = $writeConnection->fetchPairs($query);
363
364
foreach ($Columns as $Column) {
365
- $this->addCmsTranslateOriginal($Column, $cmsDataCollection, $type,$jobCmsIds);
366
}
367
368
-
369
$this->_createCMSTranslateFile($type);
370
-
371
-
372
- return $this;
373
-
374
-
375
-
376
}
377
378
- protected function _createCMSTranslateFile($type) {
379
380
- $_xml = '<?xml version="1.0" encoding="utf-8"?><root>';
381
382
- $cmsTranslateCollection = Mage::getModel('strakertranslations_easytranslationplatform/cms_'.$type.'_translate')->getCollection($this->getWriteAdapter());
383
- $cmsTranslateCollection->addFieldToFilter('job_id',$this->getId());
384
385
- foreach ($cmsTranslateCollection as $cmsTranslate ){
386
387
- $_xml .= '<data name="cms_' .$type. '_' .$cmsTranslate->getCmsId().'_'.$cmsTranslate->getColumnName().'_'.'" ' ;
388
- $_xml .= 'content_context="'.$cmsTranslate->getColumnName().'" ';
389
- $_xml .= 'content_id="'. $cmsTranslate->getId() .'">';
390
- $_xml .= '<value><![CDATA['.$cmsTranslate->getOriginal().']]></value></data>';
391
- }
392
- $_xml .='</root>';
393
394
- file_put_contents(MAGENTO_ROOT.$this->_translateFilePath.'job'.$this->getId().'.xml',$_xml);
395
- $this->setSourceFile('job'.$this->getId().'.xml')->save() ;
396
397
return $this;
398
399
400
}
401
402
- protected function _createProductTranslateFile() {
403
404
- $_xml = '<?xml version="1.0" encoding="utf-8"?><root>';
405
406
$productTranslateCollection = Mage::getModel('strakertranslations_easytranslationplatform/product_translate')->getCollection($this->getWriteAdapter());
407
- $productTranslateCollection->addFieldToFilter('job_id',$this->getId());
408
409
$attributeFrontLabel = array();
410
411
- foreach ($productTranslateCollection as $productTranslate ){
412
- if (!isset($attributeFrontLabel[$productTranslate->getAttributeId()])){
413
$attributeFrontLabel[$productTranslate->getAttributeId()] =
414
Mage::getModel('eav/entity_attribute')->load($productTranslate->getAttributeId())->getFrontendLabel();
415
}
416
417
- $_xml .= '<data name="' .$this->getTypeId(). '_' . $this->getStoreId().'_'. $productTranslate->getAttributeId().'_'. $productTranslate->getProductId().'" ' ;
418
- $_xml .= 'content_context="' . $attributeFrontLabel[$productTranslate->getAttributeId()] . '" ';
419
- $_xml .= 'content_context_url="'.Mage::getStoreConfig('web/unsecure/base_link_url',$this->getStoreId()).'catalog/category/view/id/'.$productTranslate->getProductId().'" ';
420
- $_xml .= 'content_id="'. $productTranslate->getId() .'">';
421
- $_xml .= '<value><![CDATA['.$productTranslate->getOriginal().']]></value></data>';
422
}
423
- $_xml .='</root>';
424
425
- file_put_contents(MAGENTO_ROOT.$this->_translateFilePath.'job'.$this->getId().'.xml',$_xml);
426
- $this->setSourceFile('job'.$this->getId().'.xml')->save() ;
427
428
return $this;
429
}
430
431
- protected function _createCategoryTranslateFile() {
432
433
- $_xml = '<?xml version="1.0" encoding="utf-8"?><root>';
434
435
$categoryTranslateCollection = Mage::getModel('strakertranslations_easytranslationplatform/category_translate')->getCollection();
436
- $categoryTranslateCollection->addFieldToFilter('job_id',$this->getId());
437
438
$attributeFrontLabel = array();
439
440
- foreach ($categoryTranslateCollection as $categoryTranslate ){
441
- if (!isset($attributeFrontLabel[$categoryTranslate->getAttributeId()])){
442
$attributeFrontLabel[$categoryTranslate->getAttributeId()] =
443
Mage::getModel('eav/entity_attribute')->load($categoryTranslate->getAttributeId())->getFrontendLabel();
444
}
445
446
- $_xml .= '<data name="' .$this->getTypeId(). '_' . $this->getStoreId().'_'. $categoryTranslate->getAttributeId().'_'. $categoryTranslate->getCategoryId().'" ' ;
447
- $_xml .= 'content_context="' . $attributeFrontLabel[$categoryTranslate->getAttributeId()] . '" ';
448
- $_xml .= 'content_context_url="'.Mage::getStoreConfig('web/unsecure/base_link_url',$this->getStoreId()).'catalog/category/view/id/'.$categoryTranslate->getCategoryId().'" ';
449
- $_xml .= 'content_id="'. $categoryTranslate->getId() .'">';
450
- $_xml .= '<value><![CDATA['.$categoryTranslate->getOriginal().']]></value></data>';
451
}
452
- $_xml .='</root>';
453
454
- file_put_contents(Mage::getBaseDir().$this->_translateFilePath.'job'.$this->getId().'.xml',$_xml);
455
- $this->setSourceFile('job'.$this->getId().'.xml')->save() ;
456
457
return $this;
458
}
459
460
- protected function _createAttributeTranslateFile() {
461
462
- $_xml = '<?xml version="1.0" encoding="utf-8"?><root>';
463
464
$attributeTranslateCollection = Mage::getModel('strakertranslations_easytranslationplatform/attribute_translate')->getCollection();
465
- $attributeTranslateCollection->addFieldToFilter('job_id',$this->getId());
466
467
- foreach ($attributeTranslateCollection as $attributeTranslate ){
468
469
- $dataInJson = json_encode(simplexml_load_string($attributeTranslate->getOriginal()));
470
- $data = json_decode($dataInJson,true);
471
472
- foreach ($data as $k => $attribute ){
473
- if ($k == 'title' && $attribute){
474
- $_xml .= '<data name="' .$this->getTypeId(). '_' . $this->getStoreId().'_'. $attributeTranslate->getAttributeId().'" ' ;
475
- $_xml .= 'content_context="product attribute title" ';
476
- $_xml .= 'content_id="'. $attributeTranslate->getId() .'">';
477
- $_xml .= '<value><![CDATA['.$attribute.']]></value></data>';
478
}
479
480
- if ($k = 'option'){
481
foreach ($attribute as $optionId => $optionValue) {
482
- $_xml .= '<data name="' .$this->getTypeId(). '_' . $this->getStoreId().'_'. $attributeTranslate->getAttributeId().'" ' ;
483
- $_xml .= 'content_context="product attribute option" ';
484
- $_xml .= 'option_id="'. $optionId .'" ';
485
- $_xml .= 'content_id="'. $attributeTranslate->getId() .'">';
486
- $_xml .= '<value><![CDATA['.$optionValue.']]></value></data>';
487
}
488
489
}
490
491
}
492
}
493
- $_xml .='</root>';
494
-
495
- file_put_contents(Mage::getBaseDir().$this->_translateFilePath.'job'.$this->getId().'.xml',$_xml);
496
- $this->setSourceFile('job'.$this->getId().'.xml')->save() ;
497
498
return $this;
499
}
500
501
- protected function _summitJob(){
502
503
$request = array();
504
505
- if (!$this->getTitle()){
506
$store = Mage::getModel('core/store')->load($this->getStoreId());
507
- $defaultTitle = $store->getFrontendName().'_'.$store->getName().'_'.Mage::getModel('core/date')->timestamp();
508
$this->setTitle($defaultTitle);
509
}
510
$request['title'] = $this->getTitle();
511
- $request['sl'] = $this->getSl();
512
- $request['tl'] = $this->getTl();
513
-
514
- $filePath = MAGENTO_ROOT.$this->_translateFilePath.$this->getSourceFile();
515
516
- $request['source_file'] = function_exists('curl_file_create') ? curl_file_create($filePath) :'@'.$filePath;
517
- $request['callback_uri'] = Mage::getStoreConfig('web/unsecure/base_link_url',$this->getStoreId()) . 'straker/callback';
518
- $request['token'] = $this->getId();
519
520
$api = $this->_getApi();
521
$response = $api->callTranslate($request);
522
- if($response->job_key) {
523
$this->setStatusId(2)
524
->setJobKey($response->job_key)
525
->setTjNumber($response->tj_number)
526
->save();
527
$this->setLastStatus(1);
528
- }
529
- else{
530
$this->setLastStatus(0);
531
- $message = $response->magentoMessage?$response->magentoMessage:'Unknown Error.';
532
$this->setLastMessage($message);
533
}
534
return $this;
535
536
}
537
538
- public function submitProducts($productAttributeIds,$productIds){
539
540
//product
541
$this->setTypeId(1);
@@ -545,7 +698,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
545
return $this;
546
}
547
548
- public function submitCategories($categoryAttributeIds,$categoryIds){
549
550
//category
551
$this->setTypeId(3);
@@ -555,7 +709,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
555
return $this;
556
}
557
558
- public function submitAttributes($attributeData){
559
560
//category
561
$this->setTypeId(4);
@@ -565,32 +720,35 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
565
return $this;
566
}
567
568
- public function submitCmsPage($cmsIds,$columns = array('title','content')){
569
570
$this->setTypeId(5);
571
- $this->addCmsEntities($cmsIds,$columns,'page')
572
- ->_summitJob();
573
return $this;
574
}
575
576
- public function submitCmsblock($cmsIds,$columns = array('title','content')){
577
578
$this->setTypeId(6);
579
- $this->addCmsEntities($cmsIds,$columns,'block')
580
- ->_summitJob();
581
return $this;
582
}
583
584
- public function updateQuote(){
585
586
- if ($this->getJobKey()){
587
$request = array();
588
$request['job_key'] = $this->getJobKey();
589
$api = $this->_getApi();
590
$response = $api->getTranslation($request);
591
592
if ($response->job) {
593
- foreach ($response->job as $job){
594
if ($job->token == $this->getId()) {
595
$quote = $job->quotation;
596
if ($quote && $quote != $this->getQuote()) {
@@ -605,9 +763,10 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
605
606
}
607
608
- public function updateTranslation(){
609
$updateFlag = false;
610
- if ($this->getJobKey()){
611
$request = array();
612
$request['job_key'] = $this->getJobKey();
613
$api = $this->_getApi();
@@ -667,22 +826,24 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
667
}
668
return $updateFlag;
669
}
670
-
671
protected function _getApi(){
672
673
return Mage::getModel('strakertranslations_easytranslationplatform/api',array('store'=>$this->getStoreId()));
674
}
675
676
- protected function _getStatusId($statusName) {
677
678
- return Mage::getModel('strakertranslations_easytranslationplatform/job_status')->load($statusName,'status_name')->getId();
679
}
680
681
- protected function _importTranslation() {
682
683
$xml = $this->_getApi()->getTranslatedFile($this->getDownloadUrl());
684
685
- file_put_contents(Mage::getBaseDir().$this->_translateFilePath.'translated_job'.$this->getId().'.xml',$xml, LOCK_EX);
686
687
$data = simplexml_load_string($xml);
688
@@ -690,35 +851,34 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
690
691
foreach ($data->children() as $_translation) {
692
693
- $_entityTranslationId = (string) $_translation->attributes()->content_id;
694
- if ($this->_getType() == 'attribute'){
695
- if ($_translation->attributes()->content_context =="product attribute title"){
696
- $_translationValueGroup[$_entityTranslationId]['title'] = (string) $_translation->value;
697
}
698
699
- if ($_translation->attributes()->content_context =="product attribute option"){
700
- $_translationValueGroup[$_entityTranslationId]['option']['id_'. $_translation->attributes()->option_id] = (string) $_translation->value;
701
}
702
703
- }
704
- else {
705
$_translationValueGroup[$_entityTranslationId] = (string)$_translation->value;
706
}
707
708
}
709
710
- foreach ($_translationValueGroup as $content_id => $_translationValue ){
711
712
$value = $_translationValue;
713
714
- if (is_array($_translationValue)){
715
$xml = new SimpleXMLElement('<attribute/>');
716
- $this->array_to_xml($_translationValue,$xml);
717
- $value = (string) $xml->asXML();
718
}
719
720
721
- $_entityTranslation = Mage::getModel('strakertranslations_easytranslationplatform/'.$this->_getType().'_translate')->load($content_id);
722
$_entityTranslation->setTranslate($value);
723
$_entityTranslation->save();
724
$_entityTranslation->clearInstance();
@@ -728,19 +888,21 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
728
729
}
730
731
- protected function _getType(){
732
return str_replace(' ', '_', strtolower($this->getTypeName()));
733
}
734
735
- public function updatePayment(){
736
737
- if ($this->getJobKey()){
738
$request = array();
739
$request['job_key'] = $this->getJobKey();
740
$api = $this->_getApi();
741
$response = $api->getPayment($request);
742
743
- if(!empty($response) && $response->status == "Paid"){ ///////waiting for payment api
744
$this->setPaymentStatus(1)->save();
745
return true;
746
}
@@ -748,36 +910,37 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
748
return false;
749
}
750
751
- public function applyTranslation( $entityIds = array()) {
752
753
- $collection = Mage::getModel('strakertranslations_easytranslationplatform/'.$this->_getType().'_translate')->getCollection()->addFieldToFilter('job_id',$this->getId());
754
755
if ($entityIds) {
756
- $collection->addFieldToFilter($this->_getType().'_id', array('in' => $entityIds));
757
}
758
759
$updatedIds = array();
760
$writeConnection = $this->getWriteAdapter();
761
762
- if (in_array($this->_getType() , array('cms_block','cms_page'))){
763
$this->createNewCms($entityIds);
764
}
765
766
foreach ($collection as $translation) {
767
$translation->setStoreId($this->getStoreId())->importTranslation();
768
769
- $entityId= call_user_func(array($translation, 'getData'),strtolower(str_replace(' ','_',$this->getTypeName().'_id')));
770
771
- if (empty($updatedIds[$entityId])){
772
$updatedIds[$entityId] = true;
773
$prefix = Mage::getConfig()->getTablePrefix()->__toString();
774
- if (in_array($this->_getType() , array('cms_block','cms_page'))){
775
- $cmstableName = str_replace('_','',$this->_getType());
776
$cmsColumnName = str_replace('cms_', '', $this->_getType());
777
- $entityId = $translation->getData($this->_getType().'_id');
778
- $writeConnection->update($prefix.'straker_job_'.$cmstableName ,array('version' => 1), $cmsColumnName."_id = {$entityId} and job_id ={$this->getId()}" );
779
- }else{
780
- $writeConnection->update($prefix.'straker_job_'.$this->_getType() ,array('version' => 1), $this->_getType()."_id = {$entityId} and job_id ={$this->getId()}" );
781
}
782
}
783
}
@@ -785,7 +948,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
785
return true;
786
}
787
788
- protected function createNewCms($entityIds){
789
790
791
$cmsType = str_replace('cms_', '', $this->_getType());
@@ -793,12 +957,12 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
793
$cmsModelName = str_replace('_', '/', $this->_getType());
794
795
796
- $collection = Mage::getModel('strakertranslations_easytranslationplatform/job_'.$this->_getType())->getCollection();
797
798
- $collection->addFieldToFilter('job_id',$this->getId());
799
800
if ($entityIds) {
801
- $collection->addFieldToFilter($cmsType.'_id', array('in' => $entityIds));
802
}
803
804
foreach ($collection as $jobCms) {
@@ -809,13 +973,13 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
809
810
$cmsData = json_decode($jobCms->getOrigin());
811
812
- foreach ($cmsData as $k => $v){
813
- $cmsModel->setData($k,$v);
814
}
815
-
816
- $cmsModel->setStores(array())->save();
817
-
818
- $jobCms->setNewEntityId($cmsModel->getId()) ->save();
819
820
}
821
@@ -827,29 +991,30 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
827
{
828
if ($this->getStatusId() == 5) {
829
return true;
830
- } elseif($this->getStatusId() == 4) {
831
return $this->updatePublishedStatus()->getStatus() == 5;
832
- }
833
- else{
834
return false;
835
}
836
}
837
838
- protected function updatePublishedStatus(){
839
- $collection = Mage::getModel('strakertranslations_easytranslationplatform/job_'.$this->_getType())->getCollection()->addFieldToFilter('job_id',$this->getId());
840
$collection->addFieldToFilter('version',
841
array(
842
array('neq' => '1'),
843
array('null' => true)
844
)
845
);
846
- if(!$collection->getFirstItem()->getId()){
847
$this->setStatusId(5)->save();
848
}
849
return $this;
850
}
851
852
- public function submitSupport(array $data){
853
854
$res = $this->_getApi()->callSupport($data);
855
@@ -857,13 +1022,13 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
857
858
}
859
860
- public function checkAndCreateFolder(){
861
862
$ioAdapter = new Varien_Io_File();
863
try {
864
- $ioAdapter->checkAndCreateFolder(Mage::getBaseDir('var').DS.'straker');
865
- }
866
- catch (Exception $e) {
867
Mage::throwException($e->getMessage());
868
}
869
@@ -871,7 +1036,8 @@ class StrakerTranslations_EasyTranslationPlatform_Model_Job extends Mage_Core_Mo
871
872
}
873
874
- protected function getWriteAdapter(){
875
return Mage::getSingleton('core/resource')->getConnection('core_write');
876
}
877
}
1
<?php
2
+
3
/**
4
* Created by PhpStorm.
5
* User: WlliamZhao
17
$this->_init('strakertranslations_easytranslationplatform/job');
18
}
19
20
+ protected function addProductAttributes($productAttributeIds)
21
+ {
22
foreach ($productAttributeIds as $productAttributeId) {
23
$this->_attributes[] =
24
Mage::getModel('strakertranslations_easytranslationplatform/product_attributes')
25
->setJobId($this->getId())
26
+ ->setAttributeId((int)$productAttributeId)
27
->save();
28
}
29
return $this;
30
}
31
32
+ protected function addProductIds($productIds)
33
+ {
34
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/job_product');
35
foreach ($productIds as $productId) {
36
+ $model->setProductId($productId);
37
+ $model->setJobId($this->getId());
38
+ $model->save();
39
+ $model->unsetData();
40
}
41
return $this;
42
}
43
44
+ protected function addProductTranslateOriginal($productAttributeId, $productCollection)
45
+ {
46
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/product_translate');
47
$productAttributeCode = Mage::getModel('eav/entity_attribute')->load($productAttributeId)->getAttributeCode();
48
foreach ($productCollection as $product) {
49
+ $model->setJobId($this->getId());
50
+ $model->setProductId($product->getId());
51
+ $model->setAttributeId($productAttributeId);
52
+ $model->setOriginal($product->getData($productAttributeCode));
53
+ $model->save();
54
+ $model->unsetData();
55
}
56
return $this;
57
}
58
59
+ protected function addCategoryAttributes($categoryAttributeIds)
60
+ {
61
foreach ($categoryAttributeIds as $categoryAttributeId) {
62
$this->_attributes[] =
63
Mage::getModel('strakertranslations_easytranslationplatform/category_attributes')
64
->setJobId($this->getId())
65
+ ->setAttributeId((int)$categoryAttributeId)
66
->save();
67
}
68
return $this;
69
}
70
71
72
+ protected function addCategoryIds($categoryIds)
73
+ {
74
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/job_category');
75
+ //. '` (`category_id`, `job_id`) VALUES ';
76
foreach ($categoryIds as $categoryId) {
77
+ $model->setCategoryId($categoryId);
78
+ $model->setJobId($this->getId());
79
+ $model->save();
80
+ $model->unsetData();
81
}
82
return $this;
83
}
84
85
+ protected function addCategoryTranslateOriginal($categoryAttributeId, $categoryCollection)
86
+ {
87
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/category_translate');
88
$categoryAttributeCode = Mage::getModel('eav/entity_attribute')->load($categoryAttributeId)->getAttributeCode();
89
foreach ($categoryCollection as $category) {
90
+ $model->setJobId($this->getId());
91
+ $model->setCategoryId($category->getId());
92
+ $model->setAttributeId($categoryAttributeId);
93
+ $model->setOriginal($category->getData($categoryAttributeCode));
94
+ $model->save();
95
+ $model->unsetData();
96
}
97
return $this;
98
}
99
100
+ protected function addCmsTranslateOriginal($Column, $cmsDataCollection, $type = 'page', $jobCmsIds)
101
+ {
102
103
+ // $writeConnection = $this->getWriteAdapter();
104
+ //
105
+ // $query = 'INSERT INTO `' . Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/cms_' . $type . '_translate') . '` (`job_id`, `cms_' . $type . '_id`, `column_name`, `original` , `job_cms_id`) VALUES ';
106
+ // $queryVals = array();
107
+ // foreach ($cmsDataCollection as $cmsData) {
108
+ //
109
+ // foreach ($jobCmsIds as $k => $v) {
110
+ // if ($cmsData[$type . '_id'] == $v) {
111
+ // $jobCmsId = $k;
112
+ // break;
113
+ // }
114
+ // }
115
+ //
116
+ // $queryVals[] = '(' . $this->getId() . ', ' . $cmsData[$type . '_id'] . ', \'' . addslashes($Column) . '\', \'' . addslashes($cmsData[$Column]) . '\', ' . $jobCmsId . ')';
117
+ // }
118
+ //
119
+ // $writeConnection->query($query . implode(',', $queryVals));
120
+
121
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/cms_' . $type . '_translate');
122
+ //. '` (`job_id`, `cms_' . $type . '_id`, `column_name`, `original` , `job_cms_id`) VALUES ';
123
+ $jobCmsId = 0;
124
foreach ($cmsDataCollection as $cmsData) {
125
+ foreach ($jobCmsIds as $jobCmsIdArray) {
126
+ if ($cmsData[$type . '_id'] == $jobCmsIdArray[$type.'_id']) {
127
+ $jobCmsId = $jobCmsIdArray['id'];
128
break;
129
}
130
}
131
+ $model->setJobId($this->getId());
132
+ $model->setData('cms_'.$type.'_id', $cmsData[$type . '_id']);
133
+ $model->setcolumnName($Column);
134
+ $model->setOriginal($cmsData[$Column]);
135
+ $model->setJobCmsId($jobCmsId);
136
+ $model->save();
137
+ $model->unsetData();
138
}
139
140
return $this;
141
}
142
143
+ public function array_to_xml($data, &$xml_data)
144
+ {
145
+ foreach ($data as $key => $value) {
146
+ if (is_array($value)) {
147
+ if (is_numeric($key)) {
148
+ $key = 'item' . $key; //dealing with <0/>..<n/> issues
149
}
150
$subnode = $xml_data->addChild($key);
151
$this->array_to_xml($value, $subnode);
152
} else {
153
+ $xml_data->addChild("$key", htmlspecialchars("$value"));
154
}
155
}
156
}
157
158
+ protected function addAttributeTranslateOriginal($attributeData)
159
+ {
160
161
+ // $writeConnection = $this->getWriteAdapter();
162
+ //
163
+ // $query = 'INSERT INTO `' . Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/straker_attribute_translate') . '` (`job_id`, `attribute_id`, `original`) VALUES ';
164
+ // $queryVals = array();
165
+ //
166
+ // foreach ($attributeData as $attributeId => $translate) {
167
+ //
168
+ // $original = array();
169
+ //
170
+ // $original['title'] = $translate['label'] ? Mage::getModel('catalog/resource_eav_attribute')->load($attributeId)->getStoreLabel($this->getSourceStore()) : '';
171
+ //
172
+ //
173
+ // if ($translate['option']) {
174
+ // $attributeOptioinCollection = Mage::getModel('eav/entity_attribute_option')
175
+ // ->getCollection()
176
+ // ->setStoreFilter($this->getSourceStore())
177
+ // ->setAttributeFilter($attributeId);
178
+ //
179
+ // foreach ($attributeOptioinCollection as $attributeOptioin) {
180
+ // $original['option']['id_' . $attributeOptioin->getoptionId()] = $attributeOptioin->getValue();
181
+ // }
182
+ // }
183
+ //
184
+ // $xml = new SimpleXMLElement('<attribute/>');
185
+ //
186
+ // $this->array_to_xml($original, $xml);
187
+ //
188
+ //
189
+ // $queryVals[] = '(' . $this->getId() . ', ' . $attributeId . ', \'' . addslashes($xml->asXML()) . '\')';
190
+ //
191
+ //
192
+ // }
193
+ //
194
+ // $writeConnection->query($query . implode(',', $queryVals));
195
+
196
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/attribute_translate');
197
+ // . '` (`job_id`, `attribute_id`, `original`) VALUES ';
198
199
foreach ($attributeData as $attributeId => $translate) {
200
$original = array();
201
$original['title'] = $translate['label'] ? Mage::getModel('catalog/resource_eav_attribute')->load($attributeId)->getStoreLabel($this->getSourceStore()) : '';
202
+ if ($translate['option']) {
203
$attributeOptioinCollection = Mage::getModel('eav/entity_attribute_option')
204
->getCollection()
205
->setStoreFilter($this->getSourceStore())
206
->setAttributeFilter($attributeId);
207
foreach ($attributeOptioinCollection as $attributeOptioin) {
208
+ $original['option']['id_' . $attributeOptioin->getoptionId()] = $attributeOptioin->getValue();
209
}
210
}
211
$xml = new SimpleXMLElement('<attribute/>');
212
$this->array_to_xml($original, $xml);
213
+ //$queryVals[] = '(' . $this->getId() . ', ' . $attributeId . ', \'' . addslashes($xml->asXML()) . '\')';
214
+ $model->setJobId($this->getId());
215
+ $model->setAttributeId($attributeId);
216
+ $model->setOriginal($xml->asXML());
217
+ $model->save();
218
+ $model->unsetData();
219
}
220
221
+ // $writeConnection->query($query . implode(',', $queryVals));
222
223
return $this;
224
225
226
}
227
228
229
+ protected function addAttributeIds($attributeData)
230
+ {
231
232
233
+ // $writeConnection = $this->getWriteAdapter();
234
+ //
235
+ // $query = 'INSERT INTO `' . Mage::getSingleton('core/resource')->getTableName('strakertranslations_easytranslationplatform/job_attribute') . '` (`attribute_id`, `translate_label`, `translate_option`, `job_id` ) VALUES ';
236
+ // $queryVals = array();
237
+ //
238
+ // foreach ($attributeData as $attributeId => $translate) {
239
+ //
240
+ // $queryVals[] = '(' . (int)$attributeId . ', ' . $translate['label'] . ', ' . $translate['option'] . ', ' . $this->getId() . ')';
241
+ // }
242
+ //
243
+ // $writeConnection->query($query . implode(',', $queryVals));
244
245
246
+ $model = Mage::getModel('strakertranslations_easytranslationplatform/job_attribute');
247
+ // . '` (`attribute_id`, `translate_label`, `translate_option`, `job_id` ) VALUES ';
248
249
foreach ($attributeData as $attributeId => $translate) {
250
+ $model->setAttributeId($attributeId);
251
+ $model->setTranslateLabel($translate['label']);
252
+ $model->setTranslateOption($translate['option']);
253
+ $model->setJobId($this->getId());
254
+ $model->save();
255
+ $model->unsetData();
256
}
257
258
return $this;
259
260
}
261
262
263
+ public function addProducts($productAttributeIds, $productIds)
264
+ {
265
266
+ if (!$this->getId()) {
267
+ if (!$this->getStoreId()) {
268
Mage::throwException('Error: Missing Store Id');
269
}
270
+ $this->setSourceStore(Mage::getStoreConfig('straker/general/source', $this->getStoreId()));
271
$this->save();
272
}
273
276
$countProducts = sizeof($productIds);
277
$buffer = 1000;
278
$_productIdSet = array();
279
+ for ($i = 0; $i < $countProducts; $i = $i + $buffer) {
280
+ $_productIdSet[] = array_slice($productIds, $i, $buffer);
281
}
282
283
foreach ($_productIdSet as $_productIds) {
294
$productCollection->addAttributeToSelect($productAttributeCode);
295
}
296
297
+ $productCollection->addFieldToFilter('entity_id', array('in' => $_productIds));
298
299
+ foreach ($productAttributeIds as $productAttributeId) {
300
$this->addProductTranslateOriginal($productAttributeId, $productCollection);
301
}
302
}
303
return $this;
304
}
305
306
+ public function addCategories($categoryAttributeIds, $categoryIds)
307
+ {
308
309
+ if (!$this->getId()) {
310
+ if (!$this->getStoreId()) {
311