Skip to main content

How to get the cart items count and quantity?

More
13 years 5 months ago - 13 years 5 months ago #98240 by renycheah
Hi guys ,

I've been writing a plugin for shipping .

The criteria is

1 to 2 items - $8
3 to 5 items - $16
6 to 10 items - $20
more than 10 - $0


$prod_count = count( $order->products );

// Might need a loop here to count the quantity as well

if ( $prod_count > 0 ) {
If ( $prod_count > 0 && $prod_count <= 2 ){
$rate->shipping_price = 8 ;
}else if ( $prod_count > 2 && $prod_count<= 5) {
$rate->shipping_price = 16;
}else if ( $prod_count > 5 && $prod_count<= 10) {
$rate->shipping_price = 20;
}else{ $rate->shipping_price = 0; }

}

The problem is products with Options will have extra one or more counts depends on how many options the product have. please advise ?
Last edit: 13 years 5 months ago by renycheah.

Please Log in or Create an account to join the conversation.

More
13 years 5 months ago #98307 by renycheah
Still waiting for a reply :(

Please Log in or Create an account to join the conversation.

More
13 years 5 months ago #98315 by renycheah
I manage to narrow it down as follows

Code:
$cartClass = hikashop_get('class.cart'); $productsArray = $cartClass->get(); $cart_id = $cartClass->cart_id; $db = JFactory::getDBO(); $query = 'SELECT sum(cart_product_quantity)cnt FROM '.hikashop_table('cart_product').' where cart_id = \'$cart_id\' and cart_product_option_parent_id = \'0\' and cart_product_quantity > \'0\' '; $db->setQuery($query ); $db_obj = $db->loadObjectList(); // To test i get the values immediately , i directly assign the value to the shipping price $rate->shipping_price = $db_obj->cnt;


But i keep getting 0 for the $db_obj->cnt , the supposedly value should be three.. I tested this query in phpmyadmin and it worked.

Please Log in or Create an account to join the conversation.

More
13 years 5 months ago #98381 by Xavier
Hi,

Thanks to try this request:
$query = 'SELECT sum(cart_product_quantity)cnt FROM '.hikashop_table('cart_product').' where cart_id = '.$cart_id.' and cart_product_option_parent_id = \'0\' and cart_product_quantity > \'0\' ';

The options are in tha cart object, you can use the php function var_dump() to see what is inside the object.

ps: our forum system put the posts back in the queue at each new post.

Please Log in or Create an account to join the conversation.

Time to create page: 0.304 seconds
Powered by Kunena Forum