Hide sub-category from top-menu - opencart

How can i remove/hide the sub-category from the opencart menu under dropdown Components .
Website url : http://cart.kashmosoft.com/

There is an option through which you can hide parent categories from top menu. Go to categories > Edit category > Data tab and you will see below image.
But above option will work for only parent categories and to make it work for child categories like monitors follow below steps:
Go to file /catalog/controller/common/header.php
Search term 'top' and you will notice 1 occurrence and below code is written.
foreach ($categories as $category) {
if ($category['top']) {
//...... some code written
}
}
You have edit this block of code as below
foreach ($categories as $category) {
if ($category['top']) {
//...... some code written
foreach ($children as $child) {
if ($child['top']) { // **YOU HAVE TO ADD IF CONDITION**
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
//...some extra code written
}
}
And done mark top for each category but not for monitors.

Related

Drupal 8 how to save and render an image using a custom block configuration

I'm trying to create a custom module with configuration for a block that will allow a block to have custom fields. I'm having problems allowing the upload of an image and then rendering this in the block on the site.
Currently this is what my block file looks like;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'hello' block.
*
* #Block(
* id = "hello_block",
* admin_label = #Translation("Hello"),
* category = #Translation("Hello world block")
* )
*/
class HelloBlock extends BlockBase
{
/**
* {#inheritdoc}
*/
public function blockForm($form, FormStateInterface $formState)
{
$form['heading'] = array(
'#type' => 'textfield',
'#title' => t('Heading'),
'#description' => t('Enter the main heading'),
'#default_value' => 'Main heading'
);
$form['sub_heading'] = array(
'#type' => 'textfield',
'#title' => t('Sub heading'),
'#description' => t('Enter the sub heading'),
'#default_value' => 'Sub heading'
);
$form['body'] = array(
'#type' => 'text_format',
'#title' => t('Body'),
'#description' => t('Main body'),
'#format' => 'full_html',
'#rows' => 50,
'#default_value' => ''
);
$form['image'] = array(
'#type' => 'managed_file',
'#upload_location' => 'public://upload/hello',
'#title' => t('Image'),
'#upload_validators' => [
'file_validate_extensions' => ['jpg', 'jpeg', 'png', 'gif']
],
'#default_value' => isset($this->configuration['image']) ? $this->configuration['image'] : '',
'#description' => t('The image to display'),
'#required' => true
);
return $form;
}
/**
* {#inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $formState)
{
$this->configuration['heading'] = $formState->getValue('heading');
$this->configuration['sub_heading'] = $formState->getValue('sub_heading');
$this->configuration['body'] = $formState->getValue('body');
$this->configuration['image'] = $formState->getValue('image');
}
/**
* {#inheritdoc}
*/
public function build()
{
$markup = '<h1>'.$this->configuration['heading'].'</h1>';
$markup .= '<h2>'.$this->configuration['sub_heading'].'</h2>';
$markup .= '<img src="'.$this->configuration['image']['value'].'">';
$markup .= '<div>' . $this->configuration['body'] . '</div>';
return array(
'#type' => 'markup',
'#markup' => $markup,
);
}
}
Can anyone provide some pointers as to why the image isn't appearing? I'm assuming I'm missing something.
The text saved in the body (text_format) also appears in the block on the website as 'array', if anyone can help with that too it would be good, other wise I'll raise another question.
When you save that form, the value from the image field is the File ID.
Therefore, you can get the file object and the path by using:
$image = \Drupal\file\Entity\File::load($fid);
$path = file_create_url($image->getFileUri());
Then you would output the image using that path in your markup variable. There's probably a more semantic way to output the formatted image in a 'Drupal-ish' form, but this will get you started.
Oh, and the body field, use
$form_state->getValue('body')['value'];
in your markup.
BTW, I love using Devel and the ksm() function!

OpenCart 3.0.2.0 - how to change sort order of search results & disable search in descriptions?

OpenCart 3.0.2.0 + Journal2 theme.
Problem: when using the search function, the results are sorted by "Default" sort order.
How can I change it to sort by "Name A-Z" (ascending)?
I've found a couple of solutions on SO, but they relate to OC 2.x, not 3.x, and they didn't work when I tried to implement them.
Also, as a bonus, if anyone knows how to disable the "Search in product descriptions" by default, I would really appreciate it.
For sort by "Name A-Z" (ascending)
Got to this path
catalog/controller/product/product.php
change code
Original Code
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
Change Only else part
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'pd.name';
}
For disable the "Search in product descriptions with 2 way.
Solution 1
remove or hide descriptions checkbox, check image below
Solution 2
Got to this path
catalog/controller/product/search.php
Original Code
$filter_data = array(
'filter_name' => $search,
'filter_tag' => $tag,
'filter_description' => $description,
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
Change only one line remove it or comment it.
$filter_data = array(
'filter_name' => $search,
'filter_tag' => $tag,
/*'filter_description' => $description,*/
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);

Drupal 8 programmatically create a custom form with multiple submit buttons

I have a custom Drupal 8 form that shows a list of users and a "check" button for each user.
When clicking a check button, the submit handler needs to figure out which users "check" button was clicked.
I've tried this the following way, but it always returns the id of the last element instead of the correct element.
Is this a bug in Drupal Core Form API?
Any other way to do this? I'm open to suggestions!
This is just an example. What I'm actually trying to do is show a list of users that belong to a specific 'company' node. In that list there is a 'remove from company' button for each user.
http://pastebin.com/us2YFcjr
<?php
namespace Drupal\form_multi_submit\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;
class MultiSubmitForm extends FormBase {
public function getFormId() {
return 'MultiSubmitForm';
}
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all users from database
$ids = \Drupal::entityQuery('user')
->condition('status', 1)
->execute();
$users = User::loadMultiple($ids);
// Set form table header
$form['users'] = array (
'#type' => 'table',
'#header' => array('ID', 'Remove'),
);
// Loop through all users
foreach ($users as $user) {
// Show user ID
$form['users'][$user->id()]['id'] = array(
'#type' => 'label',
'#title' => $user->id(),
);
// Show button for each user
$form['users'][$user->id()]['removememberbutton']['dummyNode'] = array(
'#type' => 'submit',
'#value' => 'Check',
'#submit' => array([$this, 'removeMember']),
);
}
return $form;
}
// Submit handler
public function removeMember(array &$form, FormStateInterface $form_state) {
$userid = $form_state->getTriggeringElement()['#array_parents'][1];
drupal_set_message($userid, 'status');
}
public function validateForm(array &$form, FormStateInterface $form_state) {
// Nothing to do here.
}
public function submitForm(array &$form, FormStateInterface $form_state) {
// Nothing to do here.
}
}
Drupal considers buttons with the same #value as the same button, unless they have a different #name
So all I had to do was add a unique #name to my buttons to get this to work properly:
$form['users'][$user->id()]['dummyNode-' . $user->id()] = array(
'#type' => 'submit',
'#value' => 'Check',
'#name' => 'check_' . $user->id(),
'#submit' => array([$this, 'removeMember']),
);
https://www.drupal.org/node/1342066#comment-11904090

How can I use different layouts in one module in Zend2

How can I use different layouts in one module in Zend2
I write as in my code down and there is no effect
I need to use different layouts for different actions in one controller
class IndexController extends AbstractActionController
{
public function indexAction()
{ $this->layout('layout/layout');
$view = new ViewModel();
$menu = new ViewModel();
$menu->setTemplate('application/menu');
$view->addChild($menu, 'menu');
return $view;
}
public function portfolioAction()
{
$this->layout('layout/portfolio');
$view = new ViewModel();
$menu = new ViewModel();
$menu->setTemplate('application/menu');
$view->addChild($menu, 'menu');
return $view;
}
}
and this is my viewManager
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/portfolio' => __DIR__ . '/../view/layout/layout_portfolio.phtml',
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
I think the layout is set up by the event MvcEvent::EVENT_DISPATCH.
So I wrote a listener to change the layout. You can see my solution at https://github.com/dafap/DafapLayout and adapt it for your needs.

Opencart Display Total Product Count in List of Children Categories

I am using opencart 1.5.4.
I would like to show a count of how many products are in a child category on my list of categories on this page:
http://50.87.186.42/index.php?route=product/category&path=59_60
I have tried to add the code but it looks like it is already in the controller (category/controller/module/category.php)
Here is the code I am looking at:
foreach ($children as $child) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$total += $product_total;
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
It looks like it is using either $total or $product_total but it isn't displaying on the front end. Did I turn this off somewhere or is there a way to turn it back on?
Thanks,
Matt
repalce this foreach (not $children the whole $categories) and let me know if its work or not ...
foreach ($categories as $category) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$product_total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $child['category_id']));
$total += $product_total;
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'total' => $product_total,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}