imc / Interactive Magento Console (Developer Guide) verwenden

24.07.2014 | Magento

Let's experiment now by instantiating a product object and setting some of itsproperties by following these steps:

1. Start the Magento interactive console running under your Magento staginginstallation root:

php shell/imc.php

2. Our first step is going to create a new product object instance by typing:

magento> $product = Mage::getModel('catalog/product');

3. We can confirm whether this is a blank instance of the product classby running:

magento> echo get_class($product);

4. We should see the following as a successful output:

magento> Magento_Catalog_Model_Product

5. If we want to know more about the class methods, we can run the followingcommand line:

magento> print_r(get_class_methods($product));

This will return an array with all the available methods inside the class. Let's try torun the following snippet of code and modify a product price and name:

$product = Mage::getModel('catalog/product')->load(2);
= $product->getName() . '-TEST';
= $product->getPrice();
$product->setPrice($price + 15);

On the first line of code, we are instantiating a specific object, then we are proceedingto retrieve the name attribute from the object. Next, we are setting the price andname, and finally are saving the object.