Results 1 to 7 of 7

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

  5. #5
    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

 

 

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