show the total number Products in the add to cart popup - joomla

i want show the total number Products (carts Product) in the add to cart popup
also i used this cod in the padded.php
$cart = VirtueMartCart::getCart(); //getting cart object
$dat = $cart->cartProductsData;
echo "Total Product Count: " . count($dat)."\n";
$cart->prepareCartData();
but it does not show the the correct number
how can i fix this please ?

To get the count of total products, you can try like this
$cart = VirtueMartCart::getCart(); //getting cart object
$products = $cart->products;
echo "Total Product Count: " . count($products)."\n";
Thanks!

Related

Reducing the number of products in stock management

I want it to reduce the number of products in the cart from stock after the order is placed. sample: The product stock with 5 IDs is 50 pieces, if 5 orders are received from this product,I want it updated to be 50 - 5 = 45.
note:number=the quantity of the product in the current order
more detailed: There is number in the cart_product table, stock in the products table,Number of products in cart_product,Taking the number from the cart_product table and subtracting it from the stock in the product table, but i didn't succeed can you help me please
DB::table('products')
->join('products', 'products.id', 'cart_product.product_id')
->join('cart_product', 'cart.id', 'cart_product.main_cart_id')
->where(session('active_cart_id'),'=','cart_product.main_cart_id')
->orWhere('cart_product.product_id','=','products.id')
->update();
// Fetch items in the cart
$cartItems = DB::table('cart_product')
->where('main_cart_id', session('active_cart_id'))
->get();
foreach ($cartItems as $cartItem) {
// Update stocks in the "products" table
DB::table('products')
->where('id',$cartItem->product_id)
->decrement(
'AAAAA',
$cartItem->BBBBB;
);
}
I couldn't use the column names since I don't know. Keep in mind that you need to change the following texts in the code:
AAAAA => Column name of the purchased item amount in "cart_product" table.
$cartItem->BBBBB => Column name of item stock in "products" table.
For more information about increment and decrement methods, you can look at https://laravel.com/docs/9.x/queries#increment-and-decrement
it worked like this
// Fetch items in the cart
$cartItems = DB::table('cart_product')
->where('main_cart_id', session('active_cart_id'))
->get();
foreach ($cartItems as $cartItem) {
// Update stocks in the "products" table
DB::table('products')
->where('id',$cartItem->product_id)
->decrement(
'stock',
$cartItem->number
);}

Getting product name and phone number in the success page for Magento

I am using Magento 1.9 and I need to use customer name, number, and product name in the success page. How can I achieve that?
get customer name and phone number using below fields
$order = Mage::getModel('sales/order')->load($this->getOrderId());
if($order->getCustomerIsGuest()){
echo $order->getBillingAddress()->getName();
echo $order->getBillingAddress()->getTelephone();
}
else{
echo $order->getCustomerName();
echo $order->getTelephone();
}
Assuming you already have the order object in success page
$order->getBillingAddress()->getTelephone();
$order->getCustomerName();
$ordered_items = $order->getAllVisibleItems();
foreach($ordered_items as $item)
$product_name[] = $item->getName();
Even if some one searching for same.
$orderDetails = Mage::getModel(‘sales/order’)->loadByIncrementId($this->getOrderId());
To get Contact Number
echo $telePhone=$orderObj->getBillingAddress()->getTelephone();
To get Complete array use print_r($orderDetails);

Magento Shopping Cart Rule - Is this combination possible

Hoping some one can help me with a Magento Rule - is this rule even possible
I have numerous products of numerous sizes all part of the same category.
Each product regardless of size costs £3.98 - If a buyer buys 3 products of the same category regardless of the product or size they get it for £9.99. If they buy 4 products, they get 3 of them for 9.99 but pay full price for the 4th...Every group of 3 is £9.99
I have a rule created that seems to work perfect if a Customer buys 3 / 6 / 9 items of the same product and same size...However if they mix and match it doesn't work (though they are the same category)
The rule is:
IF ALL of these conditions are TRUE:
If total quantity equals or greater than 3 for a subselection of items in cart matching ALL of these conditions:
Category is 4
I have also set the Discount Qty Step to be 3
* UPDATE *
Thanks for your reply - I have tried to implement what you suggest and have got so far as to where I get the category id of the added products. I'm unsure how to set the price the previous products so it will be an automatically discounted price
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
$itemPrice = "3.33";
foreach ($cartItems as $items) {
$product = $items->getProduct();
$prodCats = $product->getCategoryIds();
if (in_array('4', $prodCats)) {
$itemQty = $items->getQty();
}
$totalItems += $itemQty;
}
So what I want to do is apply a discount for multiple of 3's for any product that has a category_id of 4...The price will be 3.33 instead of the normal 3.99
You need event - observer approach for this, that will give you the flexibility you need. You can build an observer that catches the add-to-cart event sales_quote_add_item and put your logic there.
Following code within your observer function will point you in the right direction:
// Get products in cart:
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
$itemSku = $item->getSku();
$itemQty = $item->getQty();
}
// Added product:
$item = $observer->getEvent()->getQuoteItem();
$itemQty = $item->getQty();
$itemSku = $item->getSku();
// Change price of added product:
$item->setOriginalCustomPrice($newPrice);
Good luck!

Magento: count products using stock quantity

I'm new in magento.
I'm wondering how I can count all products using stock quantity. For example, I have
category 1
product one - stock 10
product two - stock 5
category 2
product three - stock 10
The result of the sum of all products should be 25
Actually, I'm using
<?php
$prods = Mage::getModel('catalog/product')->getCollection();
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($prods);
$count = number_format(count($prods));
echo $count;
?>
but this counts the products without stock quantity.
Thanks for your help.
Untested but this should get you what you need…
$stockItemCollection = Mage::getModel('cataloginventory/stock_item')
->getCollection();
$stockTotal = array_sum($stockItemCollection->getColumnValues('qty'));
This should work, too. The reports collection joins together all the quote_items. But I'm not sure wether any order status is considered
$collection = Mage::getResourceModel('reports/product_sold_collection');
$collection->addOrderedQty();
// EDIT reading the question is all
$sum = 0;
foreach($collection as $product) {
$sum += $product->getOrderedQty();
}
echo $sum;

how to count items in an order(when item status=Mixed) using orderid in magento?

I am trying to count total number of items in an order but I am unable to do so correctly.
I am using this code -
$total=0;
$order = Mage::getModel('sales/order')->load($oid);
$items = $order->getAllItems();
foreach($items as $item){
$qty = $item->getQtyToInvoice();
$total = $total + $qty;
}
echo "total :".$total;
This print correct result if the items status in orders is shipped but if the item status is mixed ,it prints 0 .
Are you simply looking for the number of items ordered, regardless of its shipped/invoiced/refunded status?
If so then then replace getQtyToInvoice() with getQtyOrdered().
For example:
foreach($items as $item){
$qty = $item->getQtyOrdered();
}
To answer the question in the comments: "I am also looking for the number of items shipped"
$item->getQtyShipped()

Resources