Skip to content

Commit

Permalink
attributes to translate is now a multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Jun 13, 2014
1 parent 02d5102 commit 9899e15
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* FBalliano
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this Module to
* newer versions in the future.
*
* @category FBalliano
* @package FBalliano_FullCatalogTranslate
* @copyright Copyright (c) 2014 Fabrizio Balliano (http://fabrizioballiano.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Fballiano_FullCatalogTranslate_Model_TranslatableAttributes
{
public function toOptionArray()
{
$entityTypeId = Mage::getModel('eav/entity')
->setType(Mage_Catalog_Model_Product::ENTITY)
->getTypeId();

$attributes = Mage::getModel("catalog/entity_attribute")->getCollection()
->addFieldToFilter("entity_type_id", $entityTypeId)
->addFieldToFilter("backend_type", array("in" => array("varchar", "text", "textarea")))
->addFieldToFilter("frontend_input", array("in" => array("text", "textarea")))
->addFieldToFilter("attribute_code", array("nin" => array("custom_layout_update", "recurring_profile")))
->setOrder("attribute_code", "ASC");

$toreturn = array();
foreach ($attributes as $attribute) {
$toreturn[] = array(
"value" => $attribute["attribute_code"],
"label" => ucfirst(str_replace("_", " ", $attribute["attribute_code"]))
);
}

return $toreturn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Fballiano_FullCatalogTranslate>
<version>0.2.0</version>
<version>0.3.0</version>
</Fballiano_FullCatalogTranslate>
</modules>
<global>
Expand All @@ -11,6 +11,11 @@
<class>Fballiano_FullCatalogTranslate_Helper</class>
</fballiano_fullcatalogtranslate>
</helpers>
<models>
<fballiano_fullcatalogtranslate>
<class>Fballiano_FullCatalogTranslate_Model</class>
</fballiano_fullcatalogtranslate>
</models>
<resources>
<fballiano_fullcatalogtranslate_setup>
<setup>
Expand All @@ -23,7 +28,7 @@
<default>
<fballiano_full_catalog_translate>
<general>
<attributes_to_translate>name, short_description, description, meta_title, meta_keyword, meta_description</attributes_to_translate>
<attributes_to_translate>name,short_description,description,meta_title,meta_keyword,meta_description</attributes_to_translate>
</general>
</fballiano_full_catalog_translate>
</default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<comment>Comma separated list of attribute codes, only these attributes will be translated.</comment>
<frontend_type>multiselect</frontend_type>
<source_model>fballiano_fullcatalogtranslate/translatableAttributes</source_model>
<comment>Only these attributes will be translated.</comment>
</attributes_to_translate>
</fields>
</general>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* FBalliano
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this Module to
* newer versions in the future.
*
* @category FBalliano
* @package FBalliano_FullCatalogTranslate
* @copyright Copyright (c) 2014 Fabrizio Balliano (http://fabrizioballiano.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();

$db = Mage::getSingleton('core/resource')->getConnection("core_write");
$config_table_name = Mage::getSingleton('core/resource')->getTableName("core_config_data");
$configs = $db->fetchAll("SELECT * FROM $config_table_name WHERE path='fballiano_full_catalog_translate/general/attributes_to_translate'");
foreach ($configs as $config) {
$newvalues = array();
$values = explode(",", $config["value"]);
foreach ($values as $value) {
$value = trim($value);
if (strlen($value)) $newvalues[] = $value;
}
$newvalues = implode(",", $newvalues);
$db->update($config_table_name, array("value" => $newvalues), "config_id={$config["config_id"]}");
}

$installer->endSetup();

0 comments on commit 9899e15

Please sign in to comment.