Magento Forum

   
Instalare tabel in baza de date
 
ivpdesign
Jr. Member
 
Total Posts:  7
Joined:  2012-07-29
 

Buna ziua! Cum creez cu codul de mai jos 2 tabele

<?php
$installer = $this;
$installer->startSetup();
$installer->run(”
CREATE TABLE IF NOT EXISTS {$this->getTable(’sales_quote_custom’)} (
`id` int(11) unsigned NOT NULL auto_increment,
`quote_id` int(11) unsigned NOT NULL,
`key` varchar(255) NOT NULL,
`value` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS {$this->getTable(’sales_order_custom’)} (
`id` int(11) unsigned NOT NULL auto_increment,
`order_id` int(11) unsigned NOT NULL,
`key` varchar(255) NOT NULL,
`value` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
“);
$installer->endSetup();

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Salut
Trebuie sa iti pui codul intr-un fisier pentru upgrade.
Pentru asta trebuie sa creezi un modul custom.
Sa-l denumim ‘Easylife_Sales’. Poti schimba ‘Easylife’ in ce vrei tu, dar sa il schimbi peste tot in cpdul care urmeaza.
Pentru asta ai nevoie de fisierele urmatoare.
app/code/local/Easylife/Sales/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
version>0.0.1</version
        </
Easylife_Sales>
    </
modules>
    <global>
        <
resources>
            <
easylife_sales_setup>
                <
setup
                    <
module>Easylife_Sales</module>
                </
setup>
            </
easylife_sales_setup>
        </
resources>
    </global>
</
config>
app/code/local/Easylife/Sales/sql/easylife_sales_setup/mysql4-install-0.0.1.php
Aici trebuie pus codul tau:
<?php 
$installer 
$this
$installer->startSetup(); 
$installer->run(” 
CREATE TABLE 
IF NOT EXISTS {$this->getTable(’sales_quote_custom’)
`
idint(11unsigned NOT NULL auto_increment
`
quote_idint(11unsigned NOT NULL
`
keyvarchar(255NOT NULL
`
valuetext NOT NULL
PRIMARY KEY (`id`) 
ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE IF NOT EXISTS {$this->getTable(’sales_order_custom’)
`
idint(11unsigned NOT NULL auto_increment
`
order_idint(11unsigned NOT NULL
`
keyvarchar(255NOT NULL
`
valuetext NOT NULL
PRIMARY KEY (`id`) 
ENGINE=InnoDB DEFAULT CHARSET=utf8
); 
$installer->endSetup();
app/etc/modules/Easylife_Sales.xml
<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends><Mage_Sales/></depends><!-- asta e aici ca sa se incarce modulul tau dupa Mage_Sales -->
        </
Easylife_Sales>
    </
modules>
</
config>

Stergi cache-ul si dezactivezi compilarea daca e activa si pur si simplu dai un refresh in orice pagina.

Sa imi zici daca a mers.
Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ivpdesign
Jr. Member
 
Total Posts:  7
Joined:  2012-07-29
 
tzyganu - 06 December 2012 11:13 PM

Salut
Trebuie sa iti pui codul intr-un fisier pentru upgrade.
Pentru asta trebuie sa creezi un modul custom.
Sa-l denumim ‘Easylife_Sales’. Poti schimba ‘Easylife’ in ce vrei tu, dar sa il schimbi peste tot in cpdul care urmeaza.
Pentru asta ai nevoie de fisierele urmatoare.
app/code/local/Easylife/Sales/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
version>0.0.1</version
        </
Easylife_Sales>
    </
modules>
    <global>
        <
resources>
            <
easylife_sales_setup>
                <
setup
                    <
module>Easylife_Sales</module>
                </
setup>
            </
easylife_sales_setup>
        </
resources>
    </global>
</
config>
app/code/local/Easylife/Sales/sql/easylife_sales_setup/mysql4-install-0.0.1.php
Aici trebuie pus codul tau:
<?php 
$installer 
$this
$installer->startSetup(); 
$installer->run(” 
CREATE TABLE 
IF NOT EXISTS {$this->getTable(’sales_quote_custom’)
`
idint(11unsigned NOT NULL auto_increment
`
quote_idint(11unsigned NOT NULL
`
keyvarchar(255NOT NULL
`
valuetext NOT NULL
PRIMARY KEY (`id`) 
ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE IF NOT EXISTS {$this->getTable(’sales_order_custom’)
`
idint(11unsigned NOT NULL auto_increment
`
order_idint(11unsigned NOT NULL
`
keyvarchar(255NOT NULL
`
valuetext NOT NULL
PRIMARY KEY (`id`) 
ENGINE=InnoDB DEFAULT CHARSET=utf8
); 
$installer->endSetup();
app/etc/modules/Easylife_Sales.xml
<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
active>true</active>
            <
codePol>local</codePool>
            <
depends><Mage_Sales/></depends><!-- asta e aici ca sa se incarce modulul tau dupa Mage_Sales -->
        </
Easylife_Sales>
    </
modules>
</
config>

Stergi cache-ul si dezactivezi compilarea daca e activa si pur si simplu dai un refresh in orice pagina.

Sa imi zici daca a mers.
Marius.

Am creat folderele si fisierele app/code/local/Easylife/Sales/sql/easylife_sales_setup/mysql4-install-0.0.1.php
app/etc/modules/Easylife_Sales.xml
app/code/local/Easylife/Sales/etc/config.xml

am dezactivat memoria cache, am dat refresh . In baza de date nu sau creat tabelele, nu stiu de ce

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Vezi ca e o eroare in app/etc/modules/Easylife_Sales.xml:

<codePol>local</codePool>
ar trebui sa fie
<codePool>local</codePool>
Lipseste un ‘o’ la ‘codePool’.
Eu l-am scris corect in postul initial.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ivpdesign
Jr. Member
 
Total Posts:  7
Joined:  2012-07-29
 

Am facut din nou toti pasii si nu merge. Eu vreau sa adaug tabelele pentru a avea inca cateva custom fields in pagina de checkout. Fac asta dupa tutorialul de aici http://www.excellencemagentoblog.com/magento-add-custom-fields-checkout-page si m-am blocat la partea cu crearea celor 2 tabele. Nu pot sa le creez in alt mod? Multumesc! site-ul e ivptrofee.ro

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Tocmai am incercat la mine si merge.
Iata fisierele din nou. Sunt luate copy/paste din fisierele pe care tocmai le-am testat:
app\code\local\Easylife\Sales\etc\config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
version>0.0.1</version
        </
Easylife_Sales>
    </
modules>
    <global>
        <
resources>
            <
easylife_sales_setup>
                <
setup
                    <
module>Easylife_Sales</module>
                </
setup>
            </
easylife_sales_setup>
        </
resources>
    </global>
</
config>
app\code\local\Easylife\Sales\sql\easylife_sales_setup\mysql4-install-0.0.1.php
<?php 
$installer 
$this
$installer->startSetup(); 
$installer->run(
CREATE TABLE IF NOT EXISTS {
$this->getTable('sales_quote_custom')} ( 
`id` int(11) unsigned NOT NULL auto_increment, 
`quote_id` int(11) unsigned NOT NULL, 
`key` varchar(255) NOT NULL, 
`value` text NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
CREATE TABLE IF NOT EXISTS {
$this->getTable('sales_order_custom')} ( 
`id` int(11) unsigned NOT NULL auto_increment, 
`order_id` int(11) unsigned NOT NULL, 
`key` varchar(255) NOT NULL, 
`value` text NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
"
); 
$installer->endSetup();
etc\modules\Easylife_Sales.xml
<?xml version="1.0"?>
<config>
    <
modules>
        <
Easylife_Sales>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends><Mage_Sales/></depends>
        </
Easylife_Sales>
    </
modules>
</
config>

Sterge si continutul folderului var/cache chiar daca ai cache-ul dezactivat.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ivpdesign
Jr. Member
 
Total Posts:  7
Joined:  2012-07-29
 

Le-am facut inca o data dar fara succes. Eu cred ca site-ul nu ruleaza fisierul cu codu ca sa creeze tabelul in baza de date. Folosesc m-turbo management dar l-am dezactivat pe prima pagina si pe categorii. Memoria cache am sters-o, copilarea e dezactivata. Versiunea mea de Magento e 1.7.0.2.
Am incercat si tutorialul de aici dar nu am reusit inca nimic http://magentocookbook.wordpress.com/2009/06/28/magento-module-sql-setup/

Multumesc,
Alex.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

E tare ciudat.
Nu prea mai am alte idei.
Eventual ultimul lucru la care ma gandesc e sa verifici in app/etc/local.xml ca valoarea din tagul asta:

<disable_local_modules>false</disable_local_modules>
este ‘false’ (ca mai sus).
In cazul in care e ‘true’ asta dezactiveaza modulele din ‘local’.

Daca nici asta nu merge, nu prea stiu ce ii mai poti face.
Cum ziceam, la mine a functionat, ti-am dat exact codul care a functionat la mine.

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top