Change / customize how product cloning works

  • Posts: 634
  • Thank you received: 16
8 years 11 months ago #222438

-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.45

When I clone a product from the product list in frontend using the + button I get a copy with the same pictures and with no data in the SEO fields.

Some fields get cloned, others not, sure there is a logical pattern for this, but I would like to change it so for example the clone comes empty of pictures.

Also I would like to change which fields get copied and which don't.

where can I change this settings?

Thank you.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 11 months ago #222469

Hi,

There are no such settings.
It is handled by the function copyProduct of the file administrator/components/com_hikashop/helpers/import.php
So if you wanted to change its behavior, you would have to change the code of that function.

The following user(s) said Thank You: PeterChain

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

  • Posts: 634
  • Thank you received: 16
8 years 11 months ago #222564

I will go for it.

Thank you!

Could be a good idea for future releases to create some extra control in the fields (similar to the custom fields interface) where you could checkbox this as if you want it to be cloned or not.

Best regards,

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 11 months ago #222670

Hi,

Well, you could potentially use the import system using the "product template" system. It actually goes through roughly the same code and thanks to the product template and the CSV, you can choose what you want to get from the template product and what you want to get from the CSV by just specifying what you want from the CSV in the CSV. The rest will come from the product template.
www.hikashop.com/support/support/documen...hikashop-import.html

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

  • Posts: 634
  • Thank you received: 16
8 years 11 months ago #222696

Thank you for the idea, I will analyze this method

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

  • Posts: 634
  • Thank you received: 16
8 years 4 months ago #245410

Please, can you give advice as how to write some code tweak? I then would extend to my need following your example

I want the product clonation button in hikaMarket product list not to copy all fields, and I want to selectively clone some only, for example:

to clone

product_name

but not

product_alias
product custom field 'MyCustom_Field_1'


and then
empty images for the new cloned product

and last force

product_published always False



I understand I should do this against this code inside administrator/components/com_hikashop/helpers/import.php

function copyProduct($product_id){
		$this->addTemplate($product_id);
		$newProduct = new stdClass();
		$newProduct->product_code = $this->template->product_code.'_copy'.rand();
		$this->_checkData($newProduct);

		if(!empty($newProduct->product_code)){
			$products = array($newProduct);
			if(!empty($this->template->variants)){
				foreach($this->template->variants as $variant){
					$copy = (!HIKASHOP_PHP5) ? $variant : clone($variant);
					$copy->product_parent_id = $newProduct->product_code;
					$copy->product_code = str_replace($this->template->product_code,$newProduct->product_code,$copy->product_code);
					unset($copy->product_id);
					$products[]=$copy;
				}
			}
			JPluginHelper::importPlugin( 'hikashop' );
			$dispatcher = JDispatcher::getInstance();
			$do = true;
			$dispatcher->trigger( 'onBeforeProductCopy', array( & $this->template, & $products[0], & $do) );
			if(!$do){
				return false;
			}

			$this->_insertProducts($products);

			$dispatcher->trigger( 'onAfterProductCopy', array( & $this->template, & $products[0]) );
		}
		return true;
	}


Hope you can dedicate some small time to write down example lines.

Thanks in advance.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 4 months ago #245425

Hi,

You could add there such lines:
unset($this->template->product_alias);
so the product_alias wouldn't be copied to the copy product.
But that's a hack.
A cleaner solution would be developping a small hikashop plugin implementing the onBeforeProductCopy and unsetting the attribute $template:
www.hikashop.com/support/documentation/6...#onBeforeProductCopy
That way, you wouldn't loose your change each time you update Hikashop.

The following user(s) said Thank You: PeterChain

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

  • Posts: 634
  • Thank you received: 16
8 years 4 months ago #245458

Thank you Nicolas!

I used it now as a hack for a quick release of some client request. It works fine for core fields and custom fields.

But, how can I remove the images?

I need cloned products to be empty of images.

I'm not sure a simple unset of something is enough. Can you guide me?

Thanks


##################################
SOLVED
##################################

OK, no need for help, is as simple as this:

unset($this->template->images);

Last edit: 8 years 4 months ago by PeterChain. Reason: found solution

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

  • Posts: 634
  • Thank you received: 16
8 years 4 months ago #245502

product_page_title does not get copied (sure for obvious reasons) to the new clone.

How could I force it? even if it was adding this part of random text to warn the user about duplicated titles

.'_copy'.rand();

I tries many ways without success, looks like another function should be involved somewhere....

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 4 months ago #245540

Hi,

You would have to add the column name to the array:

$this->fields = array('product_weight','product_description','product_meta_description','product_tax_id','product_vendor_id','product_manufacturer_id','product_url','product_keywords','product_weight_unit','product_dimension_unit','product_width','product_length','product_height','product_max_per_order','product_min_per_order','product_warehouse_id');
in the file administrator/components/com_hikashop/helpers/import.php

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

Time to create page: 0.076 seconds
Powered by Kunena Forum