Skip to content

Instantly share code, notes, and snippets.

@codeeshop-oc
Last active March 29, 2022 12:13
Show Gist options
  • Save codeeshop-oc/6226016c635c34a2357e69c0fb7d744d to your computer and use it in GitHub Desktop.
Save codeeshop-oc/6226016c635c34a2357e69c0fb7d744d to your computer and use it in GitHub Desktop.
Opencart - How much amount customer saved in cart
public function savedAmountInCart() {
$this->load->model('catalog/product');
$saved_amt = 0;
foreach ($this->cart->getProducts() as $product) {
$product_info = $this->model_catalog_product->getProduct($product['product_id']);
$actual_price = 0;
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$actual_price = $product_info['price'];
}
if ((float) $product_info['special']) {
$p = $product_info['special'];
$diff = $product['quantity'] * ($actual_price - $p);
if ($diff > 0) {
$saved_amt += $diff;
}
}
}
return $saved_amt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment