install sql not work in table Mage_Sales_Model_Resource_Setup - sql

My script runs perfect but dont save the new attribute in database.... why? thanks.
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Itep_Incomm>
<version>0.1.0</version>
</Itep_Incomm>
</modules>
<global>
<models>
<incomm>
<class>Itep_Incomm_Model</class>
<resourceModel>incomm_mysql4</resourceModel>
</incomm>
</models>
<catalog>
<product>
<type>
<incomm_virtual translate="label" module="incomm">
<label>Incomm Virtual</label>
<model>incomm/product_virtual</model>
<price_model>incomm/product_price</price_model>
<is_qty>1</is_qty>
</incomm_virtual>
</type>
</product>
</catalog>
<resources>
<incomm_setup>
<setup>
<module>Itep_Incomm</module>
<class>Itep_Incomm_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</incomm_setup>
<incomm_write>
<connection>
<use>core_write</use>
</connection>
</incomm_write>
<incomm_read>
<connection>
<use>core_read</use>
</connection>
</incomm_read>
</resources>
</global>
</config>
Script install in folder sql/incomm_setup/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
//incomm_request_active_code att order
$installer->addAttribute('order_item','incomm_request_active_code',
array(
'type' => 'text',
'grid' => false
)
);
$installer->endSetup();
And the model/resource/eav/mysql4/setup.php
<?php
class Itep_Incomm_Model_Resource_Eav_Mysql4_Setup extends Mage_Sales_Model_Resource_Setup
{
}
When i run the script, and go to search in database, i cant find the new attribute in table Mage_Sales_Model_Resource_Setup, but the script shows in core_resouce, why my code is not saving? thanks

Related

Base table or view not found while creating magento install script

Here are all my files.
app/code/local/Vlabs/Productquery/sql/productquery_setup/resource-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
-- DROP TABLE IF EXISTS {$this->getTable('Vlabs_queryBox')};
CREATE TABLE {$this->getTable('Vlabs_queryBox')} (
`id` int(11) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL default,
`email` varchar(255),
`query` varchar(255),
`product_name` varchar(255),
`sku` varchar(255),
`answer` varchar(255),
`status` varchar(255),
`date` date NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();
app/code/local/Vlabs/Productquery/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Vlabs_Productquery>
<version>0.1.0</version>
</Vlabs_Productquery>
</modules>
<frontend>
<routers>
<productquery>
<use>standard</use>
<args>
<module>Vlabs_Productquery</module>
<frontName>productquery</frontName>
</args>
</productquery>
</routers>
<layout>
<updates>
<productquery module="Vlabs_Productquery">
<file>productquery.xml</file>
</productquery>
</updates>
</layout>
</frontend>
<global>
<blocks>
<productquery>
<class>Vlabs_Productquery_Block</class>
</productquery>
</blocks>
<models>
<productquery>
<class>Vlabs_Productquery_Model</class>
<resourceModel>productquery_Resource</resourceModel>
</productquery>
<productquery_Resource>
<class>Vlabs_Productquery_Model_Resource</class>
<entities>
<querybox>
<table>Vlabs_queryBox</table>
</querybox>
</entities>
</productquery_Resource>
</models>
<helpers>
<productquery>
<class>Vlabs_Productquery_Helper</class>
</productquery>
</helpers>
<resources>
<form_setup>
<setup>
<module>Vlabs_Productquery</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</form_setup>
<form_write>
<connection>
<use>core_write</use>
</connection>
</form_write>
<form_read>
<connection>
<use>core_read</use>
</connection>
</form_read>
</resources>
<template>
<email>
<vlabs_query_email_template translate="label">
<label>Recurring order email</label>
<file>vlabs_querybox_email.html</file>
<type>html</type>
</vlabs_query_email_template>
</email>
</template>
</global>
<!-- <default>
<productquery>
<settings>
<enable>1</enable>
</settings>
</productquery>
</default> -->
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<Vlabs_Productquery before="Mage_Adminhtml">Vlabs_Productquery_Adminhtml</Vlabs_Productquery>
</modules>
<frontname>productquery</frontname>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<productquery>
<file>productquery.xml</file>
</productquery>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/Vlabs/Productquery/Model/Resource/Querybox/Setup.php
<?php
class Vlabs_Productquery_Model_Resource_Querybox_Setup extends Mage_Core_Model_Resource_Setup {
}
Error
a:5:{i:0;s:179:"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento_mirror_new.Vlabs_queryBox' doesn't exist, query was: SELECT `main_table`.* FROM `Vlabs_queryBox` AS `main_table`";i:1;s:5763:"#0 /var/www/html/magento-mirror-new/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
I am working on making an extension.. But table is not created in database. But query is working when run this query direct in mysql. How can I resolve this problem?
It seems like you have installed your module and later you changed the database name.
Go to core_resource table and try to delete this entry "form_setup". Then clear cache and try again. I hope this will work.

Override magento model files getting Fatal error: Call to undefined method

I need to edit the below file
/var/www/magento1.9/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Urlkey.php
i dont want to edit the core file
for which i have done this so far
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_Coreextended>
<version>0.1.0</version>
</Inchoo_Coreextended>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product>Inchoo_Coreextended_Model_Product_Attribute_Backend_Urlkey</product>
</rewrite>
</catalog>
</models>
</global>
</config>
i have created the folowing directory from where i like to extend the file
/var/www/magento1.9/app/code/local/Inchoo/Coreextended/Model/Product/Attribute/Backend/Urlkey.php
and file is as
class Inchoo_Coreextended_Model_Product_Attribute_Backend_Urlkey extends Mage_Catalog_Model_Attribute_Backend_Urlkey_Abstract
{
}
but when I am going to catalog pages i get following error
Fatal error: Call to undefined method Inchoo_Coreextended_Model_Product_Attribute_Backend_Urlkey::setStoreId() in /var/www/magento1.9/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php on line 66
please suggest where i am doing mistake
change your config.xml code
from
<global>
<models>
<catalog>
<rewrite>
<product>Inchoo_Coreextended_Model_Product_Attribute_Backend_Urlkey</product>
</rewrite>
</catalog>
</models>
</global>
to
<global>
<models>
<catalog>
<rewrite>
<product_attribute_backend_urlkey>Inchoo_Coreextended_Model_Product_Attribute_Backend_Urlkey</product_attribute_backend_urlkey>
</rewrite>
</catalog>
</models>
</global>

setup installer script in magento module

Hi i am developing a little magento module.
below is my directory structure of module
app/code/local/Xyz/Total
/var/www/magext/app/code/local/Xyz/Total/Block/Prototal.php
/var/www/magext/app/code/local/Xyz/Total/controllers/IndexController.php
/var/www/magext/app/code/local/Xyz/Total/etc/config.xml
/var/www/magext/app/code/local/Xyz/Total/Model/Price/Observer.php
below is my config file code
<?xml version="1.0"?>
<config>
<global>
<blocks>
<total>
<class>Xyz_Total_Block</class>
</total>
</blocks>
<models>
<xyztotal>
<class>Xyz_Total_Model</class>
</xyztotal>
</models>
<events>
<sales_order_place_after>
<observers>
<xyz_total_price_observer>
<type>singleton</type>
<class>Xyz_Total_Model_Price_Observer</class>
<method>apply_discount_percent</method>
</xyz_total_price_observer>
</observers>
</sales_order_place_after>
</events>
</global>
<frontend>
<routers>
<total>
<use>standard</use>
<args>
<module>Xyz_Total</module>
<frontName>newcatalog</frontName>
</args>
</total>
</routers>
<layout>
<updates>
<total>
<file>total.xml</file>
</total>
</updates>
</layout>
</frontend>
</config>
now what i need to install a product attribute through my module
.But i cant understand understand where should i put my installer
script and how to modify config file.
please suggest.
I saw your config.xml i am not able to find xml vesrion.
So you need to give xml version like below example:
<config>
<modules>
<Xyz_Total>
<version>0.1.0</version> <!-- Version of module -->
</Xyz_Total>
</modules>
</config>
Now create the file app/code/local/Xyz/Total/sql/total_setup/mysql4-install-0.1.0.ph‌​p
After that reinstall the module And check it.
You also have to add below code in config.xml under config tag.
<global>
<resources> <!-- These are resource setting giving access to module, read/write permission on database -->
<total_setup>
<setup>
<module>Xyz_Total</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</total_setup>
<total_write>
<connection>
<use>core_write</use>
</connection>
</total_write>
<total_read>
<connection>
<use>core_read</use>
</connection>
</total_read>
</resources>
</global>
After that reinstall module.
Take a look # Adding custom product attributes in Magento using setup script
<modules>
<Xyz_Total>
<version>0.1.0</version>
</Xyz_Total>
</modules>
<global>
....
<models>
<xyztotal>
<class>Xyz_Total_Model</class>
<resourceModel>total_setup</resourceModel>
</xyztotal>
</models>
<resources>
<catalog_setup>
<setup>
<module>Mage_Catalog</module>
<class>Mage_Catalog_Model_Resource_Setup</class><!-- that line !-->
</setup>
</catalog_setup>
</resources>
...
In
app/code/local/Xyz/Total/sql/total_setup/mysql4-install-0.1.0.ph‌​p
$installer->addAttribute('catalog_product', 'offer_type', array(
'backend' => '',
...
));

magento 1.7 add attributegroup

I need to add an attributegroup called Videos in the database using an install script.
these are my files:
app/code/local/Company/ProductVideo/etc/config.xml
<resources>
<attributegroup_setup>
<setup>
<module>Company_ProductVideo</module>
<class>Company_ProductVideo_Model_Entity_Setup</class>
</setup>
</attributegroup_setup>
</resources>
</global>
app/code/local/Company/ProductVideo/Model/Entity/Setup.php
<?php
class Company_ProductVideo_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup{
}
?>
app/code/local/Company/sql/attributegroup_setup/msql4-install-1.7.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttributeGroup('catalog_product', 'Default','Videos', 40);
$installer->endSetup();
?>
My module is also registered in app/code/etc/modules/Company_ProductVideo.xml
<config>
<modules>
<Company_ProductVideo>
<active>true</active>
<codePool>local</codePool>
</Company_ProductVideo>
</modules>
</config>
But this is not working, any help is welcome!!
I have already solved it, the problem was the name of the folder under the sql folder.
the convention is to name it like this: mysql4-install-'version'.

magento event observer (magento1.7)

i am trying to implement an simple observer in my module (app/code/local/Foo/Bar).
My objective is to set the product names to '[product name] is cool' when a product is loaded in the frontend.
These are my files:
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
</global>
<frontend>
<events>
<catalog_product_load_after>
<observers>
<foo_bar>
<type>model</type>
<class>foo_bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
</observers>
</catalog_product_load_after>
</events>
</frontend>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer{
public function catalogProductLoadAfter(Varien_Event_Observer $observer)
{
$product = $observer ->getProduct();
$product ->setName($product.getName().' '.'is cool');
}
}
?>
And i have also configured the module in app/etc/modules/Foo_Bar.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
But it doenst work, does anyone have any suggestion?
You only need to module name for the model:
<foo_bar>
<type>model</type>
<class>bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
you don't need to specify Foo_Bar
also have you an error in your PHP
$product ->setName($product.getName().' '.'is cool');
should be
$product->setName($product->getName().' '.'is cool');