1

I'm trying code like tutorial

http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-6.html

But when i add code create table into setup.php file i have an error .Please help me create table like tutorial . Thanks for your help .

My error:

Fatal error: Call to undefined method Varien_Autoload::startSetup() in C:\xampp\htdocs\magento\app\code\local\Magentotutorial\Weblog\Model\Resource\Setup.php on line 3

config.xml

<?xml version="1.0"?>
<config>
    <frontend>
        <routers>
            <weblog>
                <use>standard</use>
                <args>
                    <module>Magentotutorial_Weblog</module>
                    <frontName>weblog</frontName>
                </args>
            </weblog>
        </routers>
    </frontend>
    <global>
        <models>
            <weblog>
                <class>Magentotutorial_Weblog_Model</class>
            </weblog>
            <weblog_resource>
                <class>Magentotutorial_Weblog_Model_Resource</class>
                <entities>
                    <blogpost>
                        <table>blog_posts</table>
                    </blogpost>
                </entities>
            </weblog_resource>
        </models>

        <resources>
             <weblog_setup>
                   <setup>
                         <module>Magentotutorial_Weblog</module>
                         <class>Magentotutorial_Weblog_Model_Resource_Setup</class>
                   </setup>
              </weblog_setup>
        </resources>

    </global>
</config>

Setup.php

<?php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$installer->getTable('weblog/blogpost')}` (
  `blogpost_id` int(11) NOT NULL auto_increment,
  `title` text,
  `post` text,
  `date` datetime default NULL,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`blogpost_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `{$installer->getTable('weblog/blogpost')}` VALUES (1,'My New Title','This is a blog post','2009-07-01 00:00:00','2009-07-02 23:12:30');
 ");

  $installer->endSetup();
  class Magentotutorial_Weblog_Model_Resource_Setup extends    Mage_Core_Model_Resource_Setup {
  }
2
  • Did you check core_resource table and deleted Resource Versions? Commented Jul 27, 2015 at 6:02
  • Thank for your help . :) . So why need setup.php file Commented Jul 27, 2015 at 7:19

2 Answers 2

1

Contents of your setup.php should be

 class Magentotutorial_Weblog_Model_Resource_Setup extends    Mage_Core_Model_Resource_Setup {
  }

in your mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$installer->getTable('weblog/blogpost')}` (
  `blogpost_id` int(11) NOT NULL auto_increment,
  `title` text,
  `post` text,
  `date` datetime default NULL,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`blogpost_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `{$installer->getTable('weblog/blogpost')}` VALUES (1,'My New Title','This is a blog post','2009-07-01 00:00:00','2009-07-02 23:12:30');
 ");

  $installer->endSetup();

Currently it looks you've combined both of them :)

2
  • I did exactly what you do but error . But when i copy your code and reload page , no error . Anyway thank for your help . :) . So why need setup.php file Commented Jul 27, 2015 at 7:17
  • In your config file, you have defined class Magentotutorial_Weblog_Model_Resource_Setup, so your app/code/local/Magentotutorial/Weblog/Model/Resource/Setup.php is called.. in setup.php file, you've extended Mage_Core_Model_Resource_Setup, which contains definition for startSetup() and all other functions. Commented Jul 27, 2015 at 8:07
0

This is an option to the versions 1.9.*

https://github.com/aligent/Magento_SetStartOrderNumber

Sistem->configuration->sales->set starting order number -> padding

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.