Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2012
    Posts
    4
    Plugin Contributions
    0

    Default Posting directly to the cart via a new page(script)

    Hi,

    I've created a new page where I wrote the following sql to post directly to the cart

    $sql_cart = "insert into " . TABLE_CUSTOMERS_BASKET . "
    (customers_id, products_id, customers_basket_quantity,
    customers_basket_date_added)
    values ('" . (int)$_SESSION['customer_id'] . "', '".$product_id."', '" .
    "1', '" . date('Ymd') . "')";

    The quantity will always be 1 in my case.

    The script updates the cart correctly in the db, however, I do not see the changes in cart index.php?main_page=shopping_cart unless I logout and log back in.

    Can anyone help?

  2. #2
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Posting directly to the cart via a new page(script)

    The cart that is actually in use is stored in the SESSION variable. If the user is logged in then it is also copied to the database. So, from your point of view adding the product to the session is the critical thing.

    Off the top of my head I can't remember the details but if you put

    Code:
    <?php
    
    print_r($_SESSION);
    
    ?>
    somewhere down at the bottom of the page then you should be able to work out exactly what you need to do.

  3. #3
    Join Date
    Apr 2012
    Posts
    4
    Plugin Contributions
    0

    Default Re: Posting directly to the cart via a new page(script)

    Thanks for the answer.
    I get it but still do not know how to add the product to the session.

    Here is the print out as you suggested.
    is it new_products_id_in_cart?

    Would I need to add $_SESSION['cart']->new_products_id_in_cart = '$product_id'; ?


    Array ( [securityToken] => bcafcdf4b02f791b5fff6bf968faba5a [customers_host_address] => adsl-75-38-108-14.dsl.irvnca.sbcglobal.net [cartID] => [cart] => shoppingCart Object ( [contents] => Array ( [102] => Array ( [qty] => 1 ) [100] => Array ( [qty] => 1 ) ) [total] => 150 [weight] => 0 [cartID] => 27584 [content_type] => [free_shipping_item] => 1 [free_shipping_weight] => 0 [free_shipping_price] => 75 ) [navigation] => navigationHistory Object ( [path] => Array ( [0] => Array ( [page] => logoff [mode] => NONSSL [get] => [post] => Array ( ) ) [1] => Array ( [page] => login [mode] => NONSSL [get] => Array ( [action] => process ) [post] => Array ( ) ) [2] => Array ( [page] => index [mode] => NONSSL [get] => [post] => Array ( ) ) [3] => Array ( [page] => page_4 [mode] => NONSSL [get] => [post] => Array ( ) ) [4] => Array ( [page] => shopping_cart [mode] => NONSSL [get] => [post] => Array ( ) ) ) [snapshot] => Array ( ) ) [check_valid] => true [language] => english [languages_id] => 1 [languages_code] => en [currency] => USD [today_is] => 2012-04-03 [updateExpirations] => 1 [session_counter] => 1 [customers_ip_address] => 75.38.108.14 [customer_id] => 2 [customer_default_address_id] => 2 [customers_authorization] => 0 [customer_first_name] => Cindi [customer_last_name] => Topol [customer_country_id] => 223 [customer_zone_id] => 43 [valid_to_checkout] => 1 [cart_errors] => [new_products_id_in_cart] => 100 )

  4. #4
    Join Date
    Apr 2012
    Posts
    4
    Plugin Contributions
    0

    Default Re: Posting directly to the cart via a new page(script)

    I got it. Thanks for your help

    $_SESSION['cart']->contents['59']['qty'] = 1;

  5. #5
    Join Date
    Jan 2004
    Posts
    66,374
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Posting directly to the cart via a new page(script)

    The approach you're taking is dangerous, since it bypasses proper checks and balances and safety validations, as well as bypasses built-in hooks for plugins that you might be better off using.

    You'd be far better off to use the smarter method of calling $_SESSION['cart']->add_product() or simply giving the customer a suitable button to click to accomplish the same thing (examples the built-in add-to-cart buttons on all the product and product-listing pages).

    But A VERY IMPORTANT THING you've not mentioned here is the WHY behind what you're trying to do. What's so special about this particular page that makes you want to do as you've described? What's the business problem you're trying to solve by using the method you've posted about? Perhaps there are smarter and more efficient ways of accomplishing the same thing that will maybe even survive upgrades easier and be more adaptable to future needs, etc.
    .

    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.

  6. #6
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

    Default Re: Posting directly to the cart via a new page(script)

    What about simple hyperlinks?

    <a href="index.php?main_page=index&action=buy_now&products_id=xxx">ANCHOR TEXT OR IMG</a>
    20 years a Zencart User

  7. #7
    Join Date
    Apr 2012
    Posts
    4
    Plugin Contributions
    0

    Default Re: Posting directly to the cart via a new page(script)

    What I'm trying to is give users an option to buy a swimming lessen for their children. This is divided to categories and levels.
    Each child can only have one.
    The children's names come from a different db.

    Once they add the activity(product) to the cart I let zen do the rest.

    Is there a better way to do this? What would you suggest?

  8. #8
    Join Date
    Jan 2004
    Posts
    66,374
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Posting directly to the cart via a new page(script)

    Have you looked at Product Attributes yet?

    There's a lotta options you can give to your customers directly within a product: http://www.zen-cart.net/index.php?ma...products_id=34

    Ref: https://www.zen-cart.com/tutorials/index.php?article=57
    .

    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. v139h Group pricing: how to show the discounted price directly in the product page?
    By ilmarchez in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 20 May 2015, 11:04 PM
  2. Adding the Shopping Cart Contents Directly On The Product Listing Page
    By watzursn in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 12 Sep 2008, 12:18 AM
  3. Placing a link directly on the Main Page
    By wwwursa in forum General Questions
    Replies: 6
    Last Post: 1 Aug 2008, 12:45 PM
  4. how to add new side box to redeem the gift voucher directly?
    By webdevelopex in forum Addon Sideboxes
    Replies: 3
    Last Post: 24 Jun 2006, 05:27 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR