- Posts: 640
- Thank you received: 16
Change / customize how product cloning works
- PeterChain
-
Topic Author
- Offline
Less
More
10 years 10 months ago #222438
by PeterChain
Change / customize how product cloning works was created by PeterChain
-- 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.
-- 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.
10 years 10 months ago #222469
by nicolas
Replied by nicolas on topic Change / customize how product cloning works
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.
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.
- PeterChain
-
Topic Author
- Offline
Less
More
- Posts: 640
- Thank you received: 16
10 years 10 months ago #222564
by PeterChain
Replied by PeterChain on topic Change / customize how product cloning works
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,
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.
10 years 10 months ago #222670
by nicolas
Replied by nicolas on topic Change / customize how product cloning works
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
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.
- PeterChain
-
Topic Author
- Offline
Less
More
- Posts: 640
- Thank you received: 16
10 years 10 months ago #222696
by PeterChain
Replied by PeterChain on topic Change / customize how product cloning works
Thank you for the idea, I will analyze this method
Please Log in or Create an account to join the conversation.
- PeterChain
-
Topic Author
- Offline
Less
More
- Posts: 640
- Thank you received: 16
10 years 2 months ago #245410
by PeterChain
Replied by PeterChain on topic Change / customize how product cloning works
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
Hope you can dedicate some small time to write down example lines.
Thanks in advance.
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
Code:
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.
10 years 2 months ago #245425
by nicolas
Replied by nicolas on topic Change / customize how product cloning works
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.
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.
- PeterChain
-
Topic Author
- Offline
Less
More
- Posts: 640
- Thank you received: 16
10 years 2 months ago - 10 years 2 months ago #245458
by PeterChain
Replied by PeterChain on topic Change / customize how product cloning works
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:
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:
Code:
unset($this->template->images);
Last edit: 10 years 2 months ago by PeterChain. Reason: found solution
Please Log in or Create an account to join the conversation.
- PeterChain
-
Topic Author
- Offline
Less
More
- Posts: 640
- Thank you received: 16
10 years 2 months ago #245502
by PeterChain
Replied by PeterChain on topic Change / customize how product cloning works
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
I tries many ways without success, looks like another function should be involved somewhere....
How could I force it? even if it was adding this part of random text to warn the user about duplicated titles
Code:
.'_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.
10 years 2 months ago #245540
by nicolas
Replied by nicolas on topic Change / customize how product cloning works
Hi,
You would have to add the column name to the array:
in the file administrator/components/com_hikashop/helpers/import.php
You would have to add the column name to the array:
Code:
$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');
Please Log in or Create an account to join the conversation.
Time to create page: 0.282 seconds