2

I have magento 1.7.0.2 and now i try to add some data to the database. But i get an error:

Notice: Undefined variable: this in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 10 Fatal error: Class 'Mage_Eav_Model_Entity_Setup' not found in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 3

Here is the part of the php file which tries to add some data to the database:

<?php
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

/**
 * Adding Different Attributes
 */

// adding attribute group
$setup->addAttributeGroup('catalog_product', 'Default', 'Video', 1000);

$setup->addAttribute('catalog_product', 'videobox', array(
    'group'         => 'Video',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'Youtube video url',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'searchable' => 0,
    'filterable' => 0,
    'comparable'    => 0,
    'visible_on_front' => 1,
    'visible_in_advanced_search'  => 0,
    'is_html_allowed_on_front' => 0,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

How can this be fixed? Thanks in advance!

UPDATE: The files works. I have added a extra piece of code to see if it works:

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run

echo "it's worked!";

?>

The error has moved a line down now.

Fatal error: Call to a member function startSetup() on a non-object in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 4
2
  • Is this the start of the file? Commented Aug 29, 2013 at 11:57
  • yes, it is. Line 3 is $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); Commented Aug 29, 2013 at 12:04

2 Answers 2

1

Try to use

$setup = Mage::getModel("eav/entity_setup", "core_setup");

instead of calling directly. That should work.

Sign up to request clarification or add additional context in comments.

Comments

0

A problem might be class is not found in mage directory just carefully include mage.php will sure solve your issue.

$mageFilename = $_SERVER['DOCUMENT_ROOT'] . '/magento/app/Mage.php';

Use this. It worked for me.

DOCUMENT_ROOT is a server variable that represents the base directory that your code is located within.

5 Comments

pls check with other function is it working ? like models/ or layout function
Hi, can you specify a line to me? I am not that into this kind of code. (i can read it, but not programm it)
This worked a bit. Now my error has moved to Fatal error: Call to a member function startSetup() on a non-object in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 4

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.