0

I am working on a module for Magento 1.9.X. However, I am not able to create the database table grided_products. I have also checked core_resource, my module is updating the version also. Below are my codes

config.xml

<config>
<modules>
    <Magento_Grided>
        <version>0.2.0</version>
    </Magento_Grided>
</modules>
<global>
    <blocks>
        <grided>
            <class>Magento_Grided_Block</class>
        </grided>
    </blocks>
    <helpers>
        <grided>
            <class>Magento_Grided_Helper</class>
        </grided>
    </helpers>
    <models>
        <grided>
            <class>Magento_Grided_Model</class>
            <resourceModel>magento_grided_resource</resourceModel>
        </grided>
        <grided_resource>
            <entities>
                <product>
                    <table>grided_products</table>
                </product>
            </entities>
        </grided_resource>
    </models>
    <resources>
        <grided_setup>
            <setup>
                <module>Grided</module>
                <class>Mage_Catalog_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </grided_setup>
    </resources>
    <catalog>
        <product>
            <type>
                <grided translate="label" module="catalog">
                    <label>Custom Product by Vaibhav</label>
                    <model>grided/product_type_cp</model>
                    <is_qty>1</is_qty>
                    <index_data_retreiver>grided/catalogIndex_data_cp</index_data_retreiver>
                    <price_model>grided/product_price</price_model>
                    <composite>0</composite>
                </grided>
            </type>
        </product>        
    </catalog>
</global>

<frontend>
    <routers>
        <grided>
            <use>standard</use>
            <args>
                <module>Magento_Grided</module>
                <frontName>grided</frontName>
            </args>
        </grided>
    </routers>
</frontend>
<adminhtml>
    <layout>
        <updates>
            <grided>
                <file>gridedtab.xml</file>
            </grided>
        </updates>
    </layout>
    <events>
        <catalog_product_new_action>
            <observers>
                <customproduct_observer_catalog_product_new_action>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductNewAction</method>
                </customproduct_observer_catalog_product_new_action>
            </observers>
        </catalog_product_new_action>
        <catalog_product_edit_action>
            <observers>
                <customproduct_observer_catalog_product_edit_action>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductEditAction</method>
                </customproduct_observer_catalog_product_edit_action>
            </observers>
        </catalog_product_edit_action>          
        <catalog_product_prepare_save>
            <observers>
                <customproduct_observer_catalog_product_prepare_save>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductPrepareSave</method>
                </customproduct_observer_catalog_product_prepare_save>
            </observers>
        </catalog_product_prepare_save>
        <catalog_product_delete_before>
            <observers>
                <customproduct_observer_catalog_product_delete_before>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductDeleteBefore</method>
                </customproduct_observer_catalog_product_delete_before>
            </observers>
        </catalog_product_delete_before>            
        <catalog_product_save_after>
            <observers>
                <customproduct_observer_catalog_product_save_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductSaveAfter</method>
                </customproduct_observer_catalog_product_save_after>

                <!-- Obeserver 2nd -->
                <grided_save_product_data>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>saveProductTabData</method>
                </grided_save_product_data>
            </observers>
        </catalog_product_save_after>
        <catalog_product_status_update>
            <observers>
                <customproduct_observer_catalog_product_status_update>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductStatusUpdate</method>
                </customproduct_observer_catalog_product_status_update>
            </observers>
        </catalog_product_status_update>            




        <sales_order_item_save_after>
            <observers>
                <customproduct_observer_sales_order_item_save_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoSalesOrderItemSaveAfter</method>
                </customproduct_observer_sales_order_item_save_after>
            </observers>
        </sales_order_item_save_after>
        <sales_order_save_before>
            <observers>
                <customproduct_observer_sales_order_save_before>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoSalesOrderSaveBefore</method>
                </customproduct_observer_sales_order_save_before>
            </observers>
        </sales_order_save_before>            
        <sales_order_save_after>
            <observers>
                <customproduct_observer_sales_order_save_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoSalesOrderSaveAfter</method>
                </customproduct_observer_sales_order_save_after>
            </observers>
        </sales_order_save_after>
        <catalogrule_before_apply>
            <observers>
                <customproduct_observer_catalogrule_before_apply>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogruleBeforeApply</method>
                </customproduct_observer_catalogrule_before_apply>
            </observers>
        </catalogrule_before_apply>
        <catalogrule_after_apply>
            <observers>
                <customproduct_observer_catalogrule_after_apply>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogruleAfterApply</method>
                </customproduct_observer_catalogrule_after_apply>
            </observers>
        </catalogrule_after_apply>
        <catalog_entity_attribute_save_after>
            <observers>
                <customproduct_observer_catalog_entity_attribute_save_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogEntityAttributeSaveAfter</method>
                </customproduct_observer_catalog_entity_attribute_save_after>
            </observers>
        </catalog_entity_attribute_save_after>
        <catalog_product_delete_after_done>
            <observers>
                <customproduct_observer_catalog_product_delete_after_done>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductDeleteAfterDone</method>
                </customproduct_observer_catalog_product_delete_after_done>
            </observers>
        </catalog_product_delete_after_done>

        <customer_login>
            <observers>
                <customproduct_observer_customer_login>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCustomerLogin</method>
                </customproduct_observer_customer_login>
            </observers>
        </customer_login>
        <customer_logout>
            <observers>
                <customproduct_observer_customer_logout>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCustomerLogout</method>
                </customproduct_observer_customer_logout>
            </observers>
        </customer_logout>
        <sales_quote_save_after>
            <observers>
                <customproduct_observer_sales_quote_save_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoSalesQuoteSaveAfter</method>
                </customproduct_observer_sales_quote_save_after>
            </observers>
        </sales_quote_save_after>
        <catalog_product_collection_load_after>
            <observers>
                <customproduct_observer_catalog_product_collection_load_after>
                    <type>singleton</type>
                    <class>grided/observer</class>
                    <method>hookIntoCatalogProductCollectionLoadAfter</method>
                </customproduct_observer_catalog_product_collection_load_after>
            </observers>
        </catalog_product_collection_load_after>
    </events>
