Jump to content

adding a product with custom fields to cart, using a module.


peorthyr

Recommended Posts

Good day all.

 

I'm developing a module in which the user can configure its own product, everything is worked fine, I save the custom values in the module table, and I display them in a view.

 

now I would like to let the user add a product that takes those custom values.

 

actually I got this:
 

$fieldVal1= "30";
$fieldVal2= "30";
$fieldVal3= "10";
$fieldVal4= "90";
$fieldVal5= "10";
$fieldVal6= "MyTitle";
$fieldVal7= "MyText";
$debug.=" aggiungerei";
// get 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 to 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();

Actually the values are static, just for this example.

 

Please, please, please, don't let me answer my self to this question, it is frustrating.

 

Link to comment
Share on other sites

this place is embarrassing. None of the times I get any kind of help, and many other users have similar problem (having any help).

 

by the way, sorry for my sentence, but it is frustrating.

 

 

talking about solutions, actually, i'm researching over this:

$this->context->cart->addTextFieldToProduct($this->product->id, 13, Product::CUSTOMIZE_TEXTFIELD, "custom Title"); 

 

this, add a new "customization" to the product, it means that knowing the id of this customization, I can then add the product, customized, to the cart. I'm actually figure out how to get this cosutomization id. in the example the number "13" refers to the id of the custom field (i know its id by looking to the customization table group in the db)...

  • Thanks 1
Link to comment
Share on other sites

  • 3 years later...

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...