Jump to content

Ordering System {cart}


mohamed.khamis

Recommended Posts

Hi guys,

I started coding php last July.. But I think I got a grasp of most of the basics already

 

I am making an ordering system in a website, for now I just want to add items to my cart

I was trying to use MVC, I'm beginning to think that it was a bad idea  :D unless I use a framework

 

Now I implemented a model for the Order, and another for OrderItem,

the Order contains a list of orderItems (an array) which is initialized in Order's constructor.

 

My plan was to create an OrderItem for each product ordered, and add it to the Order's orderItems array. While the Order is saved in the session.

 

There are two problems occurring,

1. First I wanted to store the Order instance in the session, So I was trying this:

 

if (!isset($_SESSION['order'])) {
    $order = new Order();
    $_SESSION['order'] = $order;
}

 

but then I get this error:

Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Order" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\wamp\www\Orders\View\add_order_item.php on line 19

 

Apparently the problem is with using the isset function..

 

2. The other problem (occurring even if I create a new instance of the Order every time)

is when displaying the content of the array.. it is always empty ! !

$order = new Order();
$_SESSION['order'] = $order;
$order_item = new OrderItem();
$order_item->setOrder($_SESSION['order']);
$order_item->setDeliveryDate($_POST['date']);
$order_item->setStatus(getOrderStatusById(strtolower($_SESSION['type']) == 'c' ? (isset($_POST['submit']) ? 3 : 2) : 4));
$order_item->setAmount($_POST['amount']);
$order_item->setProduct(getProductById($_POST['product']));
$order_item->setPrice(-1);
$order_items_array = $_SESSION['order']->getOrderItems();
array_push($order_items_array, $order_item);
//$order_items_array[] = $order_item;
$_SESSION['order']->setOrderItems($order_items_array);
//TODO google for that: the problem is that an array belonging to an object, in the session.. cannot be filled !
$page_title = 'test';
require_once ('../../Util/header.php');
$product = $order_item->getProduct();
$order_list = $_SESSION['order'];
echo $order_item->getDeliveryDate().'  '.$product->getName().'  '.$_SESSION['order']->getOrderItems().'  '.$order_items_array;
require_once ('../../Util/footer.php');

 

Any help would be appreciated

Thanks in advance  :)

Link to comment
https://forums.phpfreaks.com/topic/175644-ordering-system-cart/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.