Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of the $layout_id definition #13595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

opencartbot
Copy link
Contributor

We can also use the switch-case construction:

switch ($route){
	case 'product/category':
		if (isset($this->request->get['path'])) {
			$this->load->model('catalog/category');
			$path = explode('_', (string)$this->request->get['path']);
			$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
		}
		break;
	case 'product/product':
		if (isset($this->request->get['product_id'])) {
			$this->load->model('catalog/product');
			$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
		}
		break;
	case 'product/manufacturer.info':
		if (isset($this->request->get['manufacturer_id'])) {
			$this->load->model('catalog/manufacturer');
			$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
		}
		break;
	case 'information/information':
		if (isset($this->request->get['information_id'])) {
			$this->load->model('catalog/information');
			$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
		}
		break;
	case 'cms/blog.info':
		if (isset($this->request->get['article_id'])) {
			$this->load->model('cms/article');
			$layout_id = $this->model_cms_article->getLayoutId((int)$this->request->get['article_id']);
		}
		break;
}

You can also use the switch-case construction:
switch ($route){
	case 'product/category':
		if (isset($this->request->get['path'])) {
			$this->load->model('catalog/category');
			$path = explode('_', (string)$this->request->get['path']);
			$layout_id = $this->model_catalog_category->getLayoutId((int)end($path));
		}
		break;
	case 'product/product':
		if (isset($this->request->get['product_id'])) {
			$this->load->model('catalog/product');
			$layout_id = $this->model_catalog_product->getLayoutId((int)$this->request->get['product_id']);
		}
		break;
	case 'product/manufacturer.info':
		if (isset($this->request->get['manufacturer_id'])) {
			$this->load->model('catalog/manufacturer');
			$layout_id = $this->model_catalog_manufacturer->getLayoutId((int)$this->request->get['manufacturer_id']);
		}
		break;
	case 'information/information':
		if (isset($this->request->get['information_id'])) {
			$this->load->model('catalog/information');
			$layout_id = $this->model_catalog_information->getLayoutId((int)$this->request->get['information_id']);
		}
		break;
	case 'cms/blog.info':
		if (isset($this->request->get['article_id'])) {
			$this->load->model('cms/article');
			$layout_id = $this->model_cms_article->getLayoutId((int)$this->request->get['article_id']);
		}
		break;
}
@TheCartpenter
Copy link
Contributor

How does that optimize the layout ID by simply sticking the codes together between each cases and using sticked opened brackets from the route on the top?

@opencartbot
Copy link
Contributor Author

opencartbot commented Jan 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants