Magento eav entity setup failing - Can't create table - magento

I am trying to set up a custom entity in Magento 1.7.0.0, following alan storms article about it, but with this simple install script, it tells me that "Can't create table: eavblog_posts".
My install script is deadsimple and looks like this:
<?php
$installer = $this;
$installer->addEntityType('complexworld_eavblogpost',
Array(
'entity_model'=>'complexworld/eavblogpost',
'attribute_model'=>'',
'table'=>'complexworld/eavblogpost',
'increment_model'=>'',eav/entity_increment_numeric
'increment_per_store'=>'0'
));
$installer->createEntityTables(
$this->getTable('complexworld/eavblogpost')
);
How can i get my install script working? Is this a known magento bug?

In my case, the issue was due to a bug with the createEntityTables() method in Magento 1.7/1.12
In their answer to this bug report, the Magento team recommend commenting out line 417 from lib/Varien/Db/Adapter/Pdo/Mysql.php:
$this->_checkDdlTransaction($sql);
Instead, I would recommend following the advice in Zachary Schuessler's post and either
1) copying the createEntityTables() method to your own file (Your/Module/Model/Resource/Setup.php) and commenting out the transaction methods...
or
2) writing an abstracted query in order to keep transactions:
// Example of MySQL API
/**
* Create table array('catalog/product', 'decimal')
*/
$table = $installer->getConnection()
->newTable($installer->getTable(array('catalog/product', 'decimal')))
->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
), 'Value ID')
->addColumn(...

First of all, this line is wrong:
'increment_model'=>'',eav/entity_increment_numeric
It needs to be inside the quotes.
Failing that there are some bugs in the installer functions of the latest version.
Go into your database using phpMyAdmin or similar and check to see if any of the tables already exist. If they do, delete them. Also delete the module's record in core_resource.
Try again.
Then there's a step in here I cant remember off the top of my head (useful, I know, but I'll try and remember it tonight and edit this).
Once the tables have been created, if you look at the foreign key assignments for the type tables (int, text char etc) you'll notice that the entity_id field is looking at eav_entity.entity_id. This needs to change to your eavblogpost_entity table.
You might also notice that the eavblogpost_entity.entity_id field is INT(11), when all the foreign key references are INT(10). Change the eavblogpost_entity.entity_id field to INT(10) manually.
The only way around all of this is to override the createEntityTables() function with one that works, or create all the tables manually. Here's a good resource to help you through that parthttp://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/
Mess around with all of these as you go and I'm sure you'll stumble across the step that you have to do that I've forgotten. Sorry!

Related

Why Laravel/Eloquent single object save() updates multiple records

I'm fetching a specific record with a DB table using
$myTableObj = MyTable::where(['type' => $sometype])->first();
Getting it successfully, updating some fields and saving with
$myTableObj->save();
Surprisingly, this record is updated along with another record that also has 'type' = $sometype. What can be done to prevent this?
NOTE: originally the table did not have the auto increment id field, but I have read in forums that it may make problems in Laravel so I did add it, which did not solve the problem.
Method save() working with 'id' filed only.
You can try this
$myTableObj = MyTable::where(['type' => $sometype])->update(['something' => 'value']);
Source
I understand update() is to update, but, my answer works fine and fits good for update too. Its useful where you dont want columns to be defined once again for update, (sp when they are not fillable, its tested with primary key as condition)
$myTableObj->save(); basically its for saving new record, if you want to update that row you can update like below code:
$myTableObj=new MyTable;
$myTableObj->exists=true;
$myTableObj->type=$sometype;//this is your condition, identify
$myTableObj->update();
I think what's happening here is Laravel is saving as well as updating row.

Update, Insert, Delete records Joomla Table

