Is there any way for the stock status to show up in thumb.twig? I've tried to add {{ stock }} but that didn't work.
No. This requires changes within the PHP code itself. You'll need to add this information to all instances where
is being called.
For example in catalog/controller/product/product.php Line 486.
Code: Select all
$this->load->controller('product/thumb', $product_data);
For example in catalog/controller/product/product.php Line 486.
Or, by using an Event Trigger rather than modifying core files.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Could you give an example for this? I'm wondering how you would modify with the event system only.straightlight wrote: ↑Thu Jun 02, 2022 8:36 pmOr, by using an Event Trigger rather than modifying core files.
Daniel is working on a documentation.marvinkleinmusic wrote: ↑Thu Jun 02, 2022 9:09 pmCould you give an example for this? I'm wondering how you would modify with the event system only.straightlight wrote: ↑Thu Jun 02, 2022 8:36 pmOr, by using an Event Trigger rather than modifying core files.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
To modify template files and add data to controllers with Events need more work then using OCMod.
- First create an module with an install function to add the events.
- Then create an module with functions to get data or modify output.
See controller/event/debug.php for the parameters available for before and after events.
Example files attached.
- First create an module with an install function to add the events.
Code: Select all
private $event_list = array(
array(
'code' => 'pprmkr_getstatus_before',
'trigger' => 'catalog/controller/product/thumb/before',
'description' => 'Adds product stock to product thumb',
'action' => 'extension/pprmkr_thumbevent/module/get_status|addTekstBefore'
),
array(
'code' => 'pprmkr_getstatus_after',
'trigger' => 'catalog/controller/product/thumb/after',
'description' => 'Adds product stock to product thumb',
'action' => 'extension/pprmkr_thumbevent/module/get_status|addTekst'
)
);
public function install() {
$this->load->model('setting/event');
foreach ($this->event_list as $event) {
$this->model_setting_event->addEvent($event['code'], $event['description'], $event['trigger'], $event['action']);
}
}
public function uninstall() {
$this->load->model('setting/event');
foreach ($this->event_list as $event) {
$this->model_setting_event->deleteEventByCode($event['code']);
}
}
Code: Select all
public function addTekst(string &$route, array &$args, mixed &$output): void {
$search = '<div class="button-group">';
$position = strpos($output, $search, 0) - 13; // end of div description
$firstPart = substr($output, 0, $position);
$lastPart = substr($output, $position);
$addedText = 'Status: ' . $args[0]['nieuweData'];
$output = $firstPart . $addedText . $lastPart;
}
public function addTekstBefore(string &$route, array &$args): void {
$this->load->language('product/product');
foreach ($args as $key => $data) {
$product_info = $this->model_catalog_product->getProduct($args[$key]['product_id']);
if ($product_info) {
if ($product_info['quantity'] <= 0) {
$stock = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$stock = $product_info['quantity'];
} else {
$stock = $this->language->get('text_instock');
}
}
$args[$key]['nieuweData'] = $stock;
}
}
Example files attached.
While it may require more work, at least, it doesn't conflict with an already existing line. Good work!
add above:
Code: Select all
foreach ($args as $key => $data) {
Code: Select all
$this->load->model('catalog/product');
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Who is online
Users browsing this forum: Google [Bot] and 6 guests