2 Replies - 5886 Views - Last Post: 09 October 2012 - 01:17 PM Rate Topic: -----

#1 FliP1992  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 200
  • Joined: 14-June 07

OpenCart Module Development

Posted 21 September 2012 - 03:46 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: OpenCart Module Development

#2 FliP1992  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 200
  • Joined: 14-June 07

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.

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

Was This Post Helpful? 0
  • +
  • -

#3 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,907
  • Joined: 30-April 10

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1