Untested Magento Code To Makesure All Products in the database have a Tax attribute set.
Last active
August 29, 2015 14:04
-
-
Save btray77/d37fc77bc22b397b03b8 to your computer and use it in GitHub Desktop.
Magento CRON set Tax Class ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- html/app/code/local/Yourname/Tax/etc/config.xml --> | |
<config> | |
<modules> | |
<Yourname_Tax> | |
<version>0.1.1</version> | |
</Yourname_Tax> | |
</modules> | |
<!-- --> | |
<crontab> | |
<jobs> | |
<Yourname_Tax> | |
<schedule> | |
<cron_expr>*/05 * * * *</cron_expr> <!-- Every X Minutes Update As Needed--> | |
</schedule> | |
<run> | |
<model>Yourname_Tax/observer::updateTaxRates</model> | |
</run> | |
</Yourname_Tax> | |
</jobs> | |
</crontab> | |
<!-- --> | |
</config> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/code/local/Yourname/Tax/Model/Observer.php | |
class YourName_Tax_Model_Observer { | |
public function updateTaxRates(){ | |
$productCollection = Mage::getModel('catalog/product')->getCollection() | |
->addAttributeToSelect('tax_class_id'); | |
foreach ($productCollection as $product) { | |
$taxClassId = $product->getTaxClassId(); | |
if (($taxClassId != '1')) { | |
//You can change the logic here | |
$product->setData('tax_class_id', $store_id)->getResource()->saveAttribute($product, 'tax_class_id'); | |
usleep(20000);//0.02 seconds to keep database from being locked | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment