I'd like have a product that is basically a calculator, which I will build in Javascript. I want the add to cart process to grab the generated price from the page and submit it to the cart - which is as far as I have got.
I've created an observer to hook into the checkout_cart_product_add_after event and update the quote item price based on a field value in the submitted form, which works.
The problem I have is that, if you add a second or multiple versions of the item with different prices, it updates all the other versions in the cart to the same price - so you can never have multiples of the same item in the cart with different prices.
Anyone have any ideas? Here's the code in my observer:
public function modifyPrice(Varien_Event_Observer $observer) {
$customprice = $_POST["customprice"];
$item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
if ($customprice > 0) {
$item->setCustomPrice($customprice);
$item->setOriginalCustomPrice($customprice);
$item->getProduct()->setIsSuperMode(true);
}
}
I think the only way to get this working is to dynamically create a new product with a new price or you try to work with attributes which replaces the price, whereas you have to code this logic into your shopping cart as well as in your checkout.
Thank you to McNab, I followed the route of adding custom options to each item added to the cart to overcome the problem with it overwriting the price - which worked perfectly.
Furthermore, I decided to actually grab the options selected on the product page that the JS uses to generate the custom price, and replicate that price generation on the back end based on the selected options. Using the following instructions to add the custom options to the product on the fly, before it's passed to the cart:
Magento - Quote/order product item attribute based on user input
This makes the price calculation much more secure, the selected options are then shown in the cart and order details, and there's no price overwriting issue!
My first question on Stack Overflow and it's hell of a community, thank you all.
Related
I have developed a module for a group of tourist to buy trips in a magento store. During the billing step of the checkout, the user fills the form of other partecipant, and according to the number of partecipants i have to change the quantity(qty) of the product to be bought.So it has to be shown in the review step(last step) in checkout, and the grandtotal has to be calculated according that value.
I have tried all the ways but nothing is useful.Can someone help me please.Thanks in advance!
Your question is pretty unclear to answer, I'll still try my best.
What you can do is write a js wherein on the form submit or probably on a filling a particular field you hit an ajax to a controller with the field or form fields details.
In that controller write the below code:
//get Product
$product = Mage::getModel('catalog/product')->load($pid);
//get Item
$item = $quote->getItemByProduct($product);
$quote->getCart()->updateItem(array($item->getId()=>array('qty'=>$qty)));
$quote->getCart()->save();
Then refresh your reviews. Your order totals should be updated accordingly.
The code below gets the product id at the store
$products = $this->getRequest()->getParam('super_group');
then I would like to get this product stock qty to add in a condition and choose between two phrases and show it in an ajax pop up.
The first frase is: product added correctly to your shipping cart, and the second one is: the stock qty is lower than you want to buy.
I already tried to use magento collection but it doen't work.
If it's necessary i can add more code.
$product->getStockItem();
You can find additionnal information about updating at : https://stackoverflow.com/a/11140724/2660794
Is it possible to add the same product to the basket twice or more times with different prices?
I know how to change the price of product when I add it to the basket using an observer and the event checkout_cart_product_add_after. But right now, when I change the price via the quote item in the observer, all products of this type that are already in the basket get the price of the last item of this type that I added…
When you add the product with the changed price add also this to the item and the product:
$data['c_price'] = 'YOUR CUSTOM PRICE HERE';
$product->addCustomOption('c_price', serialize($data));
$item->addOption($product->getCustomOption('c_price'));
This way the new product shouldn't be merged with the previous one, but if you add the product again with the custom price then it will be merged with the one you previously added with a custom price.
I would like to set some products to "non-saleable", removing the "Add to cart" button and adding a link to contact form.
I'm looking for this solution for a few weeks. Searching, I found this post:
Magento - product that are not for sale
At the end of page have this answer:
""Alternatively, you could set up a new product attribute that replaces the add to cart button with something different (more info button, popup, etc)."
How can I do it?
Another post about this subject:
http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/non-salable-products-with-attribute-sets.php
But I can't make it work. Someone could help me with more details?
small tutorial
Create a new attribute "saleable"
Default Value = yes
Unique value = no
values required = yes
apply to = all product types
use in quick search = no
use in advanced searched = no
comparable on front-end = no
Use In Layered Navigation = no
Use for Promo Rule Conditions = no
Visible on Product View Page on Front-end = no
Used in Product Listing = no
Used for Sorting in Product Listing = no
Manage titles
admin = "Is saleable"
Default store view = "Is saleable"
Now add it to your attribute set (default)
create a product or edit a product and define the is "is saleable" attribute.
Now go to the view of your product
/tomcollins.be/app/design/frontend/default//template/catalog/product/view.phtml
put an if statement like this
<? if($_product->getData('saleable')): ?>
// do what ever you want
<?php else: ?>
// do what ever you want
<?php endif; ?>
Hope this helps someone :)
bye
Modify your product with an Attribute for example nonsaleable. If that Attribute has value true the product is not saleable.
So now you should take a look at the
Productview in app/design/frontend/your_theme/your_theme/template/catalog/product/view.phtml
and the
listview app/design/frontend/your_theme/your_theme/template/catalog/product/list.phtml
Now look where in these files are the addtocart buttons are located.
Before this button you place an if nonsable === TRUE { make something } else { addtocart }
Thats the way i would try this.
Sorry for my bad english. I'm still tired :))))
For all non-for sale products you can set a quantity to 0. It will automatically remove Add to cart. Then you can add link to contact form on all products where add-to-cart doesn't exist. I am coming from Magento Go background so I would do it this way, but I know that with community and enterprise versions you have more flexibility.
I guess you will get your desire requirement through this extension because the developer teams for this extension is really very supportive.Please refer below link for extension:
Click here to get extension
We are selling ready made packs ( total weight 18 kg ) which is include several food products. But we want to make a special thing to our customers which they should make their packs by selecting our product range.
So that, they should make first a base pack with selected products then they can multiply this package in the checkout section.
What I want to do, modify the checkout section of magento to multiply selected products with a text field and calculate total amount by button.
Like in image...
Does anybody help me to make such a thing?
Personally I would do this with frontend code, in prototype. The reason being that you will have to modify your template anyway and your customers will need javascript enabled to get to your cart anyway.
General approach is to have the onclick for your apply button take the id.value for your quantity text box and then update everything with the quantity class in the cart page. Then have this script call the same update url as the standard update quantities button.
Here is my suggestion: in your module you create an observer listening to controller_action_predispatch_checkout_cart_index. In your observer's method you can get the items in cart with $itemCollection = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();. now you just have to loop through this condition and set the quantity:
foreach ($itemCollection as $item) {
$item->setQty(here_the_integer_you_want);
}
edit: sorry, didn't read about the input and button.
For the input and button, you just have to edit the template (app/design/frontend/base/default/template/checkout/cart.phtml). Or, if you want tom make an independant extension, you could add them by an observer. Check out inchoo's post. This form you've just created will call your controller/action, where you can set the items quantity (so no need for an observer anymore), with the same technique I've put earlier.
Let me know if that's not clear.
HTH