Jump to content

Combining two cart overrides


Recommended Posts

Hello,

im trying to combine two diferent cart overrides because i need them both so all my modules work how they should.

 

But it seems like it does not work. I always just get a blank page. If someone could help me it would be appreaciated. I tryed diferent methods but got no result.

 

<?php
/**
* Cart class override for additional payment fees module
* Upload this to the override/clases directory
*
* @author Burhan
* www.bvkyazilim.com
*/
class Cart extends CartCore{	   

public function getOrderTotal($withTaxes = true, $type = Cart::BOTH)
{
	    if($withTaxes && ($type == Cart::BOTH || $type == Cart::ONLY_DISCOUNTS)){
		    $backtrace=debug_backtrace(false);
		    $name=false;
		    if(isset($backtrace[0]) && stristr($backtrace[0]['file'], 'modules')){
			    $name=explode(DIRECTORY_SEPARATOR, $backtrace[0]['file']);
		    }elseif(isset($backtrace[1]) && stristr($backtrace[1]['file'], 'modules')){
			    $name=explode(DIRECTORY_SEPARATOR, $backtrace[1]['file']);
		    }
		    if($name)
			    $name=$name[array_search('modules', $name)+1];
		    if($name){
			    if($fee=Db::getInstance()->getValue('SELECT `fee` FROM `'._DB_PREFIX_.'bvk_paymentfees` WHERE `name`="'.pSQL($name).'"')){
				    if($type == Cart::ONLY_DISCOUNTS){
					    $result=parent::getOrderTotal($withTaxes, $type);
					    if(!$result){
						    $result='a';
					    }
					    return $result;
				    }
				    $fee='$total='.str_replace('total', '$total', $fee);
				    $total=parent::getOrderTotal($withTaxes, $type);
				    $tmp=$total;
				    eval($fee.';');
				    $total=Tools::ps_round($total, 2);
				    $feeamount=$total-$tmp;
				    Db::getInstance()->Execute('REPLACE INTO `'._DB_PREFIX_.'bvk_paymentfees_cart`(`id_cart`, `name`, `fee`) VALUES('.intval($this->id).', "'.pSQL($name).'", '.floatval($feeamount).')');
				    return $total;
			    }
		    }
	    }
	    return parent::getOrderTotal($withTaxes, $type);
}
}
?>

 

 

<?php
class Cart extends CartCore
{
/**
 * Return cart products
 *
 * @result array Products modded by Simon Agostini toi give also Features with name and value
 */
public function getProducts($refresh = false, $id_product = false)
{
 if (!$this->id)
  return array();
 // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
 if ($this->_products !== NULL AND !$refresh)
  return $this->_products;
 $sql = '
 SELECT cp.`id_product_attribute`, cp.`id_product`, cu.`id_customization`, cp.`quantity` AS cart_quantity, cu.`quantity` AS customization_quantity, pl.`name`,
 pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`,
 p.`quantity`, p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`, IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity,
 t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, pa.`quantity` AS quantity_attribute,
 pa.`ecotax` AS ecotax_attr, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
 IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
 IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
 (p.`weight`+ pa.`weight`) weight_attribute,
 IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
 pai.`id_image` pai_id_image, il.`legend` pai_legend
 FROM `'._DB_PREFIX_.'cart_product` cp
 LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
 LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.')
 LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
 LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
  AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
  AND tr.`id_state` = 0)
 LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
 LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
 LEFT JOIN `'._DB_PREFIX_.'customization` cu ON (cp.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = cp.`id_cart`)
 LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON (pai.`id_product_attribute` = pa.`id_product_attribute`)
 LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (il.`id_image` = pai.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
 LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.')
 WHERE cp.`id_cart` = '.(int)$this->id.'
 '.($id_product ? ' AND cp.`id_product` = '.(int)$id_product : '').'
 AND p.`id_product` IS NOT NULL
 GROUP BY unique_id
 ORDER BY cp.date_add ASC';
 $result = Db::getInstance()->ExecuteS($sql);
 // Reset the cache before the following return, or else an empty cart will add dozens of queries
 $productsIds = array();
 $paIds = array();
 foreach ($result as $row)
 {
  $productsIds[] = $row['id_product'];
  $paIds[] = $row['id_product_attribute'];
 }
 // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
 Product::cacheProductsFeatures($productsIds);
 self::cacheSomeAttributesLists($paIds, $this->id_lang);
 $this->_products = array();
 if (empty($result))
  return array();
 foreach ($result AS $row)
 {
  if (isset($row['ecotax_attr']) AND $row['ecotax_attr'] > 0)
   $row['ecotax'] = (float)($row['ecotax_attr']);
  $row['stock_quantity'] = (int)($row['quantity']);
  // for compatibility with 1.2 themes
  $row['quantity'] = (int)($row['cart_quantity']);
  if (isset($row['id_product_attribute']) AND (int)$row['id_product_attribute'])
  {
   $row['weight'] = $row['weight_attribute'];
   $row['stock_quantity'] = $row['quantity_attribute'];
  }
  if ($this->_taxCalculationMethod == PS_TAX_EXC)
  {
   $row['price'] = Product::getPriceStatic((int)$row['id_product'], false, isset($row['id_product_attribute']) ? (int)($row['id_product_attribute']) : NULL, 2, NULL, false, true, (int)($row['cart_quantity']), false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL), $specificPriceOutput); // Here taxes are computed only once the quantity has been applied to the product price
   $row['price_wt'] = Product::getPriceStatic((int)$row['id_product'], true, isset($row['id_product_attribute']) ? (int)($row['id_product_attribute']) : NULL, 2, NULL, false, true, (int)($row['cart_quantity']), false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL));
   $tax_rate = Tax::getProductTaxRate((int)$row['id_product'], (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
   $row['total_wt'] = Tools::ps_round($row['price'] * (float)$row['cart_quantity'] * (1 + (float)($tax_rate) / 100), 2);
   $row['total'] = $row['price'] * (int)($row['cart_quantity']);
  }
  else
  {
   $row['price'] = Product::getPriceStatic((int)$row['id_product'], false, (int)$row['id_product_attribute'], 6, NULL, false, true, $row['cart_quantity'], false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL), $specificPriceOutput);
   $row['price_wt'] = Product::getPriceStatic((int)$row['id_product'], true, (int)$row['id_product_attribute'], 2, NULL, false, true, $row['cart_quantity'], false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL));
   /* In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals */
   $row['price_wt'] = Tools::ps_round($row['price_wt'], 2);
   $row['total_wt'] = $row['price_wt'] * (int)($row['cart_quantity']);
   $row['total'] = Tools::ps_round($row['price'] * (int)($row['cart_quantity']), 2);
  }
  if (!isset($row['pai_id_image']) OR $row['pai_id_image'] == 0)
  {
   $row2 = Db::getInstance()->getRow('
   SELECT i.`id_image`, il.`legend`
   FROM `'._DB_PREFIX_.'image` i
   LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
   WHERE i.`id_product` = '.(int)$row['id_product'].' AND i.`cover` = 1');
   if (!$row2)
 $row2 = array('id_image' => false, 'legend' => false);
   else
 $row = array_merge($row, $row2);
  }
  else
  {
   $row['id_image'] = $row['pai_id_image'];
   $row['legend'] = $row['pai_legend'];
  }
  $row['reduction_applies'] = ($specificPriceOutput AND (float)$specificPriceOutput['reduction']);
  $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
  $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
  $row['features'] = Product::getFeaturesStatic((int)$row['id_product']);
  $row['featuresSum'] = Product::getFeaturesStaticNameValue((int)$row['id_product']);
  if (array_key_exists($row['id_product_attribute'].'-'.$this->id_lang, self::$_attributesLists))
   $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'].'-'.$this->id_lang]);
  $this->_products[] = $row;
 }
 return $this->_products;
}   
}
?>

Edited by sickz (see edit history)
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...