Hi,
I have a controller
public function products_cart()
{
$product = new Products( $this->db );
$basket = new \Basket( '
shop_cart
' );
if($this->f3->exists('POST.id'))
{
$id = $this->f3->get('POST.id');
$amount = $this->f3->get( 'POST.amount' );
$basket->set( 'product_id', $id );
$basket->set( 'product_amount', $amount );
//I get price from model
$total_db_price = $product->GetBasketTotalPrice( $id, $amount );
$basket->set( 'price', $total_db_price );
$basket->save();
$basket->reset();
}
if( $basket->count() > 0 )
{
$result = $basket->find();
print "<pre>";
var_dump($result);
print "</pre>";
This is the result
array(3) {
[0]=>
object(Basket)#10 (3) {
["key":protected]=>
string(9) "shop_cart"
["id":protected]=>
string(23) "54461bb610e9c5.00404527"
["item":protected]=>
array(3) {
["product_id"]=>
string(1) "1"
["product_amount"]=>
string(1) "1"
["price"]=>
float(255)
}
}
[1]=>
object(Basket)#11 (3) {
["key":protected]=>
string(9) "
shop
_cart"
["id":protected]=>
string(23) "54461bbccef307.95145353"
["item":protected]=>
array(3) {
["product_id"]=>
string(2) "14"
["product_amount"]=>
string(1) "1"
["price"]=>
float(479)
}
}
[2]=>
object(Basket)#12 (3) {
["key":protected]=>
string(9) "
shop
_cart"
["id":protected]=>
string(23) "54461c03913161.38059218"
["item":protected]=>
array(3) {
["product_id"]=>
string(1) "1"
["product_amount"]=>
string(1) "1"
["price"]=>
float(255)
}
}
}
}
die;
}
I need help to make total price from 3 product or total amount of products or explanation how to loop through Basket object and the insert items in table basket.
Is this the right way to do?
Thank you in advance