8 replies [Last post]
oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Was this information Helpful?

Okay folks, this really sums up my issue with ubercart 7e!
I have a gift certificate product in my shop meaning, you
buy it for an attribute option price and then it creates
a fitting coupon for it thru the now outdated coupon module.

Druing checkout I am scanning the shopping cart if there is
a gift certificate in it and then I want to add the checkout pane
called greetingstext to take in the personal wording for the
pdf gift certificate.

My issue eversince is that when I want to check in my checkout pane
callback function whether the $arg1->products's model the $arg1
order object is empty (At times i get it filled when returning
first from the review screen).

The checkout pane is called with () but then very callback function
contains ($arg1, $arg2 and $op)...

Okay, here I have come up with a test. Ryan's uc_lead contribution
ought to contain as default lead the $arg1->order_id. simply
change the default for the form, but then you will also see that
during the checkout pane in the ordering process you do not have
the $arg1 present?? Is this an core issue, an update issue or what.

Would anybody have another solution to maybe pick up the greeting sooner
during hook_order or when the gift certificate is put into the cart??

Do you get $arg1->order_id as default for uc_lead?? Let me know how!! Cool

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: UC_Lead Contribution W/ default=$arg1->order_id

Not a problem with Ubercart... there is no order object when you first go to the checkout form. That's why $arg1 is empty... Instead just check uc_cart_get_contents() for the nodes you want to find.

If you don't need a long message, just create an attribute called "Greeting" for the gift certificate and don't give it any options... this will make it a textbox.

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: UC_Lead Contribution W/ default=$arg1->order_id

Ryan, my man, now that is an answer according to my own taste.. Cool

I thought of the atrribute option myself as well, but maybe had to come up with 3 attributes, one for each line. How long can text in that attribute line be?

You should really consider changing ubercart that it also presents an $order with main order parameters...

Ok, now you want me to callback from a checkout pane a function that gets the contents of the cart? I hope there is an order_id in it, since I needed to store my greetings text linked to the order I am dealing with..

On the other hand, your uc_lead module, does it not also store the response with the order or just in a db so all can select from prior choices?

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
<?php  
<?php
   uc_cart_get_contents
($cid = NULL, $action = NULL)
?>

Description:

This function is used to return the contents of the user's cart.

When the function is called with no arguments, it will return the current customer's shopping cart. Alternately, you may specify a cart ID to load.

The function caches cart contents to prevent multiple database queries. If you need to load more than one cart, you're going to have to use the second argument to rebuild the cached contents.
Parameters:

* $cid - the ID of the cart to load from the database (loads the current user's cart when NULL); defaults to NULL
* $action - may be passed the string 'rebuild' to reload the items from the database; defaults to NULL

Return value:

An array of item arrays representing the products in the customer's shopping cart.

Sad

Ok, so then the pane cannot make decisions based on content, since I have no order-Id in order to store my stuff linked to that order. Strange, when I return from review order screen I have values. I think, you should have the first time order checkout screen simply displayed review and then there are just happy campers! Eye-wink

BTW i get no textbox but a long line... But as shown above this seems currently to be the only way of handling it. Evil (Recall, any cart is to be linked to an order object anyhow)

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: <?php  

You don't need an order ID on the checkout form page immediately. You use the 'process' op in the checkout pane callback function to add items directly to the order object. Then, you use hook_order() to save the data to the database. Look at the way the lead module is implementing that and you should be alright.

Also, use a textarea form element instead of a textfield to get a full text box instead of a single line.

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: <?php  

textarea vs. texfield: It is attribute driven, so I cannot change that,right?

No, I do not want to save the greetz, only store it from the checkout pane in the $arg1 object, so that I can use it after the order has been submitted, yet it fails to go like $arg1->greetz ="greetintext"; how come? so, you say at checoutpane i cannot use "process" in order to alter $arg1, which is the order object, I shall use the order_hook for it? But then must I store the data grom the greeting on checkoutpane into a db to reload it for that very purpose?? Enlighten me Ubercart boss Eye-wink

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: <?php  

I just really think you're missing something here... Conceptually.

Here's what you need to understand to get info from a checkout pane and find it later:

1) The checkout panes are merely parts of a form.
2) When the checkout form is submitted, you can add data to the order object.
3) You cannot save an order object through the checkout pane but must implement hook_order. This isn't the clearest thing right now, but just look at uc_lead and see how it's done. This is how you can easily store information related to an order and load it later.

I'm sorry if you feel you understand all these and still aren't getting somewhere, but the best thing I can say right now is to look at the example. Just modify it even... look at the comment checkout pane and just copy/modify that if you want.

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: Re: Re: <?php  

I'll give it yet another try and get back to you Eye-wink

marcus45's picture
Offline
Joined: 11/03/2009
Juice: 40
Having trouble adding info to order object

I'm trying to add new fields to the checkout page. I'm adding multiple delivery fields. I've gotten as far as adding the fields to the checkout page and adding the values to the order object during "process".

However the new values are not in the order object when I get to the checkout review page. My module is nothing more than uc_lead modified a little. Anyone have any idea what I could be doing wrong?

Thanks

