Cart items in magento - php

I want to display the cart items in magento. Currently it's display on the basis on product qty, but I want to display them on number of product added into the cart.
E.g. If I added 1 product of 1kg and other product of 0.500grms then in header displays 1.5 items, I want to display it as 2 items.
Any suggestions? My Magento version is 1.9.0.1

There are 2 functions available for Item count.
1) Mage::helper('checkout/cart')->getItemsCount() -- return shopping cart items count means how many sku add to shopping cart.
2) Mage::helper('checkout/cart')->getSummaryCount() -- return shopping cart items summary (suppose you add sku1 6 qty and sku2 3 qty = total 9 qty return)
You can use 1st function.

There is a config setting field under System > Configuration > Sales > Checkout > My Cart Link with two options: "Display number of items in cart" and "Display item quantities". Choose the second option and your displaying issue will be solved.

Documentation here:
app\code\core\Mage\Checkout\Block\Cart\Minicart.php
Points to a config setting in Magento admin:
admin/system_config/edit/section/checkout/
My cart link
For edge cases you may need to loop through the cart and quantify as desired yourself.

Related

Changing cart product price in Woocommerce

I wanted to implement a buy 3 free 1 feature, so I wrote a script that detect whether customer has 3 same items in cart and automatically add 1 more same item to the cart. Then using another hook, I overwrite the price of the product to 0.
I googled the solution and used the same approach found on:
WooCommerce: Add product to cart with price override?
woocommerce add custom price while add to cart
Here is the code sample:
function setGiftPriceToZero($cart_object){
foreach($cart_object->cart_contents as $k=>$item):
if(isset($item['variation']['promo']) && ($item['variation']['promo']) == 'buy 3 free 1'):
$item['data']->price = 0;
endif;
endforeach;
}
add_action('woocommerce_before_calculate_totals', 'setGiftPriceToZero');
When Woocommerce calculate the subtotal for the cart, it always add in the original price of the product that is supposed to be free. For example, when I added 3 $100 item to cart, the cart subtotal ends up with $400 instead of $300.
I digged deeper into the Woocommerce code and found that in https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#1139, $item['data']->get_price() is used which always return the original price for the item.
Is there anyway to fix this using hooks/apis instead of editing Woocommerce core file?
I have found the culprit of this error. It's caused by conflict from another plugin called Woocommerce Role Based Price. This plugin overwrite the cart item price at the end of the cart total calculation flow. This is why get_price() function always return the specified price for the item.
Now I only have to edit the plugin file so that it plays nicely with my logic.

Category Quantity Discount for Opencart

If I have many products on one category and I want to give discounts for specific quantity like: 2 for 10% off, 3 for 15% off and 4 for 20% off in any product they purchased on that same category.
I've tried to find extensions in opencart but I didn't found one. Does anyone knows any extension for this in opencart?
Thank you.
This features is already exits int the open cart system.
Go to that product form in the admin panel,
Home -> Product-> In product form there is a Discount tab,you can set price for every product according to the quantity.

How to display promotion price when qty is 0 in magento

I am building an online shop where I want to display on the category page and also on the product page the special price also when the qty is 0 and stock is manageable. The idea is to say that the product can be on demand in 24-48 hours and it has a discount but the product is not in actual stock of the client but it can arrive to the customer in 24-48 hours.
How can I make this in Magento because when I look now is taking only the original price and not the promotional price when qty is 0.
in magento version 1.9.1.0 it displays product with special price if it is out of stock so no need to change in code in magento. if not display there then use
echo $_product->getFinalPrice();
for display promotional price.
From what it appears you simply want to discount active in stock products and stop doing so when they're out of stock and then notify the customers that they have a lead time of 24-48 hours if so.
There's a Magento inventory option to do just that:
admin/system_config/edit/section/cataloginventory
Then you need to add a promo that discounts products that are quantity > 0
The promo would reduce necessary products to the 'regular price' but not if their inventory is 0.
admin/promo_quote/new
By default Magento does not give you those promotions so you'd have to use a third party module for such detection/discount such as Amasty which has some of the most robust, stable, compatibly modules in the business:
https://amasty.com/

How to show product total price calculation in Magento cart

I'm having problems trying to show the product full total price in Magento, and by product total price I mean full product price without the discount; the price has to be multiplied for each product quantity added to the cart, and custom options additional price should be added as well. Which files should I edit in Magento? is it possible to show the product discount inside the cart (amount that varies with the amount of ordered products)?
Thanks
Edit:
screenshot
In the blue rectangle it shows the regular price, which should be regular price X 2 (since product quantity is 2) with added 122€ as chosen in product special options. Instead now it shows regular price with discount applied and for only 1 product, without special option added.

Product quantity based coupon rules for a single category products

I am working on drupal 7.12. I need to add a quantity based coupon for a single category products.
If I have that category product qty = 3 in cart and I apply the code it should apply on this category of product only.
I want to apply "buy 1 at $10, buy 2 at $15 and buy 6 at $30".
Please help how I can achieve this.
There is a module called discount alternative module may do your targets. But it has only alpha version with critical bugs
https://drupal.org/project/uc_discounts_alt
https://drupal.org/comment/7164268#comment-7164268

Categories