I added a column in table g2_CheckoutItem(name: g2_beschreibung). This column is used when a user gives some notes to a picture (I added also an input-field for that where the user selects the quantity). The inputs are saved in the session, but is not saved in the db?!
In classes/GalleryCheckoutItem.class I added the following rows:
/**
* Beschreibung
*
* @g2 <member>
* @g2 <member-name>beschreibung</member-name>
* @g2 <member-type>VARCHAR</member-type>
* @g2 <member-size>MEDIUM</member-size>
* @g2 <required/>
* @g2 </member>
*
* @var $beschreibung
* @access public
*/
var $beschreibung;
.......
function getBeschreibung() {
return $this->beschreibung;
}
function setBeschreibung($beschreibung) {
$this->beschreibung = $beschreibung;
}
Then I ran make. But it didn't work.
Please help. Thx.
Posts: 4342
What do you mean by "it didn't work"?
Posts: 6
It didn't store the data from the input-field into the db, althogh it was in the session.
Posts: 4342
Ok, you need to start giving more detail than snappy one-line answers if you want help.
Describe exactly what you did, step by step, after installing the module, to get this to work.
Posts: 6
Ok, I try...
Changes:
- Admin.inc, insertion at row 487: 'beschreibung' => $product['beschreibung'],
- Confirm.inc, insertion at rot 175: $txnItem->setBeschreibung($item[$product['productId']]['beschreibung']);
also at row 235: $txnItem->setBeschreibung($items['accessories'][$optionId]['beschreibung']);
- templates/SessionContents.tpl, replacement of '<input type="text" name="{g->formVar var="form[photos][`$item.id`][quant][`$thisProduct.productId`]"}" value="{$item[$thisProduct.productId].quant|default:''}" size="1" style="text-align:right;" />'
with
'<input type="text" name="{g->formVar var="form[photos][`$item.id`][beschreibung][`$thisProduct.productId`]"}" value="{$item[$thisProduct.productId].beschreibung}" size="40" />'
The field works fine (also after reloading -> session is okay)
- templates/TransactionContents.tpl, insertion for the output (beschreibung): {$block.checkout.items[x].beschreibung}
- classes/GalleryCheckoutItem.class (changes already described)
- classes/CheckoutHelper.class, insertion at row 248:
if ( isset($itemDetails['beschreibung'][$prodId]) ) {
$items[$itemId][$prodId]['beschreibung'] = $itemDetails['beschreibung'][$prodId];
}
- classes/CheckoutTransactionHelper.class, insertion at row 215, adding the field: , [GalleryCheckoutItem::beschreibung]
and also at row 232: ,'beschreibung'=>$result[9]
In Entities.inc there is now a new line at row 12: 'beschreibung' => array('type' => STORAGE_TYPE_VARCHAR, 'size' => STORAGE_SIZE_MEDIUM, 'notNull' => 1),
In the db I added the column g2_beschreibung (varchar(255), NULL)
Does that help?
Posts: 4342
Did you uninstall/reinstall the module after running make?
The problem is that adding a column to an existing table involves a version upgrade to the module (including bump in version number) and adding the upgrade code. That would break compatbility with future upgrades (also involves a lot of testing of the upgrade procedure, which is tedious.)
It's easier to add a column to a module on initial install (assuming that you're the only person going to be running the code) but you have to uninstall/reinstall which means you lose all existing orders.
You're trying to have the best of both, and it won't work. There are various internal db entries to do with table schemas that are created only when a module is installed the first time, or when it's upgraded. Since you've added the table by hand I don't think you've done all the necessary steps that the G2 code would ordinarily do for you.
Posts: 6
I did uninstall the module. Then some error-lines appeared(!). After that I reinstalled the module, and it didn't work (it's even worse now...). The funny thing is, that when I install the module, the table and everything belonging to that module is being installed instantly. You told me to reinstall - and when do I have to make my changes?
Posts: 4342
Not specific enough to be helpful, sorry.
Nor is that...
or that.
I don't understand this question. When do you make what changes?
Posts: 6
Sorry, it's really hard to conversate properly.
The most important question for me is: How do I have to make changes in the module?
I read the manual (How to create modules) and thought that I did everything nessecary (it looked easy...)
Posts: 4342
There's no fixed procedure for what you're trying to do. The "correct" way to do it is either to create the db column when you write the module (too late for that now), or add it correctly by means of a schema+module update. That's difficult, involves many steps, and will break future upgrades for you. I can't help you hack the changes into the middle of the code.
Posts: 6
Bad news for such a little change!
Maybe it's easier to fetch the data from the session than from the db - because it's not necessary to store the notes for an image.
I will do it that way.
Thx for your fast answers.