Jump to content

Como calcular el número total de artículos del carrito en la clase cart.php


DrStein

Recommended Posts

Lo quiero hacer dentro de....

 

public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
{
   static $address = array();
 
   static $total_unidades = 0;
   foreach ($products as $product)
   {
      $total_unidades += $product['cart_quantity'];
   }
.....
 
Pero así no me está funcionando.
¿Qué hago mal?
 
Un saludo.
 
Link to comment
Share on other sites

 

Lo quiero hacer dentro de....

 

public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
{
   static $address = array();
 
   static $total_unidades = 0;
   foreach ($products as $product)
   {
      $total_unidades += $product['cart_quantity'];
   }
.....
 
Pero así no me está funcionando.
¿Qué hago mal?
 
Un saludo.

 

 

 

Porqué no utilizas la función de la clase Cart que ya está hecha?  ^_^

public static function getNbProducts($id)
{
	// Must be strictly compared to NULL, or else an empty cart will bypass the cache and add dozens of queries
	if (isset(self::$_nbProducts[$id]) && self::$_nbProducts[$id] !== null)
		return self::$_nbProducts[$id];

	self::$_nbProducts[$id] = (int)Db::getInstance()->getValue('
		SELECT SUM(`quantity`)
		FROM `'._DB_PREFIX_.'cart_product`
		WHERE `id_cart` = '.(int)$id
	);

	return self::$_nbProducts[$id];
}
Edited by joseantgv (see edit history)
  • Like 1
Link to comment
Share on other sites

No se si lo estaré o no instanciando pero me funciona.

 

Ahora quiero sobrescribir la clase con override, pero no me funciona.

He creado el fichero /override/classes/Cart.php con el contenido:

 

<?php
 
class Cart extends CartCore
{
   public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
   {
     static $address = array();
 
     $wrapping_fees = (float)Configuration::get('PS_GIFT_WRAPPING_PRICE');
     if ($with_taxes && $wrapping_fees > 0)
     {
...
 
¿Qué hago mal?
 
Un saludo.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...