I want to add products automatically to my magento cart.
The situation is I have product Y and it needs extra components to be assembled, so I want that the assembly parts to be added automatically to the cart when product Y is added.
I have googled a lot and could only find extensions for promotion product and free gifts but I need a solution which just adds the product to the cart and that it adds in the same quantity of product Y.
Are there extensions which I can use or how can I alter my code to get my desired behaviour?
You can use that kind of extension or make you own with a listener on the sales_quote_item_set_product event to check if the product added is yours and need a new product to be added.
I had a similar request that was abandonned as it is illegal in France (and in most of the part of Europe) to sell a product linked to another and that was not requested. Moreover, the customer can already have this second product and do not want it. We added a popup that said which products can be needed with this one. This second part is just an advice.
Well, if you looking programming solutions:
Write Custom module that observe event checkout_cart_add_product_complete.
In your observer, add products by following code.
The code is:
$prouctToAdd = Mage::getModel('catalog/product')->load('product_id ');
$qty = 'currently_added_produt'
$cart =Mage::getSingleton('checkout/cart');
$cart->addProduct($product, array('qty'=>$qty));
$cart->save();
Related
When I am going to add custom price to cart item by below method in checkout_cart_product_add_after Observer and it's works fine but when I am going to change currency from cart then value not converted as per rate so any other way to add custom cart item price to cart.
$customPrice = $getSlectedAttrOptions['current_price'];
$item->setCustomPrice($origCustomPrice);
$item->setOriginalCustomPrice($origCustomPrice);
$item->getProduct()->setIsSuperMode(true);
Please take a look at this:
https://github.com/magento/magento2/issues/12493#issuecomment-352038477
It seems that custom price is used only in admin area and no currency change is taken into account.
You could try this or this (not helpful in my experience, and editing core files is not our best).
Is it possible, in Magento, to build a button to add a new simple product while creating an order in the backend?
It is not important that the product would be saved in the catalog: it should to be saved into the order. Only two of the product's attributes would be needed: name and tax rate (optionally others). Qty e price could be edited from the order cart.
Yes, it's posible, you need a controller in order to do that.
Remember that you need to provide us the code that you're working on, and don't expect that we program all for you.
Thanks
Thanks to Beto Castillo I went into the spirit to think more clearly about this. The project is yet under construction. Anyway starting steps could be:
Create the right inputs to add a new product in a ChildHtml of sales/order/create/data.phtml, and adjust the layout files. Along with the inputs there will be a button to trigger the creation of the product. In one of this inputs I have to load options for tax rates.
There is plenty of ways to create a new product, i.e. Magento: Adding new products programmatically. I just need to get the above inputs.
The product should be added to order quotes in the database (I could start with this: Create order programmatically in Magento)
Update the create order view, calling an ajax function to reload the item grid. Part of the code already exists in Magento. All this steps should be packed into the same ajax call: here comes the controller action named by Beto Castillo.
So the answer is yes, it is possible.
After searching on Google for quite a while I am going crazy.
My question: Can you configure Magento to require a coupon code to buy specific product?
This is for a promotion my employer is running, basically we want to allow specific customers to buy specific product in our Magento store before any of our other customers. Thank you for your suggestions.
A brief idea I can give here.
Create a backend module, which has own db tables to save linking of products ID to specific coupon, multiple coupon or just a check that coupon is required, depending on your case. From this Module you should be able to define such linking of product to coupon.
Since customer apply a coupon code at cart page, so we will let customer add product into cart. Then edit isDisabled method of Mage_Checkout_Block_Onepage_Link class. where you will check if your quote has any product from the product-coupon linking defined in your module and coupon is not applied yet. Similar thing you can should do for Multishipping method if it is enabled in your Magento. So whenever coupon coupon code will be applied page will refresh and button will get enabled.
Same check you will need to put in indexAction of Mage_Checkout_OnepageController.
I am looking for a way adding a product to cart without display it.
Example:
New customer order -> welcome letter in the cart, but the customer doesnt see it.
The added product cost always 0 €, so it never changed the shopping cart total.
The solution should be changed as few as possible.
Any idea?
Thank you!
(Sorry for my very bad english...)
I would say to change the formulation a bit and add it to the order just before the order is saved. While the quote is being converted into an order (sales_model_service_quote_submit_before is one good event here, but there are others), add the product to the order.
This way, you don't have to hack around trying to hide items in the cart, and the effect is the same.
Two options:
Define a new product type that extends the Virtual product type in Magento, and then use a custom Item Renderer for Checkout and Cart that doesn't output any html. Here's a useful tutorial for that process.
Define a new boolean product attribute called "cart_visibility" or something like that, override DOCROOT\app\design\frontend\base\default\template\checkout\cart\item\default.phtml in your own theme and test for that value before outputting the item's attributes e.g. on line 28:
<?php if($_item->getCartVisibility(){ ?>
Don't forget to close the brace at the end of the file obviously.
if it's 0 then why add it to the cart just add it as a message to cart page by adding it to cart template or injecting your own block to this template
I have one certain product that needs to be in the cart under certain circumstances. I have been looking at the Ubercart api documentation and I don't see any hooks that would be the obvious place to see if a certain item exists prior to checkout.
I could use the hook_add_to_cart hook to add the special item whenever the first item is added, but I'm concerned that the visitor may remove the item and then complete the purchase without the required item.
Any suggestions how to make sure the special item is in the cart on checkout?
You can have a module and run something like:
function mymodule_init() {
if (preg_match('/checkout/', request_uri()) {
$items = uc_cart_get_contents();
foreach ($items as $item) {
// code
}
}
}
That will fire up on the checkout page, and fetch the cart contents. Everytime they hit the checkout page, uc_cart_get_contents() returns the cart contents.
http://www.ubercart.org/docs/api/uc_cart_get_contents
There are probably better ways to do what you want to do though, like using a Conditional Action to prevent checkout if Item B is in the cart but Item A is not. You can also look at Product Kits, but I don't have much experience with that.
From what you have said it sounds as though the product kit module might be very much worth looking into as a way of ensuring any items associated with the main product are kept in the cart.
Product kit comes as part of ubercart and you will find it on the modules page under 'Ubercart - extra'. If this is no good then we can see about using the API :)
An old question, but I found a great solution.
hook_uc_cart_item_delete() functions specifically on certain entities when they are removed. You can just set this hook in your module, check for the specific entity being removed that is dependent on the other item, and then use uc_cart_remove_item() on the item you want to remove.