</adminhtml>

upgrade-0.1.0-0.1.2.php

<?php
$this->startSetup();

$table = new Varien_Db_Ddl_Table();

$table->setName($this->getTable('grided/product'));

$table->addColumn(
'entity_id',
Varien_Db_Ddl_Table::TYPE_INTEGER,
10,
array(
    'auto_increment' => true,
    'unsigned' => true,
    'nullable'=> false,
    'primary' => true
)
);
$table->addColumn(
'created_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'updated_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'name',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
    'nullable' => false,
)
);

$table->setOption('type', 'InnoDB');
$table->setOption('charset', 'utf8');

$this->getConnection()->createTable($table);

$this->endSetup();

Model/Product.php

<?php
class Magento_Grided_Model_Product extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {
        $this->_init('grided/product');
    }
}

Model/Resource/Product.php

<?php
class Magento_Grided_Model_Resource_Product extends Mage_Core_Model_Resource_Db_Abstract{
    protected function _construct()
    {
        $this->_init('grided/product', 'entity_id');
    }
}

Model/Resource/Product/Collection.php

<?php
 class Magento_Grided_Model_Resource_Product_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
    protected function _construct()
    {
        $this->_init('grided/product');
    }
}
3
  • change version to 0.1.0 in core_resource table.it might be because you have updated version in xml file and then reloaded page so version is updated to 0.1.2 and after that you have added upgrade script in your module. Mar 2, 2016 at 6:38
  • @MineshPatel I've deleted the version from core_resource, before that I have tried to rename, now the setup version is not coming in the core_resource table Mar 2, 2016 at 6:57
  • check for log and check your xml is correct Mar 2, 2016 at 7:00

2 Answers 2

0

Make sure your version on config.xml to be 0.1.2. Another thing I would like to change there is the models in config.xml. Can you try to change like this:

<models>
        <grided>
            <class>Magento_Grided_Model</class>
            <resourceModel>magento_grided_resource</resourceModel>
        </grided>
        <magento_grided_resource>
            <entities>
                <product>
                    <table>grided_products</table>
                </product>
            </entities>
        </magento_grided_resource>
    </models>

Let me know if this can help you. Thanks!!

1
  • No, it doesn't work out. Mar 2, 2016 at 9:38
0

I have solved the problem by changing below code in the installation script.

$installer = new Mage_Catalog_Model_Resource_Setup();

$installer->startSetup();

Thanks for the contribution guys :-)

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.