Jump to content

Add product from my custom module code


Recommended Posts

I need to add some products to cart from my custom module and i have used the following code

  $productToAdd = new Product(1, true, (int)($this->context->cookie->id_lang));

/* Select the cart */
              $cart = $this->context->cart;

/* Select the product */
               $product = new Product($idProduct, true, (int)($this->context->cookie->id_lang));
               $id_product_attribute = Product::getDefaultAttribute($idProduct);
               print_r($id_product_attribute);
               $cart->update();
/* Add to cart */
                $cart->updateQty(1, $idProduct, $id_product_attribute, 0);

and is working.

I want to do the following thing also

1. need to display a custom attribute like a prename  along with the product in view cart page

eg: if my product name is test i need to display it as MY test in show cart page. How can i do that with the above line of code. how can i add a custom attribute for that using code and display the same in show cart page along with each product.

2. while adding same product to cart it should be displayed as a separate product rather than updating quantity to 2.

eg : if iam adding product "A" to cart for the second time it should be displayed as two boxes of product data in view cart page.

 

 

 

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