Post by HostOncilla » Thu Jun 02, 2022 4:34 am

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.

Newbie

Posts

Joined
Tue Aug 10, 2021 2:39 am

Post by marvinkleinmusic » Thu Jun 02, 2022 6:49 pm

No. This requires changes within the PHP code itself. You'll need to add this information to all instances where

Code: Select all

$this->load->controller('product/thumb', $product_data);
is being called.

For example in catalog/controller/product/product.php Line 486.


Posts

Joined
Sat Nov 17, 2018 3:32 am

Post by straightlight » Thu Jun 02, 2022 8:36 pm

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by marvinkleinmusic » Thu Jun 02, 2022 9:09 pm

straightlight wrote:
Thu Jun 02, 2022 8:36 pm
Or, by using an Event Trigger rather than modifying core files.
Could you give an example for this? I'm wondering how you would modify with the event system only.


Posts

Joined
Sat Nov 17, 2018 3:32 am

Post by straightlight » Thu Jun 02, 2022 9:52 pm

marvinkleinmusic wrote:
Thu Jun 02, 2022 9:09 pm
straightlight wrote:
Thu Jun 02, 2022 8:36 pm
Or, by using an Event Trigger rather than modifying core files.
Could you give an example for this? I'm wondering how you would modify with the event system only.
Daniel is working on a documentation.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by pprmkr » Fri Jun 03, 2022 3:38 am

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.

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']);
		}
	}
- Then create an module with functions to get data or modify output.

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;
		}
	}
See controller/event/debug.php for the parameters available for before and after events.

Example files attached.

Attachments


User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by straightlight » Fri Jun 03, 2022 7:04 am

While it may require more work, at least, it doesn't conflict with an already existing line. Good work!

Code: Select all

foreach ($args as $key => $data) {
add above:

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: Google [Bot] and 6 guests