php - prestashop: adding a product to cart, with custom fields -
good day all.
i'm developing module prestashop, in user choose settings, , possible save these settings , add custom product cart, using them values custom fields.
i've added new product, 7 custom text fields.
then i've write in php of module, in function add product in cart:
$debug.=" aggiungerei"; $fieldval1= "30"; $fieldval2= "30"; $fieldval3= "10"; $fieldval4= "90"; $fieldval5= "10"; $fieldval6= "mytitle"; $fieldval7= "mytext"; // cart id if exists if ($this->context->cookie->id_cart) { $cart = new cart($this->context->cookie->id_cart); $debug.=" 1.nuovo carrello"; } else { if (context::getcontext()->cookie->id_guest) { $guest = new guest(context::getcontext()->cookie->id_guest); $this->context->cart->mobile_theme = $guest->mobile_theme; $debug.=" 2.carrello"; } $this->context->cart->add(); if ($this->context->cart->id) { $this->context->cookie->id_cart = (int)$this->context->cart->id; $debug.=" 3.carrello"; } } //add cosutm fields values [todo] // add product cart $cart->updateqty(1, 39, null, (int)($customization), tools::getvalue('op', 'up')); $prods = $cart->getproducts(true); print_r ($prods[0]['id_customization']); // update cart $cart->update();
in example have static values custom fields, in real module, these values taken database.
i can't figure out how cart product must have custom fields populated values @ beginning of script... can lead me in right direction?
i've started example, founded here: prestashop: add customized product cart
the code work this:
$this->product = new product(39, true, (int)($this->context->cookie->id_lang)); if (!$field_ids = $this->product->getcustomizationfieldids()) return false; $this->context->cart->addtextfieldtoproduct($this->product->id, 7, product::customize_textfield, $titolo); $this->context->cart->addtextfieldtoproduct($this->product->id, 8, product::customize_textfield, $testo); $this->context->cart->addtextfieldtoproduct($this->product->id, 9, product::customize_textfield, $miscela1); $this->context->cart->addtextfieldtoproduct($this->product->id, 10, product::customize_textfield,$miscela2); $this->context->cart->addtextfieldtoproduct($this->product->id, 11, product::customize_textfield, $miscela3); $this->context->cart->addtextfieldtoproduct($this->product->id, 12, product::customize_textfield, $miscela4); $this->context->cart->addtextfieldtoproduct($this->product->id, 13, product::customize_textfield, $miscela5);
for luckyness, know ids of custom fields (i've taken @ custom fields table on db).
Comments
Post a Comment