Great module! I'm wondering if, for simple codeless discounts (i.e. 15% all products), it would be possible to show the discounted price in the product node and in the shopping cart?

I know that more discounts that require conditions to be fulfilled would not work. However, I was thinking that perhaps I could get the final price of a product by basing it off of what discounts are available that don't require a code and for which the Qualifying Amount is <= 1. Would this make sense and would the right way to implement it be to create a new CCK field like "Codeless Discount Price"?

CommentFileSizeAuthor
#111 price_ranges_field.zip4.3 KBmsumme
#88 product page discount.JPG10.4 KBZalatar
#88 products discount not shown.JPG4.75 KBZalatar
#76 Snap1.jpg26.02 KBadrianmak
#73 non discount product's price also be striked through54.43 KBadrianmak
#69 html source of the product list Views23.53 KBadrianmak
#71 Snap1.jpg47.54 KBadrianmak
#70 original price doesn't strike-thru in product node view29.87 KBadrianmak
#68 procut listing geenrated by a Views20.43 KBadrianmak
#68 product node view26.19 KBadrianmak
#68 UC Catalog product 13.69 KBadrianmak
#48 uc catalog product view29.11 KBadrianmak
#48 product view21.67 KBadrianmak
#49 photoshop modified29.48 KBadrianmak
#40 product_price_alterer_field_2.zip1.5 KBryangroe
#34 not-showing.PNG5.18 KBgtfourdreams
#34 fields.PNG5.34 KBgtfourdreams
#34 cache-off.PNG27.35 KBgtfourdreams
#29 product view23.68 KBadrianmak
#28 product_price_alterer_field.zip1.5 KBryangroe
#27 product node view21.28 KBadrianmak
#27 html generated29.38 KBadrianmak
#27 php error log207 bytesadrianmak
#26 uc_discounts_alt.zip41.2 KBryangroe
#22 prodcut view with beta 2015.1 KBadrianmak
#22 generated html with beta 2019.32 KBadrianmak
#20 no price altered strike thru 18.05 KBadrianmak
#20 generated html27.01 KBadrianmak
#17 untitled.PNG5.71 KBgtfourdreams
#16 uc_discounts_alt_screenshot1.jpg55.88 KBryangroe
#15 Two CCK fields added66.48 KBadrianmak
#15 Two cck fields do not shown on product node edit form35.05 KBadrianmak
#12 product_price_alterer_field_3.zip1.69 KBryangroe
#11 php_error.zip372 bytesadrianmak
#10 php_error.zip372 bytesadrianmak
#9 product_price_alterer_field_2.zip1.64 KBryangroe
#8 product_price_alterer_field.zip1.51 KBryangroe

Comments

ryangroe’s picture

The discounted price in the product page is a good idea. I'll think about how to show that.
Showing discounts in the shopping cart is also requested here: http://drupal.org/node/431808

jrust’s picture

Very cool. I'd definitely be willing to sponsor you to develop this feature. PM me if you're interested.

ryangroe’s picture

Version: 6.x-1.0-beta9 » 6.x-1.0-beta14
Assigned: Unassigned » ryangroe
Status: Active » Needs review

The following is available in beta 14:

1. Discounts are now shown on the cart page underneath the current subtotal along with an updated subtotal including discounts. This is part of the base uc_discounts module.

2. To show the discounted price in the product page there is a new sub module, product_price_alterer_field. When this field is added to products it strikes (using ) the current price and adds the discounted price in red (in product_price_alterer_field.css, use CSS to change). The discounted price shows up only if there are discounts that are codeless and would be qualified for if the user checked out with 1 or less of the current product). See README.txt for installation information.

These new features require testing. Please download beta 14 and test it out.

gtfourdreams’s picture

Using Beta14, when I enable the 'Product Price Alterer', I get a host disconnect on the products pages. But all other pages that don't show products work.

I get this for headers:

user@server:~$ lynx -head http://www.xxxxxx.com/node/1 

Looking up www.xxxxxx.com 
Making HTTP connection to www.xxxxxx.com 
Sending HTTP request.
HTTP request sent; waiting for response.
Alert!: Unexpected network read error; connection aborted.
Can't Access `http://www.xxxxxx.com/node/1' 
Alert!: Unable to access document.

(site, user and server masked for privacy)

Apache logs the visit in access.log, but generates nothing in error.log

66.41.xxx.xxx - - [20/Apr/2009:14:31:36 -0500] "GET /node/1 HTTP/1.0" 200 6539 "-" "Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.0.4"
66.41.xxx.xxx - - [20/Apr/2009:14:37:25 -0500] "HEAD /node/1 HTTP/1.0" 200 - "-" "Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.0.4"

once I remove the custom field, the products work again. I wish I had more information... anybody know where else I can look for an error msg? anybody else getting this problem?

