Remove default category

  • Posts: 114
  • Thank you received: 14
10 years 7 months ago #128285

I've searched the forums and read the documentation and I'm sure that there must be a simple answer for this (and perhaps a configuration setting hidden in plain sight) but I cannot seem to find how to disable the default product category in the vendor product form.




TIA

/DM

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 26033
  • Thank you received: 4006
  • MODERATOR
10 years 7 months ago #128317

Hi,

In the view "productmarket | form", please replace

		<dd class="hikamarket_product_category"><?php
			echo $this->categoryType->displayMultiple('data[product][categories]', @$this->product->categories, '', $this->rootCategory);
		?></dd>
By:
		<dd class="hikamarket_product_category"><?php
			if(empty($this->product->product_id))
				$this->product->categories = array();
			echo $this->categoryType->displayMultiple('data[product][categories]', @$this->product->categories, '', $this->rootCategory);
		?></dd>
To remove the categories when creating a new product.

Please note that even if there is not displayed category, if you save the product HikaMarket/HikaShop will set a default one. It is not possible to have a product without a least one category.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: DeeEmm

Please Log in or Create an account to join the conversation.

  • Posts: 114
  • Thank you received: 14
10 years 7 months ago #128332

Thanks Jerome, that works great.

However, is it possible that if no category is selected that the user is prompted to add one instead of automatically assigning one?

My reasoning is as follows (perhaps a little cynical but probably fairly accurate)

- Pre-selecting a category - 90% of users will simply assume that this is normal and so they will not delete it.
- Automatically adding a category - users who forget to select a category will be unaware.

In either case I would bet that for every 100 products added I end up with 95 in the root category.

Much better to have no category automatically selected, and some basic form validation.

Is this easily achievable?

/DM

Please Log in or Create an account to join the conversation.

  • Posts: 26033
  • Thank you received: 4006
  • MODERATOR
10 years 7 months ago #128363

Hi,

It is but it will impact the HikaMarket core so that's not a modification that I will recommend.
In HikaMarket product class, you will find this

			if(empty($product->product_id) && !count($product->categories) && !empty($rootCategory)) {
				$product->categories = array($rootCategory);
			}

Maybe the best will be to add some javascript checks in the page. So when the user wants to submit the form, some checks are made and cancel the form submission if there is something wrong.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: DeeEmm

Please Log in or Create an account to join the conversation.

  • Posts: 114
  • Thank you received: 14
10 years 7 months ago #128382

Thanks Jerome.

i ended up adding some simple javascript validation.

in productmarket / form.php I added a javascript function to detect the presence of submitted categories and added an onsubmit call to the form declaration

<script type="text/javascript">
 function validateForm(){
  if (document.forms["hikamarket_form"]["data[product][categories][]"] === undefined){
      alert("Please Select one or more categories");
      exit;
  } else {
      return;
  }
}
</script>

<form action="<?php hikamarket::completeLink('product');?>" method="post" name="hikamarket_form" id="hikamarket_products_form" enctype="multipart/form-data" onsubmit="return validateForm()">

Hope this helps someone else.

/DM

Last edit: 10 years 7 months ago by DeeEmm.
The following user(s) said Thank You: Jerome, master_b

Please Log in or Create an account to join the conversation.

  • Posts: 540
  • Thank you received: 49
10 years 6 months ago #130406

tnx for this and i think its good be if add that as option in market config


сайт з перекладами www.benefit.in.ua
PS. спасибо переводить Webmoney : Z207635098627 R152456839841 или ЯД 410011027999056

Please Log in or Create an account to join the conversation.

Moderators: Obsidev
Time to create page: 0.090 seconds
Powered by Kunena Forum