Jump to content

Erreur sur les tranches du transporteur


Recommended Posts

Bonjour à tous,

 

J'ai une erreur "Une erreur est survenue lors des tranches du transporteur." qui s'affiche quand je veux enregistrer les options d'un transporteur.

Avec le mode debug, cela m'affiche une boîte d'alerte avec ça dedans :

 

TECHNICAL ERROR: 
Details:
Error thrown: [object Object]
Text status: parsererror

 

Dans mes logs Apache, j'ai l'erreur correspondante :

PHP Notice:  Array to string conversion in /var/www/mon_site/override/classes/Carrier.php on line 194

/**
	 * Add new delivery prices
	 *
	 * @param string $priceList Prices list separated by commas
	 * @return boolean Insertion result
	 */
	public function addDeliveryPrice($priceList, $delete = false)
	{
	 	if (!Validate::isValuesList($priceList))
	 		die(Tools::displayError());
		return Db::getInstance()->Execute('
		INSERT INTO `'._DB_PREFIX_.'delivery` (`id_range_price`, `id_range_weight`, `id_range_quantity`, `id_carrier`, `id_zone`, `price`)
		VALUES '.$priceList);
	}

Si je comprends bien : $priceList devrait être une chaine avec la liste des prix séparés par une virgule. Je transforme alors $priceList en chaine séparée par des virgules :

INSERT INTO `'._DB_PREFIX_.'delivery` (`id_range_price`, `id_range_weight`, `id_range_quantity`, `id_carrier`, `id_zone`, `price`)
		VALUES '.implode(",",$priceList));

Mais ça ne fonctionne toujours pas...

Quelqu'un aurait une idée ? Pourquoi faut-il toujours bidouiller le code source de PrestaShop pour que ça fonctionne ?

 

Ma version de PrestaShop : 1.6.0.14

 

Merci d'avance

Edited by Emmure (see edit history)
Link to comment
Share on other sites

En enlevant tout le fichier, je n'ai plus l'erreur merci !  :D

Ou alors faut-il juste enlever la fonction qui pose problème dans cette override ?

 

Je suppose que cette override a été insérée lors d'une mise à jour et elle doit contenir des correctifs importants non ?

 

Je mets le code ci-dessous si ça te dérange pas d'y jeter un oeil :

<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2011 PrestaShop SA
*  @version  Release: $Revision: 6704 $
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class Carrier extends CarrierCore
{
	const SHIPPING_METHOD_QUANTITY = 4;

	/** @var boolean Free carrier */
        public          $is_free = false;

	protected static $priceByQuantity = array();
	protected static $priceByQuantity2 = array();

	/**
         * Get all carriers in a given language
         *
         * @param integer $id_lang Language id
         * @param $modules_filters, possible values:
                        PS_CARRIERS_ONLY
                        CARRIERS_MODULE
                        CARRIERS_MODULE_NEED_RANGE
                        PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE
                        ALL_CARRIERS
         * @param boolean $active Returns only active carriers when true
         * @return array Carriers
         */
        public static function getCarriers($id_lang, $active = false, $delete = false, $id_zone = false, $ids_group = NULL, $modules_filters = 1)
        {
		$carriers = parent::getCarriers($id_lang, $active, $delete, $id_zone, $ids_group, $modules_filters);
		foreach ($carriers as $key => $carrier)
			if (!key_exists('is_free', $carrier))
				$carriers[$key]['is_free'] = false;	
		return $carriers;
	}

	/**
         * Get delivery prices for a given order
         *
         * @param floatval $totalQuantity Order total quantity
         * @param integer $id_zone Zone id (for customer delivery address)
         * @return float Delivery price
         */
        public function getDeliveryPriceByQuantity($totalQuantity, $id_zone)
        {
                $cache_key = $this->id.'_'.$totalQuantity.'_'.$id_zone;
                if (!isset(self::$priceByQuantity[$cache_key]))
                {
                        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
                        SELECT d.`price`
                        FROM `'._DB_PREFIX_.'delivery` d
                        LEFT JOIN `'._DB_PREFIX_.'range_quantity` w ON (d.`id_range_quantity` = w.`id_range_quantity`)
                        WHERE d.`id_zone` = '.(int)($id_zone).'
                        AND '.(int)($totalQuantity).' >= w.`delimiter1`
                        AND '.(int)($totalQuantity).' < w.`delimiter2`
                        AND d.`id_carrier` = '.(int)($this->id).'
                        ORDER BY w.`delimiter1` ASC');
                        if (!isset($result['price']))
                                self::$priceByQuantity[$cache_key] = $this->getMaxDeliveryPriceByQuantity($id_zone);
                        else
                                self::$priceByQuantity[$cache_key] = $result['price'];
                }
                return self::$priceByQuantity[$cache_key];
        }

        static public function checkDeliveryPriceByQuantity($id_carrier, $totalQuantity, $id_zone)
        {
                $cache_key = $id_carrier.'_'.$totalQuantity.'_'.$id_zone;
                if (!isset(self::$priceByQuantity2[$cache_key]))
                {
                        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
                        SELECT d.`price`
                        FROM `'._DB_PREFIX_.'delivery` d
                        LEFT JOIN `'._DB_PREFIX_.'range_quantity` w ON d.`id_range_quantity` = w.`id_range_quantity`
                        WHERE d.`id_zone` = '.(int)($id_zone).'
                        AND '.(int)($totalQuantity).' >= w.`delimiter1`
                        AND '.(int)($totalQuantity).' < w.`delimiter2`
                        AND d.`id_carrier` = '.(int)($id_carrier).'
                        ORDER BY w.`delimiter1` ASC');
                        self::$priceByQuantity2[$cache_key] = (isset($result['price']));
                }
                return self::$priceByQuantity2[$cache_key];
        }

        public function getMaxDeliveryPriceByQuantity($id_zone)
        {
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
                SELECT d.`price`
                FROM `'._DB_PREFIX_.'delivery` d
                INNER JOIN `'._DB_PREFIX_.'range_quantity` w ON d.`id_range_quantity` = w.`id_range_quantity`
                WHERE d.`id_zone` = '.(int)($id_zone).'
                AND d.`id_carrier` = '.(int)($this->id).'
                ORDER BY w.`delimiter2` DESC LIMIT 1');
                if (!isset($result[0]['price']))
                        return false;
                return $result[0]['price'];
        }

	public static function getCarriersForOrder($id_zone, $groups = NULL, $cart = NULL)
	{
		global $cookie, $cart;

		if (is_array($groups) AND !empty($groups))
			$result = Carrier::getCarriers((int)$cookie->id_lang, true, false, (int)$id_zone, $groups, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		else
			$result = Carrier::getCarriers((int)$cookie->id_lang, true, false, (int)$id_zone, array(1), PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
		$resultsArray = array();

		foreach ($result AS $k => $row)
		{
			$carrier = new Carrier((int)$row['id_carrier']);
			$shippingMethod = $carrier->getShippingMethod();
			if ($shippingMethod != Carrier::SHIPPING_METHOD_FREE)
			{
				// Get only carriers that are compliant with shipping method
				if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
					OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)
					OR ($shippingMethod == Carrier::SHIPPING_METHOD_QUANTITY AND $carrier->getMaxDeliveryPriceByQuantity($id_zone) === false))
				{
					unset($result[$k]);
					continue ;
				}

				// If out-of-range behavior carrier is set on "Desactivate carrier"
				if ($row['range_behavior'])
				{
					// Get id zone
					if (!$id_zone)
						$id_zone = (int)$defaultCountry->id_zone;

					// Get only carriers that have a range compatible with cart
					if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
						OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)))
						OR ($shippingMethod == Carrier::SHIPPING_METHOD_QUANTITY AND (!Carrier::checkDeliveryPriceByQuantity($row['id_carrier'], $cart->nbProducts(), $id_zone))))
					{
						unset($result[$k]);
						continue ;
					}
				}
			}
			
			$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
			$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier']));
			$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false));
			$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)($row['id_carrier']).'.jpg') ? _THEME_SHIP_DIR_.(int)($row['id_carrier']).'.jpg' : '';

			// If price is false, then the carrier is unavailable (carrier module)
			if ($row['price'] === false)
			{
				unset($result[$k]);
				continue;
			}

			$resultsArray[] = $row;
		}
		return $resultsArray;
	}

	/**
	 * Add new delivery prices
	 *
	 * @param string $priceList Prices list separated by commas
	 * @return boolean Insertion result
	 */
	public function addDeliveryPrice($priceList, $delete = false)
	{
		if (!Validate::isValuesList($priceList))
	 		die(Tools::displayError());
		return Db::getInstance()->Execute('
		INSERT INTO `'._DB_PREFIX_.'delivery` (`id_range_price`, `id_range_weight`, `id_range_quantity`, `id_carrier`, `id_zone`, `price`)
		VALUES '.$priceList);
	}

	/**
	 * Copy old carrier informations when update carrier
	 *
	 * @param integer $oldId Old id carrier (copy from that id)
	 */
	public function copyCarrierData($oldId)
	{
		if (!Validate::isUnsignedId($oldId))
			die(Tools::displayError());

		$oldLogo = _PS_SHIP_IMG_DIR_.'/'.(int)($oldId).'.jpg';
		if (file_exists($oldLogo))
			copy($oldLogo, _PS_SHIP_IMG_DIR_.'/'.(int)($this->id).'.jpg');

		// Copy existing ranges price
		$res = Db::getInstance()->ExecuteS('
		SELECT * FROM `'._DB_PREFIX_.'range_price`
		WHERE id_carrier = '.(int)($oldId));
		foreach ($res AS $val)
		{
			Db::getInstance()->Execute('
			INSERT INTO `'._DB_PREFIX_.'range_price` (`id_carrier`, `delimiter1`, `delimiter2`)
			VALUES ('.(int)($this->id).','.(float)($val['delimiter1']).','.(float)($val['delimiter2']).')');
			$maxRangePrice = Db::getInstance()->Insert_ID();
			$res2 = Db::getInstance()->ExecuteS('
			SELECT * FROM `'._DB_PREFIX_.'delivery`
			WHERE id_carrier = '.(int)($oldId).'
			AND id_range_price = '.(int)($val['id_range_price']));
			foreach ($res2 AS $val2)
				Db::getInstance()->Execute('
				INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`,`id_range_price`,`id_range_weight`,`id_range_quantity`,`id_zone`, `price`)
				VALUES ('.(int)($this->id).','.(int)($maxRangePrice).',NULL,NULL,'.(int)($val2['id_zone']).','.(float)($val2['price']).')');
		}

		// Copy existing ranges weight
		$res = Db::getInstance()->ExecuteS('
		SELECT * FROM `'._DB_PREFIX_.'range_weight`
		WHERE id_carrier = '.(int)($oldId));
		foreach ($res as $val)
		{
			Db::getInstance()->Execute('
			INSERT INTO `'._DB_PREFIX_.'range_weight` (`id_carrier`, `delimiter1`, `delimiter2`)
			VALUES ('.(int)($this->id).','.(float)($val['delimiter1']).','.(float)($val['delimiter2']).')');
			$maxRangeWeight = Db::getInstance()->Insert_ID();
			$res2 = Db::getInstance()->ExecuteS('
			SELECT * FROM `'._DB_PREFIX_.'delivery`
			WHERE id_carrier = '.(int)($oldId).'
			AND id_range_weight = '.(int)($val['id_range_weight']));
			foreach ($res2 as $val2)
				Db::getInstance()->Execute('
				INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`,`id_range_price`,`id_range_weight`,`id_range_quantity`,`id_zone`, `price`)
				VALUES ('.(int)($this->id).',NULL,'.(int)($maxRangeWeight).',NULL,'.(int)($val2['id_zone']).','.(float)($val2['price']).')');
		}

		// Copy existing ranges quantity
                $res = Db::getInstance()->ExecuteS('
                SELECT * FROM `'._DB_PREFIX_.'range_quantity`
                WHERE id_carrier = '.(int)($oldId));
                foreach ($res as $val)
                {
                        Db::getInstance()->Execute('
                        INSERT INTO `'._DB_PREFIX_.'range_quantity` (`id_carrier`, `delimiter1`, `delimiter2`)
                        VALUES ('.(int)($this->id).','.(int)($val['delimiter1']).','.(int)($val['delimiter2']).')');
                        $maxRangeQuantity = Db::getInstance()->Insert_ID();
                        $res2 = Db::getInstance()->ExecuteS('
                        SELECT * FROM `'._DB_PREFIX_.'delivery`
                        WHERE id_carrier = '.(int)($oldId).'
                        AND id_range_quantity = '.(int)($val['id_range_quantity']));
                        foreach ($res2 as $val2)
                                Db::getInstance()->Execute('
                                INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`,`id_range_price`,`id_range_weight`,`id_range_quantity`,`id_zone`, `price`)
                                VALUES ('.(int)($this->id).',NULL,NULL,'.(int)($maxRangeQuantity).','.(int)($val2['id_zone']).','.(float)($val2['price']).')');
                }

		// Copy existing zones
		$res = Db::getInstance()->ExecuteS('
		SELECT * FROM `'._DB_PREFIX_.'carrier_zone`
		WHERE id_carrier = '.(int)($oldId));
		foreach ($res as $val)
			Db::getInstance()->Execute('
			INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier`, `id_zone`)
			VALUES ('.(int)($this->id).','.(int)($val['id_zone']).')');

		//Copy default carrier
		if ((int)(Configuration::get('PS_CARRIER_DEFAULT')) == $oldId)
			Configuration::updateValue('PS_CARRIER_DEFAULT', (int)($this->id));
	}

	public function getRangeTable()
	{
		$shippingMethod = $this->getShippingMethod();
		if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT)
			return 'range_weight';
		elseif ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE)
			return 'range_price';
		elseif ($shippingMethod == Carrier::SHIPPING_METHOD_QUANTITY)
			return 'range_quantity';
		return false;
	}

	public function getRangeObject($shipping_method = false)
	{
		$shippingMethod = $this->getShippingMethod();
		if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT)
			return new RangeWeight();
		elseif ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE)
			return new RangePrice();
		elseif ($shippingMethod == Carrier::SHIPPING_METHOD_QUANTITY)
			return new RangeQuantity();
		return false;
	}

	public function getRangeSuffix($currency = NULL)
	{
		$suffix = '';
		$shippingMethod = $this->getShippingMethod();
		if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT)
			$suffix = Configuration::get('PS_WEIGHT_UNIT');
		elseif ($this->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE)
		{
			$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
			$suffix = $currency->sign;
		}
		elseif ($shippingMethod == Carrier::SHIPPING_METHOD_QUANTITY)
			$suffix = 'article';
		return $suffix;
	}
}

Merci d'avance

Link to comment
Share on other sites

Aucun correctif/migration ne met en place d'override.

Seul des modules tiers font cela.

Il n'est pas possible de savoir si tu dois ou non garder cette override à ta place.

Tout dépend de tes modules, tes besoins

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...