ryangroe’s picture

I had that problem initially but I thought I got it worked out. Sorry about that. I will investigate this tonight.

gtfourdreams’s picture

any idea where to look? i can help debug if you like.

ryangroe’s picture

The field uses javascript to change the price field. It was the easiest way to implement it and it was the easiest for people to integrate. The problem may be related to this (or could just be another bug in my code). I will send out some info to help debug this in an hour or so. Thanks for your help.

ryangroe’s picture

StatusFileSize
new1.51 KB

Sorry, I got held up at work. Now I'm home and can help debug this. First try replacing your product_price_alterer_field.module with the attached file.

ryangroe’s picture

StatusFileSize
new1.64 KB

If that doesn't fix the problem try this file. This will write to your PHP error log file. So please post the results here. This file won't fix the problem but will help us debug the problem.

adrianmak’s picture

StatusFileSize
new372 bytes

I got the same issue after added the two fields. i attached my php error log

adrianmak’s picture

StatusFileSize
new372 bytes

I got the same issue after added the two fields. i attached my php error log

ryangroe’s picture

StatusFileSize
new1.69 KB

Thank you, adrianmak. I have another update to gather more information (please clear your error log first). Sorry for the roundabout method. I've tried to get this to fail locally but have been unsuccessful.

ryangroe’s picture

Hold up on that test. I think I figured out the problem. I realized that my site had the product nodes cached and that's why I wasn't getting the error (my site wasn't entering the load case as your site was). Please download and try beta 18. If that still gives you a problem then download product_price_alterer_field_3.zip and send me the log. Thanks.

adrianmak’s picture

I updated to beta18 of this module and the mentioned problem fixed.
But why I cannot see the added the two cck field in node edit ?

and cannot see any below mentioned on another issue thread

2. To show the discounted price in the product page there is a new sub module, product_price_alterer_field. When this field is added to products it strikes (using ) the current price and adds the discounted price in red (in product_price_alterer_field.css, use CSS to change). The discounted price shows up only if there are discounts that are codeless and would be qualified for if the user checked out with 1 or less of the current product). See README.txt for installation information.

adrianmak’s picture

I attached my screen below.

ryangroe’s picture

StatusFileSize
new55.88 KB

I'm sorry, beta 18 didn't contain all the files. Please try beta 19.

