Access stock qty - magento

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

Related

Limit cart to 1 product per attribute/type - Magento

Our company sells pharmaceuticals online and by law we are limited to how much of a particular drug a customer can purchase.
For singular products with one brand this is easily controllable through default Magento functionality, my problem arises when we have different brands of a particular drug.
In a nutshell I can currently limit a customer to 1 pack of paracetamol from brand A but there is nothing to stop them getting another pack from brand B at the same time.
I would like to be able to check the cart for products with a particular attribute and limit them to 1 per cart. Ideally this would be when the customer clicks add to cart and the message would be displayed via the default Magento alerts that we currently have.
EDIT: I think the easiest way to solve this would be to check the SKU codes currently in the basket when adding a product to the cart. If there is a match, Throw up an error else add the item to the cart.
I think this link will help you but you need to modify as per your requirement. http://ceckoslab.com/magento/magento-check-if-product-is-in-cart/..
This link is to check the cart whether the same product is added or not? So modify this as per you requirement
You can set maximum allowed quantity in cart from admin panel. System->configuration. From left tab see catalog->inventory. Set Maximum qty allowed in shopping cart to 1.
If you want to add check on whole cart. see this paid extension

Same product in basket twice with different prices - magento

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.

Magento Qty Increments

Basically all my products in magento are single units, however everything is sold in packs say 10 units to a pack. Theres the Enable Qty Increments on the product options in Magento and then you enter the Qty increments, which works without problems. However by default when you go to the product on the front end, hit add to cart it tries to add just 1 unit not the minimum of 10 is there a way, when you hit add to cart it adds the minimum qty of 10 rather than 1?
I know this is a while after you posted the problem & you probably have a fix already..
We are looking at this problem ourselves.. & have an issue with Bundled products not allowing us to add more than one instance of the product on each page.. hard to explain..
What I am thinking to do is remove the quantity box from the actual product.. Customers can select in a drop down if they want packs of 5 - 10 - or singles.. if they require odd numbers they can adjust the number still in the checkout..
does that all make sense..
Add to cart & Qty box are on the products.phtml page i think... I am still looking at all my options though.. Setting up a selection of Grouped products at the moment..
Just a passing suggestion ;)
Edit.. // What we have done as a final solution.. Use // Promotions /
Shopping Cart Rules.. You can make specific rules for Bulk categories
& Products in set numbers.. This will be a lot easier for our staff to
manage.. just drop requested products into a category called "bulk"
..wish I had thought of it earlier :)
In Admin panel go to
System >> Configuration >> Catalog >> Inventory >> Product Stock Options and set Qty Increments to what you want.
Magento provides Bundled Products to achieve such sell of products in packets.
Create a Bundle Product and follow these steps at Bundled Items tab in product edit form
Add New Option
Provide Title, select input type checkbox or multiselect and set Is Required to Yes
Search your product in below grid and add this product providing "Qty to add" to 10
Add selected product to option and then save product.

Magento: Product dynamic price change on add to cart

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.

Custom price for product, displayed in cart; not showing custom price in Review order page- in Multiple Shipping Checkout

I am in a deep trouble, I want to add different categories of product in cart, For each product I have to bring additional 5$ for additional quantity. It may differ in different category.
For the above case I have successfully implemented. But issue is that the price is not showing as that in cart in review order while opting multiple address checkout option.
for E.g: there is two product 1 and 2. for product 1 , for
additional quantity i have to add $5/qty excluding its original price
, i.e; if cost of product 1 is $10 and i selected 2 quantity then
price will be $10*2+($5*1)=25 . for product 2 , for additional
quantity i have to add $10/qty excluding its original price , i.e; if
cost of product 1 is 15 and i selected 2 quantity then price will be
$15*2+($10*1)=40 .
I have implemented it.
while proceeding with checkout option this price is showing fine. *But when I opt multiple shipping its showing products original price,*
Is there anyway , to show the custom price in the review order also.
Please provide me help.
thanks in advance.
Atlast I figure out the solution for this. All price for product displaying in cart is being set in Subtotal.php in
[magento root]/app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php
in function _initItem($address, $item), there I edit the set price for product with the custom price.
Now its working fine.
Hope it helps if someone needed it...

Resources