Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Sep 2007
    Posts
    58
    Plugin Contributions
    0

    Default trying to create an extra cart action

    Hi all,

    Sorry if you've seen this question before. I think I picked the wrong thread when I first posted it.

    I'm trying to add an extra cart action that will allow my visitors to update the parameters assigned to a product after it is already in the cart. At the moment, they have to delete it and add it again.

    My goal was to keep this as simple as possible, so while I'm sure there are better ways of doing this, what I have done is this
    1. Create a new page that just shows the product and the attribute controls.
    a. This is just a copy of product_info_display with the unwanted bits deleted.
    b. I've also copied the required language and modules/pages files
    c. Added an "update" button that calls my new action (see 3)

    2. Put a new link in the shopping cart from the attribute fields to my new page

    3. Create an extra cart action called update_product_attributes in the extra_cart_actions directory.

    1 and 2 are working OK, but 3 is a problem. I had just planned to make my extra action do a delete of the current product and add a new instance with the updated parameters. I went for this plan because it would use existing functions delete and add functions. My extra_cart_action looks like:
    Code:

    if ($_GET['action'] == 'update_product_attributes') {
    /* how do I remove the existing product with the old attributes??? */
    $_SESSION['cart']->actionAddProduct($goto, $parameters);
    }

    Any pointers that you could give would be greatly appreciated.

    Thanks,

    Possum

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: trying to create an extra cart action



    you're a few hours too late, or in luck, depending upon how you're felling about this. Here's why.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Sep 2007
    Posts
    77
    Plugin Contributions
    2

    Default Re: trying to create an extra cart action

    yes, Kuroi is right. I have just uploaded a mod that does almost exactly what you want done and in pretty much the same way.

    I am pretty much scratching my head as to how we could have been both making the same mod on the same day, and a mod that until now doesn't seem to have been made.

    Anyway there is a cart class function called remove. If you use that then your item will be removed from the cart. My code looks like this:
    Code:
    // intercept add_product actions if the edit_item_id paramater is set, 
    //remove that item from cart, and proceed to add it again
    if (($_GET['action'] == 'add_product') && isset($_POST['edit_item_id']) ) {
    	$_SESSION['cart']->remove($_POST['edit_item_id']);
    I passed in a separate paramater from the product_info page, edit_item_id, which the above code checks for.

    I noticed that it was possible to tell from the product_id on the product_info page if it had been referred by the shopping cart page. So I did not change the shopping cart at all.

    Anyway have a look at my module "Edit Cart," available from downloads page. And you will see how I did it anyway.

  4. #4
    Join Date
    Sep 2007
    Posts
    58
    Plugin Contributions
    0

    Default Re: trying to create an extra cart action

    you're a few hours too late, or in luck, depending upon how you're felling about this
    Definitely in luck! Thanks justin (and kuroi). Not sure if it's a matter of great minds thinking alike, but definitely good news for me.

    I'll go and check it out now.

    Possum.

  5. #5
    Join Date
    Sep 2007
    Posts
    77
    Plugin Contributions
    2

    Default Re: trying to create an extra cart action

    Hi Possum

    I am going to continue my thoughts on this, in this thread. Because the other thread is really for Edit Cart mod specific enquiries.

    Some really useful thoughts on alternative approaches to my gift wrapping problems. Thanks. FYI, I'm selling children's books, so you're right that the wrapping is not truly an attribute of the product itself.

    In short I think the challenge is that there is no wholly satisfactory way of doing gift wrapping at the moment. Attributes have the problems that you have stated above. Products suffer from the fact that the additional "gift wrap" product can't actually be connected to the book(s) that are to be wrapped. This would stop someone from ordering a book for themselves plus a book as a gift because i wouldn't know which book or books were supposed to be wrapped.

    The Cross Sell and Better Together mods provide the option to offer the gift wrapping, but lose the connection once the products are in the cart.

    The Gift Wrapping mod (which I'm using) does nice things with offering flexible pricing options and separates the gift wrapping costs from the books themselves, but it is based on attributes, which again has the compromises you have mentioned.

    BTW, Amazon inserts an optional extra page in the checkout process where you assign wrapping options to each book.

    I note Dr Byte's concerns about removing the safeties. Assuming that I can figure out how, I was planning to update the logic so that it queried whether there were any mandatory attributes, rather than just looking for any attributes.
    Actually I think you should heed Dr Bytes concerns. For 2 reasons,
    i) You are going into uncharted territory and it is sure to be frustrating work
    ii) I don't think you need to go into that area.

    I don't think you need to because the method I suggested will probably do the same job, for far less coding and with far fewer hidden gotchas.
    I would change the code for the buy now button on the product listing page. How about changing it such that it submits the same information as the add_product action of the cart_quantity form on the product info page? You would need to hard code hidden parameters for the quantity, gift wrapping attribute at least, into the buy now button code.
    Also I still feel you may be unnecessarily complicating your requirements. It may be that some users will combine books that require gift wrapping and books that do not in the same order. But these will surely be an exception to the main. My guess is that you are in a hurry to get this ready for Xmas. (We all are)

    Managing exceptions is always problematic, and it will slow you down. If the number of exceptions is not excessive, the value of the lost sales before you go live, and amount of your dev. time may not warrant trying to manage exceptions programmatically. In this case, I would advise your customers to make 2 orders, one for the gift wrapping package (which may have a different shipping address anyway) and one for the non gift wapping books.
    If that is not acceptable somewhere in the gift wrapping product description, explain that if they want some books gift wrapped and others not gift wrapped, they should note this in the notes area of the checkout process.

    Justin

  6. #6
    Join Date
    Sep 2007
    Posts
    58
    Plugin Contributions
    0

    Default Re: trying to create an extra cart action

    Hi Justin,

    Thanks for taking the time to respond.

    Actually, you were all right and I was wrong

    I went back into the gift wrapping mod thread and found that swguy has made a major release change. I haven't tried to install it yet but it looks like it does everything I want.

    My PHP is definitely not up to "major uncharted territory" as you put it.

    And again, congrats and thanks on the edit cart mod. I'm sure you'll find a LOT of people who'll love it.

    Cheers,

    Possum.

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: trying to create an extra cart action

    Quote Originally Posted by possum View Post
    I went back into the gift wrapping mod thread and found that swguy has made a major release change. I haven't tried to install it yet but it looks like it does everything I want.
    I was never satisfied with the "attribute" based solution of Release 1 - I think you'll like Release 2.

    Good luck,
    swguy
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  8. #8
    Join Date
    Mar 2010
    Posts
    3
    Plugin Contributions
    0

    Default Re: trying to create an extra cart action

    I have been trying to do something related (I think) but slightly different. In the shop I'm working on, some of the products are associated, and need to be bought as a 'bundle'. I also need the products to be removed from the cart as a bundle, so that if the shopper removes any one item of a bundle, it removes all associated items of that bundle. I believe it has to be this way, since I wish to keep stock level of the components of each 'bundle'.

    I aim to achieve this by adding a custom cart action bundles.php in /includes/extra_cart_actions/ with the following effects

    1) When adding bundles to the cart, the extra cart actions will generate a unique bundleId and write this id into a text attribute (bundleId) for each product in the bundle, thereby making it possible to identify which products belong to which bundle.

    2) When removing an item from the cart, the extra cart actions will search the attributes of each product in the cart, and remove those products which have the same bundleId.

    3)When modifying the quantity of an item in the cart, the extra cart actions will search the attributes of each product in the cart, and make the same quantity modification for each item with a matching bundleId attribute.


    Bundles are being added to the cart perfectly well, however I am having no luck at all trying to set and get attributes of the cart contents form within the extra_cart_actions/bundles.php. My plan hinges on this, and I'm totally stumped.

    I've been trying all sorts of variations on :-

    $_SESSION['cart']->contents['$productId']['attributes_values']['bundleId'] = 'someId';

    None of which actually seem to affect the bundleId attribute value.

    Pehaps I'm barking up the wrong tree

    Any ideas would be much appreciated.

    John

  9. #9
    Join Date
    Jan 2007
    Posts
    1,483
    Plugin Contributions
    10

    Default Re: trying to create an extra cart action

    Quote Originally Posted by johnofyork View Post
    I have been trying to do something related (I think) but slightly different. In the shop I'm working on, some of the products are associated, and need to be bought as a 'bundle'. I also need the products to be removed from the cart as a bundle, so that if the shopper removes any one item of a bundle, it removes all associated items of that bundle. I believe it has to be this way, since I wish to keep stock level of the components of each 'bundle'.

    I aim to achieve this by adding a custom cart action bundles.php in /includes/extra_cart_actions/ with the following effects

    1) When adding bundles to the cart, the extra cart actions will generate a unique bundleId and write this id into a text attribute (bundleId) for each product in the bundle, thereby making it possible to identify which products belong to which bundle.

    2) When removing an item from the cart, the extra cart actions will search the attributes of each product in the cart, and remove those products which have the same bundleId.

    3)When modifying the quantity of an item in the cart, the extra cart actions will search the attributes of each product in the cart, and make the same quantity modification for each item with a matching bundleId attribute.


    Bundles are being added to the cart perfectly well, however I am having no luck at all trying to set and get attributes of the cart contents form within the extra_cart_actions/bundles.php. My plan hinges on this, and I'm totally stumped.

    I've been trying all sorts of variations on :-

    $_SESSION['cart']->contents['$productId']['attributes_values']['bundleId'] = 'someId';

    None of which actually seem to affect the bundleId attribute value.

    Pehaps I'm barking up the wrong tree

    Any ideas would be much appreciated.

    John
    It would be helpful if you posted the bundle.php file to look at the code to see what's going on.

    Zen Cart and it's community are the best!!

  10. #10
    Join Date
    Mar 2010
    Posts
    3
    Plugin Contributions
    0

    Default Re: trying to create an extra cart action

    Thank you for taking the time out to reply LankeeYankee,

    My bundle.php is in a state of flux at the moment, as I try out different ways of accessing and mutating the attributes values. I seem to be having some luck using the function
    [FONT="Courier New"]
    $_SESSION['cart']->get_products()[/FONT]

    as this returns an array of product details of the products in the cart. I'm still experimenting with this, and am hoping it might lead me to a way to access and also mutate the attributes within the cart.

    I'll post bundle.php when it is in better shape (its terribly hacky at the moment, probably like my approach ...)

    Unfortunately php isn't a langage I've used much. That in conjunction with getting to know the zen cart architecture, is having me digging holes all over the place :-) I'm sure there must be a 'right' way to access and mutate cart contents (including attributes) from within an added extra_cart_actions script, but its eluding me.

    I will of course post my findings when/if I work this out, or hopefully someone will point me in the right direction.

    Kind regards,

    John

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Create extra upload page after adding to cart
    By arjanschip in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 27 Jan 2013, 12:01 AM
  2. Stumped trying to move "Your Cart is Empty" beside "Create Account"
    By sophie666 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 28 Feb 2012, 12:02 AM
  3. Adding an extra cart action ... help needed!
    By possum in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 18 Nov 2007, 12:36 PM
  4. Extra! Extra! Zen Cart Owners Manual Available!
    By Kim in forum Zen Cart Release Announcements
    Replies: 0
    Last Post: 10 Feb 2007, 04:45 PM
  5. Trying to rename extra pages
    By Aranea in forum General Questions
    Replies: 7
    Last Post: 24 Oct 2005, 08:14 AM

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