I have created a module which requires an additional field to be added to the sales_flat_quote table / model.
Everything appears to work fine in my install script and the new field can be seen in the database.
When retrieving a quote object and storing a value against my new field the value never gets recorded to the database. The save method doesnt product an error or exception but the value never sticks.
If it makes a difference, I am trying to save the value to the quote from an observer, during the checkout process.
Here is the code I am using in my install script:
$setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
$setup->getConnection()->addColumn(
$setup->getTable('sales_flat_quote'),
'test_attribute',
'text NULL DEFAULT NULL'
);
$setup->addAttribute('quote', 'test_attribute', array('type' => 'text', 'visible' => false));
Am I missing something obvious here?
Don't know why you create this object $setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
If you look for example into \app\code\core\Mage\Sales\sql\sales_setup\mysql4-upgrade-1.3.99-1.4.0.0.php, you will see:
/* #var $installer Mage_Sales_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();
/* Include code from mysql4-upgrade-0.9.38-0.9.39.php */
$installer->getConnection()->addColumn($installer->getTable('sales_flat_quote_item'),
'store_id', 'smallint(5) unsigned default null AFTER `product_id`');
And of course you should delete cache, change your module version in config.xml to number bigger than you have for you module in core_resource table.
Related
===
UPDATE:
I think now I am literally just trying to get a database value into my component php files, but again, there seems to be very little documentation that can give an example of a function that will return this info like there is in Wordpress.
So I have a table called membersarea_countries that will have records of differnt countries I want to store values for.
I've read about JTable and other things, but how can I simply just bring back the records from this table?
$row = JTable::getInstance('membersarea_countries', 'Table', array());
But this returns a boolean of 0.
I'd really appreciate some help if anyone can.
===
I've been following what several online guides explain, which are all pretty much the same thing, but I never seem to return the values that I'm expecting.
In Components > Members Area (my component), I have a table set up to allow me to enter a record for each country, and then store a uniqueRef, signature, and URL within that record. (for GeoIP purposes).
I've created the first record, however when I try to use the following code, which the tutorials suggest, I don't see any of my fields within this:
$app = JFactory::getApplication();
$params = $app->getParams();
$uniqueRef = $params->get('uniquereference');
$signature = $params->get('signature');
This is all I see in NetBeans:
There's nothing about $app, and no sign of the fields I've got in the Joomla backend.
I don't understand what's happening, or exactly what I should be doing here. Wordpress uses a simple get_option function. Can anyone try and help me?
Below is the link to the detailed document about JTable -
https://docs.joomla.org/Using_the_JTable_class
Firstly you need to create JTable instance using below code and also change table file name to membersareacountries.php
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_membersarea/tables');
$row = JTable::getInstance('Membersareacountries', 'Table', array());
JTable Class in this file /administrator/components/com_membersarea/tables/membersareacountries.php-
<?php
defined('_JEXEC') or die();
class TableMembersareacountries extends JTable
{
public function __construct($db)
{
parent::__construct( '#__membersarea_countrie', 'id', $db );
}
}
Then you can use load method to get any records. This accepts primary key value of that table -
$id = 1;//change id as per your record
$row->load($id);
//read data
echo $row->id;
echo $row->title;
I have created a new product attribute in Magento using the admin panel. But I can't find where to put a note for that attribute (that is the text that should display below the input field as extra info about it.)
Am I missing something, or is this not possible to implement in the admin panel?
This is an example of how a note on an attribute would look like:
I am using Magento 1.7 CE.
It's not possible through the admin Panel.
By the way, you really should add your attributes programatically. (if you database crash, your done for).
What you need is to modify the column "note" of the eav_attribute table.
You can modify it with the updateAttribute() command in an upgrade script. Example :
$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'color', 'note','my comment');
hmm this might be a bit late, but anyway, I had a similar problem today and solved it in the following intuitive way:
first my problem:
howto get in the extended-search-page the attributes in the a custom order?
for this I've found something here:
http://www.magentocommerce.com/boards/viewthread/11782/
-- they tell:
U might use the custom not used field ´note´ from the mysql table: ´eav_attribute´
therefor you can change in
app\code\core\Mage\CatalogSearch\Model\Advanced.php
the order-by
i.e.
from: ->setOrder('main_table.attribute_id', 'asc')
to: ->setOrder('main_table.note', 'asc')
But then, you still have the prob, how to edit the things properly, without edit anything directly by in a mysql-client; from now on, I have had your problem, my solution:
Model: get/set
in app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
grep: class Mage_Eav_Model_Entity_Attribute_Abstract ex
add: best after search: "n getName"
/**
* Get attribute note
*
* #return string
*/
public function getNote()
{
return $this->_getData('note');
}
/**
* Set attribute note
*
* #param string $name
* #return Mage_Eav_Model_Entity_Attribute_Abstract
*/
public function setNote($note)
{
return $this->setData('note', $note);
}
Controler: set
in app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
(o.k. this is a shortcut, I think you can add some attributes to "note_text" somewhere, but I have no plan from magento)
search for: "default value" and extend:
from:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
}
to:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
$data['note'] = $this->getRequest()->getParam('note_text');
}
View:
in ./app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php
after:
$fieldset->addField('default_value_text', 'text', array(
add:
$fieldset->addField('note_text', 'text', array(
'name' => 'note_text',
'label' => Mage::helper('eav')->__('Note Value'),
'title' => Mage::helper('eav')->__('Note Value'),
'value' => $attributeObject->getDefaultValue(),
));
finally I've initiallized the note-field in the mysql table by:
update eav_attribute set note=lpad(attribute_id,10,'0000000000') where attribute_id not in(84,100);
where attributes with the id 84 and 100 have had already some notes.
I'm using Datamapper v1.8.2 with Codeigniter v2.1.2 and have a "get" rule that doesn't seem to run on fields with NULL values. Here's the model:
class Page extends Datamapper {
public $validation = array(
'name' => array(
'rules' => array('required'),
'get_rules' => array('get_page_name')
)
);
function _get_page_name($field)
{
$this->$field = 'TESTING '.$this->id;
}
}
Example code:
$page = new Page();
foreach ($page->get() as $p) echo $p->name;
When the table field name has any non-null value including an empty string it works fine outputting something like TESTING 358, but when the value is NULL (which is the default value for this field), it outputs nothing. There is no difference using get_iterated().
I guess I could work around this by changing the default value, but I'm wondering if I'm doing something wrong or missed something in the documentation, or maybe it's a bug? Does anyone know what the issue is?
Also, if someone could point me to the proper thread in the CI forums for Datamapper 1.8.2 support that would be great, I'm trying to find it and getting lost in a maze of links to threads for old versions of DM.
You need to add the allow_null to the get_rules array to make this work. I'm not sure about the intent of the creator but this is how get_rules are implemented (however i don't see it mentioned in the docs).
I have written a custom module in Magento who add a row in the sales_flat_quote_item_option table.
I use the addOption method with an array as parameter on a quote_item object.
Then I run $quoteItem->save();
With version 1.4 of Magento, everything works like a charm. I tried to upgrade Magento to 1.7 version but my module seems to not working anymore.
After couple try to debug, I figure that the insert query in sales_flat_quote_item_option is not launch at all (according to the query log file).
So I wrote a simple query to insert data and my module is working now.
Maybe someone has been already facing this kind of issue ? I need to do it as clean as possible.
Let me share the code who fails :
public function assignDocumentToQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem, $documentid)
{
if(is_numeric($documentid) && $documentid > 0)
{
/** #var Mage_Catalog_Model_Product */
$product = $quoteItem->getProduct();
$quoteItem->addOption(array(
'product_id' => $product->getId(),
'product' => $product,
'code' => 'documentid',
'value' => $documentid));
$quoteItem->save();
return true;
}
throw new Exception(__METHOD__.' - Document id has to be a numeric value.');
}
Works fine with Magento 1.4 but not with 1.7 any idea here ?
Thank you very much !
This has been asked many times before but with no working answer.
I have multiple stores and some attributes have been overridden. I want to change these attributes to 'use default value' with a script.
Here is an image showing store views and 'use default value' checkboxes
http://dl.dropbox.com/u/3209649/storeviews-and-defaultvalues.png (not allowed to post images yet)
In app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php setData() is used with false for the second argument when 'Use Default Value' has been selected for any attributes.
/**
* Check "Use Default Value" checkboxes values
*/
if ($useDefaults = $this->getRequest()->getPost('use_default')) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
The following code attempts to set the 'name' attribute to 'use default values' for product 1 in store 3 using the same method.
require_once '../app/Mage.php';
Mage::app(3);
$product = Mage::getModel('catalog/product')->load(1);
$product->setData('name', false); # as used in ProductController.php
$product->save();
Using
$product->setData('name', 'anything');
correctly sets the 'name' attribute to 'anything' but false does not set it to 'use default value'
'Use Default Value' is not stored anywhere in the database so within the controller for the admin interface there must be another procedure that deletes the attribute row?
Related Links here -> http://pastebin.com/raw.php?i=j7fwu9H6
(not allowed to post links yet either)
This doesn't work because you need the current store being the admin store for this kind of operation.
To make a specific store view use the default value for a given attribute:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')
->load($product_id) // in your case: 1
->setStoreId($store_id) // in your case: 3
->setData($attr, false) // in your case: 'name'
->save();