How to create table in opencart 3.x through ocmod?

I've managed to make an extension for cashback feature in my opencart 3.0.3.2 .I've added the sql for creating a table in model , which i've executed(refer code please) through install() from controller.But in the front end while testing it says the table is not created. Please check and tell if I need any other additional requirements to be met. I've attached the code below.

<?php
model
  class ModelExtensionCmsCashback extends Model {
    public function install() {
      $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "product_cashback` ( `cashback_id` INT NOT NULL AUTO_INCREMENT , `product_id` INT NULL , `status` TINYINT NOT NULL DEFAULT '1' , PRIMARY KEY (`cashback_id`)) ENGINE = InnoDB;");

  }

  public function uninstall() {
    $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "product_cashback`");

}

}


<?php
  class ControllerExtensionModuleCashback extends Controller {
    private $error = array();

    public function index() {}

    public function validate() {}

    public function install() {
      $this->load->model('extension/cms/cashback');
      $this->model_extension_cms_cashback->install();
    }

    public function uninstall() {
      $this->load->model('extension/cms/cashback');
      $this->model_extension_cms_cashback->uninstall();
    }
  }

Upvotes: 1

Views: 1155

Answers (1)

Zehra Noor
Zehra Noor

Reputation: 131

You need to install those queries from extension>>modules and search in module section CmsCashback and press the plus sign (install button) next to it. It will execute sql queries and to run uninstall press minus sign

Upvotes: 1

Related Questions