Jump to content

Create a new cart and add products in it


Xtense

Recommended Posts

Hi there,

 

I'm new around here and I'm working with Prestashop for like two weeks. I was not even very familiar with OOP and I had barely heard of MVC (you got it, I'm not a pro programmer, I'm more like a guy who wanna do everything on his own). But I browsed a lot of documentation.

 

So I became familiar with OOP, MVC, Smarty and Prestashop modules (well familiar is a huge word I have to admit it :P).

 

Now I'm trying to adapt a tool I've been working on, you can find it here (oh French is my mother language, it's pretty intuitive though, and please god I know it lacks of Ajax, or transitions effects but come on guys it'sn ot over ^^) : hmastery.com/greativity/test

It's a tool allowing you to personalize some items with your own photos :)

 

So basically what I wanna do is when I click on save ("Enregistrer" in French on top right corner). I'd like to create a new cart if there's not one yet. So I tried using :

 

 

$cart_id = $this->context->cart->id;
/* Create a cart if there's no existing one yet */

if (empty($cart_id)){
$this->context->cart->add();
}

 

But it keeps creating a new one on without understanding my condition.

 

Once I got my cart, I'd like to add product in it, and oh my god, I've read the entire Cart.php class and I didn't find any suiting method.

 

Also I'm trying to store the personalized thing into customization, but I have understood almost everything except how to send the customized_data value. The following method :

 

 

public function _addCustomization($id_product, $id_product_attribute, $index, $type, $field, $quantity, $customization_value)

 

 

Sets it using this thing :

 


$query = 'INSERT INTO `'._DB_PREFIX_.'customized_data` (`id_customization`, `type`, `index`, `value`)
VALUES ('.(int)$id_customization.', '.(int)$type.', '.(int)$index.', \''.pSql($field).'\')';

 

And I don't know how to generate : pSql($field)

 

So there I am, hitting my head against my keyboard, spending my entire night crying all alone in the dark (just kidding I'm living in Paris).

 

Anyway, if someone can give me some help. I'm pretty sure some of you guys already tried to handle customization and cart basic features :)

 

/thanks you're awesome !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...