The fields won't show up on the edit page because the information they display is always generated, so it can't be edited manually. The values only show up when viewing the product. I have attached a screenshot of how it looks on my site (it's just the part showing the two CCK fields).

gtfourdreams’s picture

StatusFileSize
new5.71 KB

hmm.. doesn't work for me (in the customer view mode).

i installed the beta19 version. uninstalled the fields modules and re-installed. it looks like the module is being called.. because it's attaching the css file.

< link type="text/css" rel="stylesheet" media="all" href="/modules/uc_discounts_alt/product_price_alterer_field/product_price_alterer_field.css?9" / >

but the following javascript isn't being generated anywhere on the pages.

<?php

	//Alter price using javascript
	drupal_add_js( sprintf("$(document).ready(function()
		{
			sell_price = $(\".sell-price:not(.product_price_alterer_field-processed)\").each(function()
				{
					if ( $(this).hasClass(\"product-info\") )
					{
						$(this).addClass(\"product_price_alterer_field-processed\")
							.addClass(\"product-price-alterer-field-sell-price\")
							.html(%s)
							.after(%s);
					}
				});
		});", drupal_to_js($sell_price_string), drupal_to_js($discount_price_string) ), "inline");

	//Always return NULL to not display an actual field to user
	return NULL;
}
?>

HTML Generated equiv of attachment, if it helps

Height: 3.65in< br / >
Length: 11.39in< br / >
Width: 0.78in< br / >
Weight: 2 lbs< /p >
< div class="field field-type-codeless-discounts field-field-codeless-discount" >
      < div class="field-label">Codeless Discount:&nbsp;< /div >
    < div class="field-items">
            < div class="field-item odd" >
                    10% Quantity Discount: 10 items or more        < /div >
        < /div >
< /div >
< div class="product-info sell-price" >$50.00< /div >< div class="add-to-cart" >< form action="/"  accept-charset="UTF-8" method="post" id="uc-product-add-to-cart-form-3" >
ryangroe’s picture

Darn. It must be generating a different type of field event on your site (a different $op value in product_price_alterer_field_field). I will do a little more research and get back to you.

gtfourdreams’s picture

lemme know if there's anything you want me to run to help you debug.

adrianmak’s picture

StatusFileSize
new27.01 KB
new18.05 KB

I installed beta19 and execute the update.php script and then disabled the two cck field module and enabled again.

However those configured discount product did not show the price strike thru on product view.
I look into the generated html and cannot found and additional html of product price alter similar as gtfourdreams

My problem is same as gtfourdreams . ><

ryangroe’s picture

please grab beta 20.

I changed the way the CCK modules work. Unfortunately this change breaks any existing theming people have done to codeless_discounts_field_get_codeless_discount_html_for_product (see theme_codeless_discounts_field_get_codeless_discount_html_for_product in codeless_discounts_field.module for new format)

I appreciate your patience. The CCK module hooks aren't particularly well documented.

adrianmak’s picture

StatusFileSize
new19.32 KB
new15.1 KB

grabbed beta20 and replaced existing folder.
updated.php script performed.
disable and enable two cck fields.
clear clear data.

But this time, even worse.

Nothing html generated in the product view

ps I'm using CCK 2.2 version.

ryangroe’s picture

The product_price_alterer_field module does not write any HTML. Instead it uses javascript to alter the field. This javascript only gets loaded once and then is cached. The codeless_discounts_field produces HTML but is also only loaded once and cached. So please flush all your caches and reload the product page. I think you did this but please try it again.

ryangroe’s picture

By "try again" I mean just load a product page again.

adrianmak’s picture

I cleared cache data at admin/settings/performance. The right place ?

I even though cleared all web browser cache too and cleared cache again and does not help.

---------updated----------
I found that I get into a product node edit page, and click save, the discount information shown (but still no price strike)
However I refresh the page by clicking F5 key , the discount information will disappear

ryangroe’s picture

StatusFileSize
new41.2 KB

Thank you for your patience. We'll get this figured out soon.

That's the correct place to clear the cache, but after the problems you've had I am going to move away from caching data for now. It's a little less efficient but I think it's good enough for now.

I've attached a zip containing a test version of the entire uc_discounts_alt module. It changes the way I generate the CCK fields. It also writes to the error log. So let me know what your visible display is and what your error log says. Thanks again.

adrianmak’s picture

StatusFileSize
new207 bytes
new29.38 KB
new21.28 KB
ryangroe’s picture

StatusFileSize
new1.5 KB

OK, so everything is there except the javascript isn't working. My site had a "product-info" class on my sell price div. I removed this from the javascript. Give the attached file a try. If it still doesn't work please ensure the javascript is getting added to the page by searching for the following:
$(".sell-price:not(.product_price_alterer_field-processed):first")

Thanks.

adrianmak’s picture

StatusFileSize
new23.68 KB

I replaced mine by your attachment and now price striking is shown properly.

ryangroe thanks ~~~

ryangroe’s picture

That's great. I'm glad we got this worked out. Thanks for your help. I will release a new beta.

adrianmak’s picture

one more minor question, I have a product node theming template,
Which field should I print out this information ?

I tried following code

	print $node->content['field_product_price_alterer'][field][items][0]['#theme'];

but still cannot print out right stuff.

ryangroe’s picture

I don't think I am setting the field up entirely right for you to do that yet. I'll look into it.

adrianmak’s picture

waiting for you~~~~

gtfourdreams’s picture

Version: 6.x-1.0-beta14 » 6.x-1.0-beta21
StatusFileSize
new27.35 KB
new5.34 KB
new5.18 KB

it's still not showing for me. i disabled and uninstalled both field modules. i cleared the cache, although my caching is turned off. i updated my php.ini to enable error_log. i restarted apache2. doesn't work. so i tried the module file from 'product_price_alterer_field.zip'. it still doesn't work.

same problem as before. css gets loaded on product pages.

< link type="text/css" rel="stylesheet" media="all" href="/modules/uc_discounts_alt/product_price_alterer_field/product_price_alterer_field.css?L" / >

but no javascript and no html generated.

Length: 11.39in< br />
Width: 0.78in< br />
Weight: 2 lbs< /p>
< div class="field field-type-codeless-discounts field-field-codeless-discount">
      < div class="field-label">Codeless Discount:&nbsp;< /div>
    < div class="field-items">
            < div class="field-item odd">
                    10% Quantity Discount: 10 items or more        < /div>
        < /div>
< /div>
< div class="product-info sell-price">Price: $50.00< /div>< div class="add-to-cart">< form action="/node/3"  accept-charset="UTF-8" method="post" id="uc-product-add-to-cart-form-3">

error log is blank

-rw-r--r-- 1 root root    0 2009-04-22 09:06 php_error.log

files are attached.

gtfourdreams’s picture

here's my crude debugging method. i added the following code:

<?php
        echo "\$op is: ".$op;
        switch ($op)
        {
                case "sanitize":
                case "view":
                        //If items is empty, generate value by getting discounts that apply to this product
?>

and it generated this everytime i load up a product page: $op is: sanitize

jrust’s picture

Very cool! This really makes for a nice discount system.

I am trying to add the field just as a CCK field. I think Javascript is a great idea so that it works for default installs, but I want the actual HTML to show the discounted price so that it's picked up by people without javascript and by bots like Google that search for the price.

Perhaps, there could be two CCK Display values for the field: Javascript and HTML? Anyhow, I tried just putting this into my node template (field_price is the name of the CCK field):

print $node->content['field_price']['#children'];

And it almost did exactly what I want, with one caveat: The original price was empty, both for products that are on sale and for products not on sale. This is the HTML that is generated:

<div class="field field-type-product-price-alterer field-field-price"> <div class="field-label">Price:&nbsp;</div> <div class="field-items"> <div class="field-item odd"> <div class='product-price-alterer-field-discounted-price'>Discounted price:&nbsp;$17.00</div> </div> </div> </div>

jrust’s picture

Also, to allow styling of the label we should wrap Discounted Price in a

<div class="field-label">

ryangroe’s picture

I definitely agree the all javascript idea wasn't the best :)

I initially went with all javascript but now it generates the discounted price with standard HTML and uses javascript to strike the original price and move the discounted price to always be under the original price. This went into beta 21.

I think I know why the original price is empty. I'll look into this tonight. I'll also wrap the discounted price in a field-label div.

Thanks for the help.

adrianmak’s picture

Under beta21, can i print two fields value in node template ?

ryangroe’s picture

Version: 6.x-1.0-beta21 » 6.x-1.0-beta14
StatusFileSize
new1.5 KB

jrust, please try the attached file and tell me if the original price is still blank.

adrianmak, I am not sure what you mean by "two fields value in node template". Can you please explain this more. Thanks!

adrianmak’s picture

As I said in previous reply, my product node page is themed node-product.tpl.php
I printed each fields as desired but now I have no idea which object or array to print the
strike price, discount text string on the product page.

jrust’s picture

Unfortunately, it is still blank :(

Also, the field-label is now there, but it should only wrap around the label (the words Discounted Price) instead of both the label and price.

adrianmak’s picture

ryangroe,

Do you understand what I mean ?
Most people would like to have their own product node theming i.e. node-product.tpl.php

printing field by field for theming is necessary so how to print the strike thru text, the discount information on the product view ?
I cannot figured out which field under object $node is relevant to this piece of information.

ryangroe’s picture

Sorry, most of my theming is done in a bit of a hack way on my site. I will attempt to create a test file with the appropriate field information by tomorrow.

ryangroe’s picture

A quick update: I am going to rewrite the CCK modules this weekend so they work properly with theming. I appreciate your patience on this.

gooddesignusa’s picture

Good work ryangroe I've been working hard and haven't had time to check up on this module. I'm excited its becoming so popular. Hopefully more people are donating to you :) I can maybe talk my boss into throwing you another donation b/c of this cool feature. Keep up the good work.

ryangroe’s picture

Thank you, gooddesignusa. I am trying hard to get this feature right for everyone. Unfortunately I didn't realize until now that I had been missing a theme function required to render the field properly.

I think I have this problem figured out. Please download beta 22. If upgrading you will need to delete your exist field and add a new one. Also, please read README.txt for additional theming information (such as removing the javascript this module adds that moves the discounted price field).

Using a custom node-product.tpl.php file I confirmed the following have values (assumes you named your field 'field_discounted_price'):
$node->content["sell_price"]["#value"]
$node->content["field_discounted_price"]["#children"]

jrust and adrianmak, I am happy to keep working on this until it's right.

adrianmak’s picture

StatusFileSize
new21.67 KB
new29.11 KB

Does the strike thru css effect shown on product catalog page or a views (I cannot find such field under view panel)?

I am not sure this should be handled by your module or other kinds

adrianmak’s picture

StatusFileSize
new29.48 KB

A photoshop modified catalog product view I expected.

ryangroe’s picture

I agree this is probably not the greatest way to do the strike but I wanted to have a single solution for users less advanced as you guys.

Just override the CSS and add a theme function to not add the javascript. Something like:
function phptemplate_add_product_price_altering_javascript($product)
{
//Do not add javascript
}

gooddesignusa’s picture

I never noticed any theme problems b/c i must of been doing it wrong. I use firebug with drupal plugin and just find the field with the info i need. i was using

$node->field_showdiscount[0]['view'];

Prob end up still doing that b/c i'm already using the stike for MSRP vs our price.
ex: http://snoutsdirect.com/products/12f-snout-scratchdent

adrianmak’s picture

Then how do I able to show the product discount alter price under catalog product page or on a view ?

ryangroe’s picture

adrianmak, I've actually never looked into how the catalog page views are created. I'll take a look at that but it probably won't be until Wednesday. I'm swamped at work.

jrust’s picture

Wow, really nice! Works like a charm! For those wondering how you might add the strikethrough on the original price without javascript, it would be something like this:

if (!empty($node->content["field_discounted_price"]["#children"])) {
  $node->content["sell_price"]["#value"] = '<div class="original-price">' . $node->content["sell_price"]["#value"] . '</div>';
}

And then of course you'd want to theme the javascript function that Ryan mentioned in #50 so that the JS is not outputted. Thanks again for all your work, this really makes Ubercart top notch.

jrust’s picture

Ok, sorry, one more thing that I just noticed. Is it possible to have the field show up in Views like other CCK fields? Neither the Codeless Discounts field or the Product Price alterer show up in views with the other CCK fields which makes it difficult to create custom store catalogs. According to this, the field should automatically be exposed to views, so I'm not sure why it's not. However, looking at another custom CCK module, colorpicker, it looks like it would just be a 5 line implementation of hook_field_settings(). Here's how colorpicker does it:

function colorpicker_cck_field_settings($op, $field) {
  switch ($op) {
    case 'database columns':
      return array('value' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE));

    case 'views data':
      $allowed_values = content_allowed_values($field);
      break;
  }
}

One other thing. Could you make the javascript that you run onload into a named function? I'd like to be able to call the javascript myself manually, but currently cannot because it's an anonymous function. Plus, if it was named and its own file it could be cached and minimized as an added bonus.

ryangroe’s picture

I think that's exactly what adrianmak wants to. I imagine there is just another notification mechanism I need to trigger to make that happen. I'll hopefully have that working by Wednesday.

adrianmak’s picture

ryangroe,

any good news regarding showing strikethru pricing under catalog product listing or in a views

ryangroe’s picture

Still working on it. I have a demo to get done at my day job that's keeping me from doing any uc_discounts_alt work.

adrianmak’s picture

Any update ?

ryangroe’s picture

Sorry, I've been working pretty late at the day job so I haven't been able to figure this out yet.

jrust’s picture

I looked into this a little bit more and the reason it doesn't show up in views is because it isn't a straight database column. It appears the module will have to implement hook_views_data() to expose the sell price. uc_products provides an example of how to show a virtual field (i.e. the addtocartlink field) that isn't a straight database field.

ryangroe’s picture

Yep, hook_views_data was needed. I finally got to this last night after a hellish week working on a demo at my day job. I created a hook_views_data(), changed the theming slightly and will have a new release out for you tonight.

jrust’s picture

Very nice -- thanks. Ok, now don't shoot the idea man, but I was thinking about this on the way home and was wondering why use CCK to implement this field? It doesn't seem to add a lot of functionality, but does make it more complicated for new users. Would it make more sense to use the new uc_price() stuff that came out in rc1? See this commit and this one as an example of how the uc_discount() module did it. Now, if it works, don't fix it, right? But, thought I'd throw it out there as an idea while we're still in beta.

ryangroe’s picture

Ya, that would be much easier. We might switch to that eventually but for now let's just say we're trying to backwards compatible with Ubercart versions :)

Beta 25 is available. Try it out.

jrust’s picture

Works great. I dare say this issue can be closed now... Thanks again for your great work!

ryangroe’s picture

I'm glad you are happy with the results. It was a little tricky to created a generated field for a view because I couldn't find an example where someone was doing the same thing. As usually is the case the code is pretty simple but figuring out what to change and how was the problem.

adrianmak, have you tried out this new version? Let me know what you think.

adrianmak’s picture

Today, I just got it has an update. I will try it and get back to you later.

adrianmak’s picture

StatusFileSize
new13.69 KB
new26.19 KB
new20.43 KB

Tested beta25 with some issues

I added discount price field in my views and it shown properly in product views page. But the original price will not strike thru.

The discount price will not show on catalog product list (i.e. not using views to product listing)

adrianmak’s picture

StatusFileSize
new23.53 KB

It seems that the javascript cannot alter the views-field-sell-price element to add a class on it.

I think the the if statement inside the selection of .views.field-sell-price is return FALSE, so addClass is not performed .

$(document).ready(function()
{
$(".views-field-sell-price").each(function()
{
if (this.tagName.toUpperCase() == "TD")
$(this).addClass("original-sell-price");
});
 $(".sell-price:not(.original-sell-price):first").each(function()
 {
 this_wrapped = $(this);
 this_wrapped.addClass("original-sell-price")
 .after( $(".field-type-discounted-price:first") );
 });
 });
adrianmak’s picture

Please discard this reply.

adrianmak’s picture

StatusFileSize
new47.54 KB

My product views settings

ryangroe’s picture

Version: 6.x-1.0-beta14 » 6.x-1.0-beta25

Try changing:
if (this.tagName.toUpperCase() == \"TD\")
to:
if (this.tagName.toUpperCase() != \"TH\")
in product_price_alterer_field.module around line 198.

This if statement is just trying to avoid striking the table header text that says "Sell price".

To put the discounted price on the catalog page you'll need to override theme_uc_catalog_product_grid (see uc_catalog/uc_catalog.module).

adrianmak’s picture

As your suggestion, it works. But it also strike-through all non-discount product

ryangroe’s picture

I added better handling for view styling. I'm not sure it will cover every case but it should be close. Try out beta 26 coming out shortly.

adrianmak’s picture

I'm feel sorry. After updated to beta27, price for non discount product still be strike through on product views

adrianmak’s picture

StatusFileSize
new26.02 KB

This is html output for an non discount product.

Because when .views-field-discounted-price class exist , the if statement will be true and it will add class to original price no matter whether the product has a discount or not.

I guess not to output the the div .views-field-discounted-price ...... if a product doesn't not apply an discount.
Then the javascript will work properly.

update.....
For quick & dirty method, I used views's row theming template to check discount price is exist or not.
If exist, output those div element otherwise none.

This is what I added in view row template. I added $field->content to check content

<?php if ($field->content) { ?>
  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      // $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      ?>
      <<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
<?php } ?>  

It seems work fine

ryangroe’s picture

This is a bit tricky but the following should handle most cases (replace your entire existing js block in product_price_alterer_field.module with this). Let me know if this works for you:

//Alter price using javascript
drupal_add_js("$(document).ready(function()
{
$(\".views-field-discounted-price\").each(function()
{
var self = $(this);
var content = self.find(\".field-content:first\");
if ( (content.size() > 0) && ($.trim( content.html() ).length == 0) )
return true;
else if ($.trim( self.html() ).length == 0)
return true;

self.parent().find(\".views-field-sell-price:not(th)\")
.addClass(\"original-sell-price\");
});
$(\".sell-price:not(.original-sell-price):first\").each(function()
{
self.addClass(\"original-sell-price\")
.after( $(\".field-type-discounted-price:first\") );
});
});", "inline");

recrit’s picture

Version: 6.x-1.0-beta25 » 6.x-1.0-beta28
Category: feature » bug

I am using beta28 and the original sell-price was not getting a strike through... I believe the bug lies on line 210 of product_price_alterer_field.module.

210: self.addClass(\"original-sell-price\")

should be:
210: $(this).addClass(\"original-sell-price\")

since self is not defined for the query $(".sell-price:not(.original-sell-price):first")

ryangroe’s picture

Thanks, recrit. I've changed this code so many times and made several mistakes. I'll fix this tonight (PDT).

recrit’s picture

further refining my previous fix for use in lists since the original query used :first sell-price, which would only add a class to the first item on the page.

product_price_alterer_field.module:

208: $(\".sell-price:not(.original-sell-price)\").each(function()
209: {
210: var self = $(this);
211: self.addClass(\"original-sell-price\")
212: .after( $(\".field-type-discounted-price:first\", self.parent()) );
213: });

line 212 query ensures the element is added after within in context of the sell-price's parent. I haven't fully tested this, but it worked on my example.

adrianmak’s picture

According to recrit's post #78, should I replace all self. to $(this). before my testing ?

ryangroe’s picture

Here's what I put in and tested:
var self = $(this);
$(this).addClass(\"original-sell-price\")
.after( self.parent().find(\".field-type-discounted-price\") );

Basically what recrit suggested except I'm using self.parent().find instead of passing self.parent() into the selector. I'm not sure which faster but this way looks a little more readable...to me at least :)

This will be part of beta 29 to be released shortly.

ryangroe’s picture

Sorry, that should be:

var self = $(this);
self.addClass(\"original-sell-price\")
.after( self.parent().find(\".field-type-discounted-price\") );

recrit’s picture

thanks for the quick response!
line 208 without the ':first' is what fixed my issue with it only adding to the first sell-price in a node list, will you be adding this to beta29?

.find() or context passing to jquery - I'm not sure which is faster either. I had passed the self.parent() as a context to jquery since depending on the specific situation if there is no parent() then the expression degrades to $(".field-type-discounted-price:first").

However, forcing an empty parent is producing the same result as with a real parent.... confusing to me. But if you remove any parent consideration, whether context or find(), then things get confused

test case with empty parent: results in same as actually finding a parent

$(\".sell-price:not(.original-sell-price)\").each(function()
{
var self = $(this);
var dbg = $(\".nothing\");
self.addClass(\"original-sell-price\")
.after( $(\".field-type-discounted-price:first\", dbg) );
});

test case with no parent: results in very confused random placement of original sell-prices

$(\".sell-price:not(.original-sell-price)\").each(function()
{
var self = $(this);
self.addClass(\"original-sell-price\")
.after( $(\".field-type-discounted-price:first\") );
});

on a side note..
This is a great module! It's a much better implementation and flexibility than the uc_coupon module. It has everything I need to meet all my client's requirements.

ryangroe’s picture

Thanks, recrit! That's more testing and experimentation than I can do on my current schedule. I'll change the block to be exactly like you posted in comment 80:

$(\".sell-price:not(.original-sell-price)\").each(function()
  {
    var self = $(this);
    self.addClass(\"original-sell-price\")
      .after( $( \".field-type-discounted-price:first\", self.parent() ) );
  });

Zalatar’s picture

Just a quick question on this thread. Did this get fixed in the latest release? I can't seem to get it to show up on the products page.
Thx,
Z

ryangroe’s picture

It's broken in beta 32- but should be fixed in beta 33+

Zalatar’s picture

StatusFileSize
new4.75 KB
new10.4 KB

Hmm..I am running beta 33 but no discount price on products page. I see it on the product page but not on the products page. Not sure if I am using the right terminology or not. Hopefully you get the meaning. See photos.
Let me know what I can do to help.
Thx,
Z

ryangroe’s picture

Sorry, I misread that. The product page works. I believe the products page is a view and you'll need to add the discounted price field to that view.

/admin/build/views/edit/uc_products
+Field
Field name: Add "Product: Discounted price"

I'm unable to check the code right now so please let me know if this is correct. If not I can go over this more with you tonight (PDT).

Zalatar’s picture

I had already added the field to the view but I still does not show. If you have time tonight that would be great, if not I will keep my eye out for your post.
Z

ryangroe’s picture

That's a catalog page, right (the URL is something like /catalog/13)? To put the discounted price on the catalog page I believe you'll need to override theme_uc_catalog_product_grid (see uc_catalog/uc_catalog.module).

From comment #47:
Using a custom node-product.tpl.php file I confirmed the following have values (assumes you named your field 'field_discounted_price'):
$node->content["sell_price"]["#value"]
$node->content["field_discounted_price"]["#children"]

There may be a better way. I haven't been keeping up with Ubercart theming changes.

duckzland’s picture

Hi, Ryan,

How do you exactly override theme_uc_catalog_product_grid? I got the node-product.tpl.php to show the strike through price both using $node->content["field_discounted_price"]["#children"] and custom php :

if ( $node->field_discountprice[0]['view'] != NULL ) :

print uc_currency_format($node->sell_price);
            		print $node->field_discountprice[0]['view']; 

else:

print uc_currency_format($node->sell_price);
endif;

but no luck in views and product catalog.

Just upgrade to beta33, still no strike through in views. and views is showing the discounted label although there is no discount value.

BTW, great module though...

Duckz

duckzland’s picture

Just see the http://drupal.org/node/466472 and modified the catalog page with

foreach ($products as $nid) {
    $product = node_load($nid);
	$discounted_price = theme("get_discounted_price", $product);
    $context['subject'] = array('node' => $product);

and

    if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
      if ( is_null($discounted_price) ) {
	  $product_table .= '<div class="catalog-grid-sell-price">'. uc_price($product->sell_price, $context) .'</div>';
	  $product_table .= '<div class="catalog-grid-discount-price"></div>';
	  }
	  else {
	  $product_table .= '<div class="catalog-grid-sell-price"><s>'. uc_price($product->sell_price, $context) .'</s></div>';
	  $product_table .= '<div class="catalog-discount-price">'. '¥ ' .$discounted_price .'</div>';
	  }
	 }

now the catalog page is working with slash price and discounted price showing correctly.

But no clue for page with views enabled, ryan is there any solution for views?

Thanks

duckz

EDIT : Update the following line:

//	  $product_table .= '<div class="catalog-grid-discount-price">'. '¥ ' .$discounted_price .'</div>';
$product_table .= '<div class="catalog-grid-discount-price">'.uc_price($discounted_price, $context) .'</div>';

now paypal is broken.....

Fatal error: Unsupported operand types in /sites/all/modules/ubercart/uc_store/includes/uc_price.inc on line 89

jrust’s picture

With views you may be better off using one of the theme preprocess functions for the view. I took a look at the javascript being produced and it's just not particularly easy to figure out a one-size-fits-all solution considering how flexible views is. With a theme_preprocess_view function you could easily run through the rows and check to see if a discounted price is present and modify the sell price accordingly.

tahiticlic’s picture

Well, if you want to do the same without making the template, you have to put the "Discounted price" in the content type used as products, not in the product content type.
I guess for the product content type, UC controls which fields are displayed ,with none by default. So the right solution would be to add a "Discount price" checkbox in the admin/store/settings/products/edit/fields checklist.

Moreover, with this solution, you have to display the sell price in order to have the discount price displayed, but only the sell price is biffed, not the "master" price (he big one).

By the way, perhaps your test should lead to :

  <?php  if ( is_null($fields['discounted_price']->content) ) { ?>
  <div class="catalog-grid-sell-price"><?php print $fields['sell_price']->content; ?></div>
  <?php } else { ?>
  <div class="catalog-grid-sell-price"><s><?php print $fields['sell_price']->content; ?></s></div>
  <div class="catalog-grid-discount-price"><?php print $fields['discounted_price']->content; ?></div>
  <?php } ?>
mrwhizkid’s picture

@cfab,

For me, this seems like the best solution. I need my main catalog page and the associated product pages (catalog/13, for example) to display the sell price and the discounted price.

How would I go about adding this discounted_price checkbox to the product settings page so that if I ever need to turn this off for some reason, I don't have to go into the module and 'unhack' a bunch of stuff?

It would be nice to be able to just have it as a product field...

Thanks in advance for your help!

RachelNY’s picture

@ryangroe from comment #91

I put
print $node->content['field_discounted_price']['#children'];
in a custom node-product.tpl.php file.

It displays both the regular price and discounted price in Firefox, but only the regular price in MSIE.

Firefox: Regular Price with strike-through and discounted price shown

MSIE: Regular Price shown with no strike-through, no discounted price

Chrome, Safari, Opera: Regular Price shown with strike-through, no discounted price

Can you tell me what I have to do to get this to show properly on all (especially MSIE)?
Thanks,
Rachel

ezra-g’s picture

Status: Needs review » Needs work

Based on the reviews in this issue, it seems like this needs work.

Zalatar’s picture

Does anyone have the discounted price working on the product grid page yet?
It looks to me that this is still an issue.
If it is fixed, post a link to please.
Thx,
Z

msumme’s picture

I did something like this for a site I built recently. http://www.freelakotasilver.com/content/soto-nation-turtle-island

I just made a little module that would calculate the total price off for price tiers based on quantity discounts and then automatically display a small table with the actual price of the product at different tiers.

If anybody thinks they can use this, message me, and I'll upload the code back here. It's not super elegant, but it works.

I realize that's not exactly what everybody is saying here, but this is just for a very special use case. If anyone's interested, I'll write up what it's good for. It's just a cck field you add to the product.

P.S. If anyone can tell me why the discounts show up on the cart page, but not the cart/checkout or cart/review page, I would be very grateful.

redhatmatt’s picture

I would like the code msumme, as we use the grid. please post.

jmuessig’s picture

subscribe

jagpreet08’s picture

I have installed the uc_discounted module and it's working fine for the authenticated users but for anonymous users discounted price is not visible, however it shows him the current price with strike. Can anybody have any idea about how to make discounted price visible to anonymous user.

One more thing does anybody have any idea about hoe to show the discounted prices in the catalogue?

tacoma’s picture

Are there plans to have a build with the discounted price on product grid available soon?

grub3’s picture

+1 Tacoma. This would be very needed. People who buy do not only think in %, they need real figures to compare.

grub3’s picture

msumme, we would love to have your code.

trofiarik’s picture

Please Help!

I can't get the discounted price to show in my product detail page!
I am working with content template to modify the theme.
I tried a lot. I found that the discounted price is calculated if the conditions are true and so if I set a discount for quantity that get activated if you buy 2 or more items i can see the discount only in my cart, if otherwise I 'enable' the discount for 1 item or more, the module calculate the discount and I can get the value displayed already in my product detail.

How the hell to get and show the value even if discount is for 2 or more items?

There is a way to call and insert in my template the us_discount_alt module function that calculate the discounted price?

Or anybody know ho to write and insert in template a db query to get the 'discount_amount' value, so that with php I can easily recalculate and print out the discounted price??

Or other solutions/ideas?

Thanks everybody

trofiarik’s picture

An Update.

Succeded in showing the discounted price trough the codeless discount description field ...

but would be nice to find a way to directly insert the right function to calculate the discounted price, like said above. Would be better and more dynamic. In this way I have to compile the codeless discount field for each product category, and there are a lot of them.

thank again
Riccardo

ColinMctavish’s picture

Still trying to make this work on my site. Price Alterer doesn't seem to do anything and I have no need for the codeless discount.

msumme’s picture

StatusFileSize
new4.3 KB

This is really weird. I could swear I posted the code for this about a month ago, but it's not showing up.

It's basically a modification of one of the other modules already included in discounts_alt. It's not very polished, but hopefully it will benefit someone. It only works in a limited case where there are codeless discounts that stack on top of one another, so 50 cents off the first tier, 50 cents off the next tier, etc., and it displays like on freelakotasilver.com