Callback:
function uc_checkout_pane_recipients($op, &$arg1, $arg2) {

// Get Cookie that stores how products are grouped
$product_group = $_COOKIE["productGroup"];
$arrProductGroup = (explode(" ", $product_group));
$num_recipients = count($arrProductGroup) - 1;

$arrCopy = array();
switch ($op) {
case 'view':
$description = t('Please tell us where to deliver your birthday balloon bouquet.');

for($i = 0; $i < $num_recipients; $i++)
{
$j = $i+1;
$recipient_panel = "recipient" . $i;
$recipient_title = "Recipient " . $j;

$contents[$recipient_panel] = array (
'#type' => 'fieldset',
'#title' => t($recipient_title),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
if (uc_address_field_enabled('first_name'))
{
$field_name = "recipients_first_name" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('first_name'),
NULL,
uc_address_field_required('first_name'));
}
if (uc_address_field_enabled('last_name'))
{
$field_name = "recipients_last_name" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('last_name'),
NULL,
uc_address_field_required('last_name'));
}
if (uc_address_field_enabled('company'))
{
$field_name = "recipients_company" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('company'),
NULL,
uc_address_field_required('company'), NULL, 64);
}
if (uc_address_field_enabled('street1'))
{
$field_name = "recipients_street1" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('street1'),
NULL,
uc_address_field_required('street1'), NULL, 64);
}
if (uc_address_field_enabled('street2'))
{
$field_name = "recipients_street2" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('street2'),
NULL,
uc_address_field_required('street2'), NULL, 64);
}
if (uc_address_field_enabled('city'))
{
$field_name = "recipients_city" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('city'),
NULL,
uc_address_field_required('city'));
}
if (uc_address_field_enabled('country'))
{
$field_name = "recipient_delivery_country" . $i;
$contents[$recipient_panel][$field_name] = uc_country_select(uc_get_field_name('country'),
NULL, NULL, 'name',
uc_address_field_required('country'));
}
if (uc_address_field_enabled('zone'))
{
$field_name = "recipient_delivery_country" . $i;
if (isset($_POST['panes']['delivery'][$field_name]))
{
//$field_name = "recipient_delivery_country" . $i;
$country_id = intval($_POST['panes']['delivery'][$field_name]);
}
else
{
//$field_name = "recipient_delivery_country" . $i;
$country_id = $arg1->$field_name;
}
//$field_name = "recipients_zone" . $i;
$contents[$recipient_panel][$field_name] = uc_zone_select(uc_get_field_name('zone'),
NULL, NULL,
$country_id, 'name', uc_address_field_required('zone'));
if (isset($_POST['panes']) && count($contents['delivery_zone']['#options']) == 1)
{
$contents[$recipient_panel]['delivery_zone']['#required'] = FALSE;
}
}
if (uc_address_field_enabled('postal_code'))
{
$field_name = "recipients_postal_code" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('postal_code'),
$arg1->delivery_postal_code,
uc_address_field_required('postal_code'), NULL, 10, 10);
}
if (uc_address_field_enabled('phone'))
{
$field_name = "recipients_phone" . $i;
$contents[$recipient_panel][$field_name] = uc_textfield(uc_get_field_name('phone'),
$arg1->delivery_phone, uc_address_field_required('phone'), NULL, 32, 16);
}

}

$contents['lead_source'] = array(
'#type' => 'select',
'#title' => t('I found your site through'),
'#options' => drupal_map_assoc($options),
'#default_value' => $arg1->recipients['source'],
);
$contents['lead_other'] = array(
'#type' => 'textfield',
'#title' => t('Other source'),
'#description' => t('Fill this in if you chose Other source above.'),
'#default_value' => $arg1->recipients['source'] == t('Other source') ? $arg1->recipients['other'] : '',
);
return array('description' => $description, 'contents' => $contents, 'theme' => 'address_pane');
//return array('description' => $description, 'contents' => $contents);

case 'process':
for($i = 0; $i < $num_recipients; $i++)
{
$recipient_num = "recipient" . $i;

$field_name = "recipients_first_name" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_last_name" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_company" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_street1" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_street2" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_city" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_delivery_country" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_postal_code" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

$field_name = "recipients_phone" .$i;
$arg1->recipients[$recipient_num][$field_name] = $arg2[$recipient_num][$field_name];

}
if ($arg1->recipients['source'] !== t('Please select one...'))
{
$arg1->recipients['source'] = $arg2['lead_source'];
}
if ($arg1->recipients['source'] == t('Other source'))
{
$arg1->recipients['other'] = $arg2['lead_other'];
}

return TRUE;

case 'review':
for($i = 0; $i < $num_recipients; $i++)
{
$j = $i + 1;
$recipient_address = "Recipient " . $j . " Address";
$recipient_num = "recipient" . $i;
$review[] = array('title' => t($recipient_address), 'data' => uc_order_address($arg1->recipients[$recipient_num],
'delivery', FALSE));
if (uc_address_field_enabled('phone') && !empty($arg1->delivery_phone))
{
$field_name = "recipients_phone" .$i;
$review[] = array('title' => t('Phone'), 'data' => check_plain($arg1->recipients[$recipient_num][$field_name]));
}
}

if ($arg1->recipients['source'] != t('Please select one...'))
{
$review[] = array('title' => t('Site found through'),
'data' => $arg1->recipients['source'] == t('Other source') ? check_plain($arg1->
recipients['other']) : check_plain($arg1->recipients['source']));
}

return $review;

case 'settings':
$form['uc_recipients_options'] = array(
'#type' => 'textarea',
'#title' => t('recipients options'),
'#description' => t('Enter options one per line for the lead tracking select box.'),
'#default_value' => variable_get('uc_recipients_options', ''),
);
return $form;
}
}