1

Since couple of weeks I'm trying to understand Magento, it's structure, mechanisms and I'm stuck on scripts creating for example additional columns in tables. In my config.xml script I have:

<?xml version="1.0"?>

<config >
< modules >
    < Inchoo_Orders >
        <version>0.0.0.3< /version>
    < /Inchoo_Orders>
< /modules>
<global>
    <models>
        <inchoo_orders>
            <class>Inchoo_Orders_Model</class>
enter preformatted text here          
  <resourceModel>inchoo_orders_resource</resourceModel>
        </inchoo_orders>
    </models>
    <resources>
        <inchoo_orders_setup>
            <setup>
                <module>Inchoo_Orders</module>
                <class>Inchoo_Orders_Model_Mysql4_Setup</class>
            </setup>
        </inchoo_orders_setup>
    </resources>
   ......

My Sql script name is: mysql4-upgrade-0.0.0.2-0.0.0.3.php

But it won't update table. What I'm doing wrong ? Getting error:

Fatal error: Class 'Inchoo_Orders_Model_Mysql4_Setup' not found in /home/.../app/code/core/Mage/Core/Model/Resource/Setup.php on line 234

If I change class to Mage_Core_Model_Resource_Setup not giving me any errors but also I can't see it work.

5
  • Please post the file path to Inchoo_Orders_Model_Mysql4_Setup and also the contents your upgrade script. Aug 28, 2016 at 1:38
  • 1
    Find in core_resource table your module, delete it, again refresh page again. Aug 28, 2016 at 1:43
  • @KhoaTruongDinh while that is also good advice, his error is stating that the class is not found Aug 28, 2016 at 1:49
  • @Shawn If I change class to Mage_Core_Model_Resource_Setup not giving me any errors but also I can't see it work.. So, I think we need to remove the module and refresh page. Aug 28, 2016 at 1:52
  • 1
    Good point. I upvoted you. Aug 28, 2016 at 1:53

1 Answer 1

1

Mysql4 is actually deprecated. However, if your Mysql4_Setup file lives within the resource directory, you will need to change the class name to Inchoo_Orders_Model_Resource_Mysql4_Setup.

If you are just trying to update a table and not much else, you should be able to just change

<class>Inchoo_Orders_Model_Mysql4_Setup</class>

to

<class>Mage_Core_Model_Resource_Setup</class>

If you need some sort of custom functionality that will live in your own Setup class, create this file.

<?php

class Inchoo_Orders_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
{
   //whatever needs to go in here
} 

And remember to add this to your config.xml file:

<class>Inchoo_Orders_Model_Resource_Setup</class>

If you need instruction on how to actually update the table itself, let me know.


Based on our continued discussion in the comments, it has been determined that all you really want to do here is add an attribute programatically.

First things first, you do not need your install script should be an instance of Mage_Catalog_Model_Resource_Setup

<?php

/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = $this;

$installer->startSetup();

$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'offer_status', array(
    'type'         => 'int',
    'label'        => 'Offer Status',
    'input'        => 'select',
    'global'       => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'source'       => 'inchoo_orders/catalog_product_attribute_source_offer_status',
    'backend'      => '',
    'visible'      => true,
    'required'     => false,
    'user_defined' => false,
    'default'      => '',
    'group'        => "General Information"
));

Then you need to create a source model for your attribute.

<?php

class Inchoo_Orders_Model_Catalog_Product_Attribute_Source_Offer_Status
{
    /**
     * Options getter
     *
     * @return array
     */
    public function toOptionArray()
    {
        return array(
            array('value' => 0, 'label' => Mage::helper('core')->__('Auto')),
            array('value' => 1, 'label' => Mage::helper('core')->__('Enabled')),
            array('value' => 2, 'label' => Mage::helper('core')->__('Disabled')),
        );
    }

    /**
     * Get options in "key-value" format
     *
     * @return array
     */
    public function toArray()
    {
        return array(
            0 => Mage::helper('core')->__('Auto'),
            1 => Mage::helper('core')->__('Enabled'),
            2 => Mage::helper('core')->__('Disabled'),
        );
    }
}
32
  • Hi Shawn, no, I do not need more than just one column into the table.
    – Rob D. A.
    Aug 28, 2016 at 14:43
  • I can't make it work :( don't know why, removed from core_resources inchoo_orders_setup and it still won't add column. Apparently I missed something .... will work on it ;)
    – Rob D. A.
    Aug 29, 2016 at 8:47
  • Please post the contents of your install script Aug 29, 2016 at 14:57
  • <?php // Add an extra column to the eav/catalog_products table: $installer = $this; $connection = $installer->getConnection(); $installer->startSetup(); $installer->getConnection() ->addColumn($installer->getTable('eav/catalog_products'), 'offer_status', array( 'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR, 'nullable' => false, 'default' => '0', 'comment' => 'Offer status' ) ); $installer->endSetup();
    – Rob D. A.
    Aug 29, 2016 at 16:32
  • @RobertA. in looking at what you are doing here, I am wondering if you can tell me more about what you are hoping to accomplish. The reason I ask is that you want to add a column 'offer_status' to every attribute, regardless of whether it is a product attribute, category attribute, customer attribute, etc. It doesn't seem to make sense. I am hoping to get you going in the right direction. Are you trying to create an attribute or do you have a valid reason to add Offer Status to every attribute in the system? Aug 29, 2016 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.