Results 1 to 7 of 7

Hybrid View

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

    Default Question for guru to answer please

    When a product is added to cart, if i inspect the element of the add to cart button i see:
    <div id="cartAdd">
    <input type="hidden" name="cart_quantity" value="1"><input type="hidden" name="products_id" value="6"><input type="image" src="includes/templates/template_default/buttons/english/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart "> </div>

    Products id and qty are then, i assume, put into an array that can be read in the classes/shopping_cart.php file

    if i add another hidden field to that so that it has:
    <div id="cartAdd">
    <input type="hidden" name="cart_quantity" value="1"><input type="hidden" name="products_id" value="6"><input type="hidden" name="offer" value="1"><input type="image" src="includes/templates/template_default/buttons/english/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart "> </div>

    where do i need to edit to get "gift" to be added to the array.

    If i am in shopping_cart.php, specifically around line 100, i can use (int)$_POST['offer'] and it knows that it was 1 and i can set a new db field to show it as such in TABLE_CUSTOMERS_BASKET. But, if i try to use (int)$_POST['offer'] in function get_products, around line 1085 so that i can select a different field to populate $products_price var, it is always empty. Why can i get a result from (int)$_POST['offer'] in some places, but not others within the same file?

    If i print_r($this); i see:

    shoppingCart Object ( [contents] => Array ( [27] => Array ( [qty] => 1 ) [181] => Array ( [qty] => 1 ) [6] => Array ( [qty] => 1 ) ) which is a list of product id's and the qty of each. Now, i assume this is populated with each add to cart function, so what i want is to have [offer] added to this array. I haven't found where this array is built so don't even know for sure if i can add my 'offer' flag to it.

    Is that the best way to be able to recall whether or not that product had a value of 1 posted with the add to cart, or is there another way i should be doing it?

    Thanks for any help you can offer.

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

    Default Re: Question for guru to answer please

    Quote Originally Posted by strelitzia View Post
    ...
    where do i need to edit to get "gift" to be added to the array.
    ...
    If I am reading your request correctly you want to do something additional when specific products are added to the cart...

    One way this can be done is by defining extra cart actions. You can do this by creating a file in "/includes/extra_cart_actions/". You can then change the "action" of the submitted form and have your custom code called.

    For example, we can change the form creation line in the template to (fill in "..." accordingly):
    PHP Code:
    if($_GET['products_id'] == 1$my_action 'add_product_with_gift';
    else 
    $my_action 'add_product';

    echo 
    zen_draw_form('cart_quantity_form'zen_href_link(zen_get_info_page($_GET['products_id']), zen_get_all_get_params(array('action')) . 'action=' $my_action$request_type), 'post''enctype="multipart/form-data"') . "\n"?>
    ...
    if($_GET['products_id'] == 1) {
        // Add hidden field w/ gift id (gift_id).
        ...
    }
    ...
    // End Form ?></form> 
    And create a file "/includes/extra_cart_actions/handle_offers.php" (may need some modifications):
    PHP Code:
    <?php
    // Check the action
    if(isset($_GET['action']) && $_GET['action'] == 'add_product_with_gift') {
        
    // Add the gift to the cart
        
    $_SESSION['cart']->add_cart((int)$_POST['gift_id']);

        
    // Add the product
        
    $_SESSION['cart']->actionAddProduct($goto$parameters);
    }
    This should cause the 'add_product_with_gift' code to execute when the product_id is 1. Again this is just some quick sample code and may need some changes... But it should hopefully give an idea of how you can use extra cart actions.
    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

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

    Default Re: Question for guru to answer please

    Thanks lhungil.
    I see the concept of what you are doing there, however, i'm not sure how i can integrate that method. The offer products (there could be 1, 20 or 100 of them) is the same as the normal product, not duplicated to another category, merely given a second price in the products table.

    But, these are added to cart via a different method to standard products, ie via jquery ajax poupup. This popup adds the hidden field of offer value 1.
    That is how the system knows to use the lower price, which displays correctly in the jquery window.
    If the customer is signed in, it adds to TABLE_CUSTOMERS_BASKET correctly, marking it as an offer product, so the value of 1 is working that far, but trying to reference to it when it is needed for calculating cart totals and product price, it doesn't. Unless i can get that offer value of 1 added to the array, i can't see a way forward.

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

    Default Re: Question for guru to answer please

    Quote Originally Posted by strelitzia View Post
    ...
    But, these are added to cart via a different method to standard products, ie via jquery ajax poupup. This popup adds the hidden field of offer value 1.
    That is how the system knows to use the lower price, which displays correctly in the jquery window.
    ...
    So if the customer has javascript disabled, they are not eligible for the offer? Or if the customer's browser freezes while running javascript (and asks to disable javascript) they are not eligible for the offer? Or if the jQuery code has not finished running and the customer clicks "add to cart" the customer is not eligible for the offer? You can see where I am going with this line of questioning :)

    But back on task... You will need a way to differentiate the "offer" product in the database. Then you can modify Zen Cart's pricing code to display the prices you need for the offer... So when the "offer" product(s) are added to the shopping cart they contain the correct pricing.

    You may want to take a look at Better Together. This is a great Zen Cart modification which allows one to configure promotions (such as discounts based upon what is in the cart). Using this you would only need to configure the discount(s) and then add the "offer" product to the shopping cart.
    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

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

    Default Re: Question for guru to answer please

    Quote Originally Posted by lhungil View Post
    So if the customer has javascript disabled, they are not eligible for the offer? Or if the customer's browser freezes while running javascript (and asks to disable javascript) they are not eligible for the offer? Or if the jQuery code has not finished running and the customer clicks "add to cart" the customer is not eligible for the offer?
    I already have a fallback system in place for those where javascript is switched off, or otherwise unavailable.
    The system i have written is pretty much complete and everything works apart from collecting the correct price for the product based on whether or not the 'offer' value is passed as a 1.
    If i can get that value into the array then then i have got the rest of it working as i want.

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

    Default Re: Question for guru to answer please

    Quote Originally Posted by strelitzia View Post
    ...
    The system i have written is pretty much complete and everything works apart from collecting the correct price for the product based on whether or not the 'offer' value is passed as a 1.
    If i can get that value into the array then then i have got the rest of it working as i want.
    Zen Cart processes the "add to cart" action (and other cart actions) separate from any specific page. It then redirects based upon your store settings to the next page (shopping cart page, product page, or reviews page). Key is "redirect". Redirects lose all POST data. It does this right after processing the "cart actions".

    See "/includes/main_cart_actions.php".

    One easy way to keep the POST data from being lost is to create a custom "/includes/extra_cart_actions/do_something_with_my_post_data.php" and add code to do something with your post data (such as storing the data in the database, the session, a cookie, etc). If one stores the data, one can then access the data later (such as the shopping cart page, checkout pages, observers, order_total modules, etc).

    Then you can hack away on "/includes/classes/shopping_cart.php" if absolutely necessary and make use of your stored "offer" data. Depending on your needs, you may be able to avoid this by using an order total module which applies the "offer" (similiar to how the "Better Together" module applies "offers").
    Last edited by lhungil; 24 Jun 2013 at 10:54 PM. Reason: clarification
    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

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

    Default Re: Question for guru to answer please

    Quote Originally Posted by strelitzia View Post
    If i am in shopping_cart.php, specifically around line 100, i can use (int)$_POST['offer'] and it knows that it was 1 and i can set a new db field to show it as such in TABLE_CUSTOMERS_BASKET.
    Line 100 is in the restore_products() function, which is invoked only when customers log back into their account (after logging out) and their saved basket contents are reconstituted into their basket. It has nothing to do with adding products to the *current* basket.
    Quote Originally Posted by strelitzia View Post
    But, if i try to use (int)$_POST['offer'] in function get_products, around line 1085 so that i can select a different field to populate $products_price var, it is always empty. Why can i get a result from (int)$_POST['offer'] in some places, but not others within the same file?
    the get_products() function looks up and returns the array of products IN the cart. But to be IN the cart you need to use the add_cart() function ... which is of course triggered automatically when the add-to-cart process happens ... but if you're not changing the value based on your post data there, then the get_contents() call will still only return the original data that was actually added to cart.
    It's also worth noting that the actionAddProduct() and actionBuyNow() functions are the ones that receive the POST data and evaluate it before calling add_cart() themselves.
    Quote Originally Posted by strelitzia View Post
    shoppingCart Object ( [contents] => Array ( [27] => Array ( [qty] => 1 ) [181] => Array ( [qty] => 1 ) [6] => Array ( [qty] => 1 ) ) which is a list of product id's and the qty of each. Now, i assume this is populated with each add to cart function, so what i want is to have [offer] added to this array. I haven't found where this array is built so don't even know for sure if i can add my 'offer' flag to it.
    See what I just posted.
    .

    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.

 

 

Similar Threads

  1. Simple question, please answer
    By nadinesky in forum General Questions
    Replies: 3
    Last Post: 12 Jan 2010, 10:47 AM
  2. Question for Zen Cart Guru's
    By dcd2008 in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 11 Jun 2008, 01:46 PM
  3. Easy To Answer For Zen Guru...
    By RChenoweth in forum General Questions
    Replies: 5
    Last Post: 17 Apr 2008, 12:36 PM
  4. Question for a MYSQL Guru
    By rickstorm in forum General Questions
    Replies: 3
    Last Post: 31 May 2006, 08:12 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