I'm just playing around with Opencart module development at the moment. Despite the documentation being abit limited it's quite easy to setup and play around with. I'm trying to create a module that will discount a product price by a variable amount depending if its in a selected category.
I was hoping i could hook in to an event like you would with Magento or Wordpress when a product has been added to cart, which i will then be able to perform a check and edit the price according.
Has anyone played around with Opencart modules before? Do you know how to capture the event when a product has been added to the cart?
Thanks,
Tom
OpenCart Module Development
Page 1 of 12 Replies - 1126 Views - Last Post: 09 October 2012 - 01:17 PM
Replies To: OpenCart Module Development
#2
Re: OpenCart Module Development
Posted 09 October 2012 - 08:24 AM
I found the solution to this problem quote easy. You just need to follow the OpenCart MVC pattern. What i was actually looking for was to create a "Order Totals" Module instead of a standard one. These are processed when the cart/checkout total is loaded.
The code below is just the model class for the "Order Totals" processing part. To use it you will need to create a module as usual. If you don't know who to do this there are loads of tutorials you can follow online.
The only problem i faced using it was that the code was being run 4 times. Two of the times it was being passed blank cart data. To get around this problem i just checked how many times the code was being run and returned null if it was more than once.
I will write an expanded tutorial if enough people are intrested.
Hope this helps,
Tom
Edit Reason: I accidently deleted the post the first time.
The code below is just the model class for the "Order Totals" processing part. To use it you will need to create a module as usual. If you don't know who to do this there are loads of tutorials you can follow online.
The only problem i faced using it was that the code was being run 4 times. Two of the times it was being passed blank cart data. To get around this problem i just checked how many times the code was being run and returned null if it was more than once.
File: /catalog/model/total/ModuleName.php
<?php
class ModelTotalModuleName extends Model {
public function getTotal(&$total_data, &$total, &$taxes) {
$discount_total = 0.00;
$discount_title = '20% off';
$status = true;
if($status){
$total_data[] = array(
'code' => 'ModuleName',
'title' => $discount_title,
'text' => $this->currency->format($discount_total),
'value' => $discount_total,
'sort_order' => 0
);
}
$total += $discount_total;
}
}
?>
I will write an expanded tutorial if enough people are intrested.
Hope this helps,
Tom
Edit Reason: I accidently deleted the post the first time.
This post has been edited by FliP1992: 09 October 2012 - 08:33 AM
#3
Re: OpenCart Module Development
Posted 09 October 2012 - 01:17 PM
I am very interested in a tutorial on opencarts usage, I am working tword using a cart soon and could use the extra knowledge.
This post has been edited by laytonsdad: 09 October 2012 - 01:18 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|