Hi Matt,

I've been trying to integrate the donations_thermometer block ( http://drupal.org/project/donations_thermometer ) and uc_lto but I cant figure out how to assign one thermometer block to one LTO product as currently the thermometer block shows in the entire website. I inserted some code from the donations module and donations thermometer block into uc_order and managed to pass all the variables. However, I am finding difficult to put the right code to allocate one thermometer block to one LTO product.

I've done the following:

1.From donations module I took:

define ('DONATION_UPDATE_DONATIONS_THERMOMETER', 'donation_update_donations_thermometer');

And inserted it into uc_order module at the top.

2.Then I took:

donation_update_donation_thermometer_amount();

And inserted it into uc_order module at the end of function uc_order_log_changes:

function uc_order_log_changes($order_id, $changes) {
global $user;

if (count($changes) == 0) {
return FALSE;
}

foreach ($changes as $key => $value) {
if (is_array($value)) {
$items[] = t('@key changed from %old to %new.', array('@key' => $key, '%old' => $value['old'], '%new' => $value['new']));
}
elseif (is_string($value)) {
$items[] = $value;
}
}

db_query("INSERT INTO {uc_order_log} (order_id, uid, changes, created) VALUES (%d, %d, '%s', %d)",
$order_id, $user->uid, theme('item_list', $items), time());

donation_update_donation_thermometer_amount();

return TRUE;
}

3.Also I added at the end of uc_order module the following functions from donations module:

/**
* Return the total amount of the donations
*/

function donation_total() {
$sql = 'SELECT SUM(d.Amount) FROM {donations} d WHERE d.status=1';
$result = db_result(db_query($sql));
$result = check_plain(sprintf('%.2f',$result));
return $result;
}

/**
* If enabled update the donations_thermometer_amount
*/

function donation_update_donation_thermometer_amount() {
if (variable_get(DONATION_UPDATE_DONATIONS_THERMOMETER, 0) == 1) {
variable_set('donations_thermometer_amount', donation_total());
}
}

4. Then I changed database query:

function donation_total() {
$sql = 'SELECT SUM(d.Amount) FROM {donations} d WHERE d.status=1';
$result = db_result(db_query($sql));
$result = check_plain(sprintf('%.2f',$result));
return $result;
}

Into :

function donation_total() {
$sql = 'SELECT SUM(qty) FROM {uc_order_products} WHERE nid=%d';
$result = db_result(db_query($sql));
$result = check_plain(sprintf('%.2f',$result));
return $result;
}

I activated donations_thermometer and added a LTO to one product and after the checkout the thermometer shows the amount. However, the thermometer appears in all nodes and pages.

Any suggestions on how to allocate this donations_thermometer block to one LTO product, please? Or is there any other solution? Maybe working on the theme template? However, a block to publish the amount of products ordered during the offer time either as a thermometer, as text or other graphical format would be nicer.

Many thanks,

Andrew

CommentFileSizeAuthor
#4 LTO.jpg13.03 KBandrews501

Comments

WebNewCastle’s picture

Hi Andrew,

I'm sorry I missed seeing this. Where are things at for you on this?

- Matt

andrews501’s picture

Hi Matt,

Still trying to figure out how to create a block. However, I am also considering the option of using css to only highlight the section where the clock and/or termometer are placed.

WebNewCastle’s picture

I see. I'm not familiar with the module and am not entirely sure I understand what you are creating. Is there a link you can post to provide a visual reference? If that module is literally creating a block, can you use the block visibility settings to isolate the display to the specific node/product only? Or am I completely missing the point?

andrews501’s picture

StatusFileSize
new13.03 KB

Attached you will find an example of how the block is placed next to the clock. Regards the block visibility settings, I think you are right. If the block visibility settings could be isolated to display the specific node/product only, would be great. So, you show the clock (limited time offering) and also the limited amount, either presenting both at the same time, or only one of them.

I am also thinking that css could help to highlight the LTO and bar sections in case node cannot be isolated in a block.

WebNewCastle’s picture

That image looks awesome. :-)

If the main task is to just control when the block appears, then, yes, you can put something like "node/1" in the visibility section and tell it to only display there (vs. the exclude or PHP option).

kayusee’s picture

Thank you for the code. I'm trying to do something similar. Please how did you resolve the 'display the specific node/product only' issue.

Thank you

andrews501’s picture

Still trying to figure it out how to display specific node/product info in the uc_donation thermometer block. It seems that it is based in a single product/donation. I managed to create the block with the thermometer and make it appear in evrery product, however, it is the same thermometer that is used for the entire site.

Any suggestions, please?

Many thanks

marinex’s picture

Hi, maybe help you this link Show a block depending on node type and node id


good luck!


Marinex

kayusee’s picture

andrews501, You said:

"1.From donations module I took:

define ('DONATION_UPDATE_DONATIONS_THERMOMETER', 'donation_update_donations_thermometer');

And inserted it into uc_order module at the top."

When I opened UC Order folder in the Ubercart module, there are several sub-folders. Did you insert the code into the uc_order.module or which file were you referring to?

Thank you.

andrews501’s picture

Marinex,

Many thanks, I will try it.

andrews501’s picture

kayusee,

Yes, I inserted it into uc_order.module (step 2).

kayusee’s picture

Thanks.

marinex’s picture

I looked at donations_thermometer.module and I dont understand why do you use variable donations_thermometer_amount. This variable is only for one value and you have a lot of products, therefore every product should have own variable or you must constantly updated this variable upon display of any product.


And my 2nd question is why do you add donation_update_donation_thermometer_amount() to uc_order_log_changes function. A better solution would be use any hook of order or ubercart.

Thanks for reply

andrews501’s picture

Hello Marinex,

Yes, you are right, each product needs to have one value, however, I am just learning programming, so still cannot figure it out.

Regards your second question, you are also right, it would be better probably doing the update directly from hook order.

Any examples you could provide will be very helpful.

Many thanks

marinex’s picture

I am rewriting this module to integrate with Ubercart and maybe to end this month I will have whole a new module ;-)

you must endure ;-)

M.

kayusee’s picture

Thanks. Looking forward to the module.

WebNewCastle’s picture

Hello,

I apologize for having to be away and not following the conversation more closely. Is there anything I need to do or respond to in regards to UC LTO?

Thanks,

Matt

kayusee’s picture

Is it possible to have the module look like or similar to the picture here: http://drupal.org/files/issues/LTO.jpg

Dragolin’s picture

Any update on this? Marinex, how is that module coming along?