Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Where is price of product added to cart, or should that be How is it?

    I'm currently working on a module and i need to be able to change the product price as it is added to cart.
    For example, Product A price is $25, but it is also available for $5 dollars if certain conditions are met.

    I've got the product to show the correct price in an ajax popup that allows it to be added to cart, but when it goes to cart, it charges the full price.
    Both prices are stored in the db, one as products_price, the other as products_price_offer.
    The new pages i have built all reference products_price_offer as i want, but i just can't get it to pass the offer price to the shopping cart.

    I think if i can find where it builds the array for adding to cart i can manipulate this to use the offer price instead, but i just can't seem to find it.

    Any help would be appreciated because i seem to be getting nowhere fast now.

    Thanks

  2. #2
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    Seems no one can offer any help so far.

    I've looked further into this and am even more confused by it now.
    tpl_product_info_display uses this to get the product price for display:

    echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);

    So i looked at functions_prices.php for function zen_get_products_display_price($products_id) {
    I then hard coded a value into $display_normal_price for testing purposes.

    Refresh the product page and the coded price showed correctly.
    Except, when added to cart, it used the price from the database, and not the one i hard coded.

    This suggest to me that the process of adding to cart does not take the variables used to output the product page, and it can't be using zen_get_products_display_price.

    So what does it use? Where does it get the price that is used for the cart?

  3. #3
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    Quote Originally Posted by strelitzia View Post
    ...
    For example, Product A price is $25, but it is also available for $5 dollars if certain conditions are met.
    ...
    Can you give us an example condition?
    Does the "Better Together" plugin fit your needs? Or "group discounts"? (these would be be good examples to look at for pricing changes).
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  4. #4
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    I looked at those and didn't really find anything that pointed me in the right direction.

    I can't believe it's so difficult to add a product to cart referencing the database for products_price_offer instead of products_price when conditions are met.

    Dr Byte, if you could give me some info on how zc processes prices i would appreciate it.

  5. #5
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    From what i can see, it doesn't actually carry an array full of ALL the product data over to the shopping cart, but instead uses $prid to hold the product id, plus some other checks that are made for attributes etc. The details in the cart are then pulled in from the database in includes/classes/shopping_cart.php.
    If i'm right on this, that explains why i can't get the cart to display the correct price, even though the product page does.

    So what i'm thinking is that if i set a var when the product is added to cart via the ajax system, which is only used for offers, i should be able to store that var with the product id in TABLE_CUSTOMERS_BASKET if they are logged in, or in the session contents if not, and depending upon the value of the var, change the code around line 1083 in shopping_cart.php to reference the alternative price. I'll also need to do the same where it calculates the total etc i suspect, but not looked that far yet.

    Anyone got any better suggestions, or comments on whether or not this is the best way forward (Aimed at ZC team as they know the core better than anyone else.)

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Where is price of product added to cart, or should that be How is it?

    Quote Originally Posted by strelitzia View Post
    From what i can see, it doesn't actually carry an array full of ALL the product data over to the shopping cart, but instead uses $prid to hold the product id, plus some other checks that are made for attributes etc. The details in the cart are then pulled in from the database in includes/classes/shopping_cart.php.
    If i'm right on this, that explains why i can't get the cart to display the correct price, even though the product page does.
    Correct. That's the behavior that was inherited from osC. It will be changed for v2, but for now that's how it works.
    And then that information is passed to the order class during checkout. Both the shopping cart and order class pull the actual price from the database in real time ... not based on any price modifications passed via the URL. To pass modifications via the URL (or your ajax thing or whatever) you'll need to pass a get or post value which you then use to modify the price in those two classes. In some cases you can use custom observer classes to do that, if the necessary notifier hooks exist.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    Dr Byte,
    Thanks for the confirmation on this. At least i know my detective work was correct and that i was looking in the right direction.

  8. #8
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Where is price of product added to cart, or should that be How is it?

    Quote Originally Posted by DrByte View Post
    To pass modifications via the URL (or your ajax thing or whatever) you'll need to pass a get or post value which you then use to modify the price in those two classes.
    I changed this:

    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);

    to this:

    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_draw_hidden_field('g_ad', (int)$_GET['1']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);

    in tpl_product_info_display.php

    I then went to includes/classes/shopping_cart.php and replaced the relevant instances of

    $products_price = $products->fields['products_price'];

    with

    if($_POST['g_ad'] == '1') {
    $products_price = $products->fields['products_price_offer'];
    }else{
    $products_price = $products->fields['products_price'];
    }

    but i still get the normal price displaying in the cart.

    I assume $_POST['g_ad'] isn't showing as '1'

    Any suggestions where i'm going wrong? Do i need to do anything else with g_ad to get it to work?

    Thanks
    Steve

 

 

Similar Threads

  1. Replies: 1
    Last Post: 7 Apr 2013, 02:31 AM
  2. Product unit price doubled when added to shopping cart
    By capncrunch0 in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 13 Nov 2012, 12:48 AM
  3. Questions on how I should set up attributes that would be interdependent.
    By hillebrandts in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 16 Jul 2012, 09:03 AM
  4. text attribute price isn't added to overall price when product added to cart
    By grossd in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 13 Nov 2011, 07:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg