Pro100Tom Pro100Tom - 1 year ago 123
Javascript Question

Which file should I use when assigning products to a category in Magento programatically?

I am new to Magento. I have created a category in the back end of Magento. There are quite few threads about how to assign a product to a category, however I don't understand which file should I use to use that code:

If I understand correctly, the page is generated automatically by Magento, when you create a category and assign products to it. I know there is a
file which is a template of how the webpage should look like. Thank you in advance, guys. Will be waiting for your respond.

Answer Source

Code examples like that is for developers (which I'm kind of guessing you're primarily not) to put into their own modules, maybe as an observer running on the product save event.

For you I would instead recommend testing out snippets like that in small freestanding files in your magento-folder. At least until you know how to make a proper module this is the easiest way to run some custom code, that perhaps only needs to run once.

Create file triggerCustomAction.php in your Magento root directory, making it accessible from to run it once.

Use this as a starting point, with code you need to run at the bottom of the file:


require 'app/Mage.php';
if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";

ini_set('display_errors', 1);

// this can be changed from to any store ID number like this:
// Mage::app()->setCurrentStore(xx);

//enter your code to run below here:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download