Skip to content

Commit

Permalink
finished translation routine for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrizio Balliano committed Jul 29, 2015
1 parent 5ae534e commit e130391
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions shell/fballiano_full_catalog_translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,22 @@ public function run()

public function translateCategories($store_id_dest)
{
$appEmulation = Mage::getSingleton("core/app_emulation");
$attribute_id = Mage::getModel("catalog/entity_attribute")->loadByCode(Mage_Catalog_Model_Category::ENTITY, "fb_translate")->getId();
$table_name = Mage::getSingleton("core/resource")->getTableName("catalog_category_entity_int");
$categories = Mage::getSingleton("core/resource")->getConnection("core_read")->fetchCol("SELECT entity_id FROM {$table_name} WHERE attribute_id={$attribute_id} AND store_id={$store_id_dest} AND value=1");

$category = Mage::getModel("catalog/category");
foreach ($categories as $category_id) {
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($this->store_source);
$category = Mage::getModel("catalog/category");
$category->load($category_id);
$row = $category->getData();
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

echo "Translating category {$row["entity_id"]} from {$this->language_source} to {$this->language_dest}... ";
if ($this->debug_mode) echo "\n";
$translated_row = array();
$translated_row["store"] = (string)$this->store_dest;
$translated_row["sku"] = (string)$row["sku"];
$translated_row["fb_translate"] = "0"; //leave it as string otherwise magmi won't save it
$translated_row["fb_translate"] = 0;
foreach ($this->category_attributes_to_translate as $attribute) {
if (strlen($row[$attribute])) {
$translated_row[$attribute] = $this->translateString($row[$attribute]);
Expand All @@ -157,7 +159,12 @@ public function translateCategories($store_id_dest)
}
}
if (!$this->dry_run) {

$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($this->store_dest);
$category = Mage::getModel("catalog/category");
$category->load($category_id);
$category->addData($translated_row);
$category->save();
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
}
echo "OK\n";
}
Expand Down

0 comments on commit e130391

Please sign in to comment.