• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: sandwichbar online order website
PostPosted: Mon Mar 19, 2018 2:02 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 26, 2012 3:22 pm
Posts: 225
Location: Belgium
Hi,
I would like your feedback on this:

i need to make a online order website for a company that makes sandwiches.
they want this to speed up the queue they have in front of their shop every noon.

i've been looking at the modules "product" & "cart2" the last 2 days, but was unable to set it up orders with different options (except with SKU codes which they don't have).

For example people want to order a ham cheese sandwich with extra pickles as topping for Tom and 1 ham cheese sandwich with mayonnaise for Linda.

Within the product detail page they should be able to select some options and add it to the cart. (options do change the price).

No need for shipping, taxes or online payments for this shop.
But i would like to use FEU.

What do you think? Will this work with the above mentioned modules or do i need to build my own shopping cart??

_________________
Kind regards,
HarmO


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Tue Apr 10, 2018 8:59 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 26, 2012 3:22 pm
Posts: 225
Location: Belgium
Ok, i made a simple shopping cart UDT that adds my items into the session variable shopping_cart (see code below).

Now the only thing i'm struggling with is this: i want to check if the description tag of a newly added product is different from an existing product line so i can add twice the same product, but with different descriptions... (example ham sandwich on white bread and ham sandwich on brown bread.)

Code:
if(isset($_POST["cartaction"]) and !empty($_POST["cartaction"]))
{
   switch($_POST["cartaction"]){
      case "add":
         if(isset($_SESSION["shopping_cart"]))
         { 
            $item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
            if(!in_array($_POST["itemID"], $item_array_id))
            { 
               $count = count($_SESSION["shopping_cart"]); 
               $item_array = array(   
                  'item_id'         =>     $_POST["itemID"], 
                  'item_name'         =>     $_POST["name"],
                  'item_details'      =>     $_POST["details"],
                  'item_price'      =>     $_POST["price"], 
                  'item_quantity'      =>     $_POST["quantity"]
               ); 
               $_SESSION["shopping_cart"][$count] = $item_array; 
            } 
            elseif(in_array($_POST["itemID"], $item_array_id))
            { 
               $cart_item = array_search($_POST["itemID"], $item_array_id);
               $_SESSION["shopping_cart"][$cart_item]['item_quantity']= $_SESSION["shopping_cart"][$cart_item][item_quantity]+$_POST["quantity"];
            } 
         } 
         else
         { 
               $item_array = array( 
                  'item_id'         =>     $_POST["itemID"], 
                  'item_name'         =>     $_POST["name"], 
                  'item_details'      =>     $_POST["details"],
                  'item_price'      =>     $_POST["price"], 
                  'item_quantity'      =>     $_POST["quantity"] 
               ); 
               $_SESSION["shopping_cart"][0] = $item_array; 
         }
         break;
      case "eddit":
         $_SESSION["shopping_cart"][$_POST["cart_item"]]['item_quantity'] = $_POST["quantity"];
         break;
      case "remove":
         unset($_SESSION["shopping_cart"][$_POST["cart_item"]]);
         $_SESSION["shopping_cart"]=array_values($_SESSION["shopping_cart"]);
         break;
   }
}

_________________
Kind regards,
HarmO


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Tue Apr 10, 2018 9:09 am 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 2929
Location: The Netherlands
I don't see a description tag in your code.

I think it might be possible to make a hash of the description and use it as the key for the array:

$_SESSION["shopping_cart"][YOUR_HASH_VALUE] = $item_array;


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Tue Apr 10, 2018 1:02 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 26, 2012 3:22 pm
Posts: 225
Location: Belgium
Sorry, my descriptiontag is $_POST["details"].

_________________
Kind regards,
HarmO


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Tue Apr 10, 2018 1:06 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 2929
Location: The Netherlands
Then you might use that to create the hash.

One warning: never trust user input. Those $_POST variables are user input so be careful to check their values before further processing.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Tue Apr 10, 2018 1:55 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 26, 2012 3:22 pm
Posts: 225
Location: Belgium
I was counting on sanitizing the user input, no worries there.
i see where your getting at, but in my case the check should now be on the combination of 2 variables: $_POST["itemID"] and $_POST["details"].

I'm not realy a PHP programmer so if i just can do the check in this part, i don't have to reorganize my cart's mechanism for the keys, nor do i need to redo my cart template ect.
Code:
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
//check if already in cart
if(!in_array($_POST["itemID"], $item_array_id)) //not in the cart yet?
{
    add to the end of the cart
}
else{
    Modify line in cart
}

_________________
Kind regards,
HarmO


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: sandwichbar online order website
PostPosted: Mon Apr 16, 2018 10:05 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 26, 2012 3:22 pm
Posts: 225
Location: Belgium
I made it work with the hash, thanks for the idea Velden.

will be posting details after i finished up the project.

_________________
Kind regards,
HarmO


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting