You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to add a new "is new product" attribute in OpenCart

Practice




1. in the fileadmincontrollercatalogproduct.php in the method private function getForm() {...
add
if (isset($this->request->post['new'])) {
$this->data['new'] = $this->request->post['new'];
} elseif (!empty($product_info)) {
$this->data['new'] = $product_info['new'];
} else {
$this->data['new'] = '';
}


find the same place where these variables are also saved
(in the controller, passing variables from the user to the engine)

2. in the file adminmodelcatalogproduct.php
very carefully add
"', new = '" . $this->db->escape($data['new']).

something like this

public function addProduct($data) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', new = '" . $this->db->escape($data['new']). "', .....
(in the model - data storage, i.e. writing to and reading from the database)



3. in the file adminview emplatecatalogproduct_form.tpl


Новинка - 1 обычный - 0








(this is where everything is actually displayed to the user)

4. most importantly, there should be such a field in the database table

that is, in the table " . DB_PREFIX . "product there should be a field new, integer, defaulting to 0


that's everything for the admin panel

you need to do something similar on the storefront side as well

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)