I'm able to fetch information for whatever table I need the problem here is the update, insert, and delete records, is not working..
I have read the Joomla doc's but even doing the simplest update queries are not working... so here is my code:
UPDATE:
// I'm getting the data from an array
if (!empty($_POST['data'])) {
$getData = json_decode($_POST['data'], true);
}
// after this line I have a foreach for the array
// in the foreach I have a few IF's
// ether if the result from IF is True or False
// in both I have similar queries
// So let say IF return true;
// Lets prepare the Data using OBJECT's
$object = new stdClass();
$object->product_id = $v['product_id'];
$object->product_name = $v['product_name'];
$object->product_price = $v['product_price'];
$object->product_number = $v['product_number'];
$result = JFactory::getDbo()->updateObject('#__tienda_product', $object, 'product_number');
// that should Update my tables but it doesn't ... now my table has about 21 columns
// but I only need to update 4 columns base on the column product_number
You might have notice the $v['product_id'] where $v is from the foreach, the foreach and the first query are working fine, I did a few echo's before moving to the Update part just to make sure I'm getting the correct data in a format that it should be... any way... the Update part is not working... so I thought it may be because of my table I when to use one table from the regular instalation of joomla... but it still the same no result on the update...
Does any one know how to "update" a table using Joomla CMS as framework?...
Remember I want to use the updateObject() method...
Why don't I use Joomla Framework instead of the CMS's library?
Well, I can give you a few examples, let say:
a business man want a simple basic report, he doesn't care about managing the site he has people to do that, he also gets a sales report, but he doesn't trust the crew just yet and he want to able to see and compare the result, and he needs and standalone without all the fancy tools that joomla has and for that he need an standalone app that can give that kind of report... ok I might have gone a bit far, but the idea is to have basic, simple, easy to read reports and updates, and that is why I have started this project.
Again, I already went to joomla and read the docs but following their examples it just not working... now, am I have to declear all of the columns even if they don't need to be update? or am I missing an execution for the query which in joomla doesn't mention any executions when using $object() only when using regular queries SQL... the idea is to use $object() ...
Thank you for taking the time.
You have defined the updateobject as a variable, and are not calling it. try changing this:
$result = JFactory::getDbo()->updateObject('#__tienda_product', $object, 'product_number');
to this:
JFactory::getDbo()->updateObject('#__tienda_product', $object, 'product_number');
Also, on a side note, you should not use $_POST and instead should use JInput

Laravel 4 - how to use a unique validation rule / unique columns with soft deletes?

Assume, you are trying to create a new user, with a User model ( using soft deletes ) having a unique rule for it's email address, but there exists a trashed user within the database.
When trying to validate the new user's data, you will get a validation error, because of the existing email.
I made some kind of extra validation within my Controllers, but wouldn't it be nice to have it all within the Model?
Would you suggest creating a custom validation rule?
As I haven't found a clean solution now, I am interessted in how others solved this problem.
You can validate passing extra conditions:
'unique:users,deleted_at,NULL'
This sounds like an issue with your business logic rather than a technical problem.
The purpose of a soft delete is to allow for the possibility that the soft-deleted record may be restored in the future. However, if your application needs uniqueness of email (which is completely normal), you wouldn't want to both create a new user with that email address and be able to restore the old one as this would contravene the uniqueness requirement.
So if there is a soft deleted record with the email address for which you are adding as a new record, you should consider instead restoring the original record and applying the new information to it as an update, rather than trying to circumvent the uniqueness check to create a new record.
This is the best approach
'email' => 'required|email|unique:users,email,NULL,id,deleted_at,NULL',
It give you this query
select count(*) as aggregate from `users` where `email` = ? and `deleted_at` is null
Laravel offers "Additional Where Clauses".
My url validation rule (from the update model method) looks like this:
$rules['url'] = 'required|unique:pages,url,'.$page->id.',id,deleted_at,NULL';
This means that the url must be unique, must ignore the current page and ignore the pages where deleted_at id not NULL.
Hope this helps.
Your Eloquent model should have the $softDeletes property set. If so, then when you perform a WHERE check, like User::where('username', 'jimbob'), Eloquent will automatically add in the query WHERE deleted_at IS NULL... which excludes soft deleted items.
In laravel 6.2+ you can use
'email' => ['required', Rule::unique('users')->whereNull('deleted_at')]

Fatal error: Call to a member function setFinalPrice() on a non-object?

When i installed an extension named ajax pro on magento 1.702. when i add a product to cart,it shows
Fatal error: Call to a member function setFinalPrice() on a non-object in ..app\code\core\Mage\Sales\Model\Quote\Item\Abstract.php on line 73.
although i delete all this extension's files and folders. when i add a product to cart. the error still exist? how to correct it. thank you. i have clear all the cache.
I got this error after programmatically creating a quote with a different store id to the default store id.
Fix was to run this sql (after backing up all sales_flat_quote tables, of course):
DELETE FROM sales_flat_quote_item;
Note that TRUNCATE sales_flat_quote_item won't work due to referential integrity, and that the above command will remove the linked records from some of the other sales_flat_quote tables as well.
In reply to the comment - if you don't have access to the database then ask your hosting provider to give it to you (most give you some sort of access - eg phpmyadmin) you can run it as a code snippet, I guess:
<?php
// Save this in Magento root directory.
require_once( dirname(__FILE__) . ' /app/Mage.php');
umask(0);
Mage::app()->setCurrentStore(0);
$resource = Mage::getSingleton('core/resource');
$dbw = $resource->getConnection('core_write');
$query = "DELETE FROM sales_flat_quote_item;";
$dbw->query($query);
It's not a good idea to run that on a live production system - existing customers will lose all the items in their carts - though if your site is broken and you've nothing left to lose, maybe give it a go!
To backup the database without access to it, https://www.phpmyadmin.net/ or a similar tool will help there. You can also run the above query directly using that.
Delete session files from var/session thats it.
If it is throwing for all the customers then you can delete sales_flat_quote_item table. If this happens only for particular customer then do the following thing. In this case, all the quotes wont be deleted.
Get the customer id from sales_flat_quote_address(column name: customer_id) table. Here you can get the specific quote id(column name in table is quote_id) which is causing the problem.
Example: SELECT quote_id FROM sales_flat_quote_address where customer_id=23423
Now, go to sales_flat_quote_item then delete the particular records which is causing the problem.
Example: DELETE FROM sales_flat_quote_item WHERE quote_id=43535

Concrete 5 ADODB update and insert duplicate primary key

I'm creating a new package for Concrete 5 (5.4.0+). Inserting a new block works perfectly. But when I edit an existing block, it tries to INSERT again when I click 'save', instead of UPDATE.
The two fields on the database that affect this are bID and eID. Both are non-auto-incrementing INT(10) default none NOT NULL.
The values are passed in an associative array $args in the controller and I'm calling the parent save method with Parent::save($args);
Any help/input would be appreciated. PS: I have looked over this on the net and the C5 forums did turn up some stuff which I tried, mostly relating to the database fields, but I still get the above error. I don't want to overwrite the ADODB save() method if possible.
--- EDIT ---
Perhaps I'm looking at this all wrong. Let me say what I'm trying to achieve. I need the eID to remain 37 (for example) across multiple edits of the block. The bID can increment away AFAIC.
How do I get the eID to remain 37 on edit, but increment by 1 on creation of a new instance? Make sense?
A second table references the eID field, and edited instances of an entry on this table must have the same eID unless a new instance is created. Sry - clear as mud I know.
Are you saying you get a new instance of the block appearing on your page, rather than a new version of the existing one? I don't think the problem is with there being a new record inserted in your table, since new records are normally created when you edit a block. C5 keeps the older version of the block.
The custom blocks I've done have never required a call to the parent save method. You just need an edit form that collects the data and designates which database field it corresponds to, and the parent controller knows what to do with it when the form is submitted.
For example, if you have a text field in your block table called "firstname" that you are updating, you would add a line to your edit.php file like this:
<?php echo $form->text('firstname', $firstname, array('style' => 'width: 320px'));?>
My block editors contain little else than this, other than html/CSS stuff to add labels and make the form look better. The $form object takes care of everything else.
One thing that really helped me understand blocks and block controllers was to download and install the "designer content" add-on. It's free. You can use it to build some custom blocks, then look at the code it generates to perform various functions.
So I looked into the existing packages to duplicate this funcitonality and my question has evolved into this: PHP Concrete 5 Pass Variables to Add.php
Follow the rabbit ;)

Resources