Back to JKShop Support

AlexeiKo
AlexeiKo

Hey man, could you please add Duplicate feature please? I think I already asked for it.

It's very useful. I already made a code for it (its simple, but working)

in Product.php:

      public function onDuplicate(){

        $selectedId = post('id');

        $selectedProduct = Product::where('id', $selectedId)->first();

        $duplicatedProduct = $selectedProduct->replicate();

        $duplicatedProduct->slug = $selectedProduct->slug . 'duplicate';

        $duplicatedProduct->title = $selectedProduct->title . 'duplicate';

        $duplicatedProduct->save();

     }

In update.htm (product controller):

                <button
                    type="button"

                    data-request="onDuplicate"

                    data-request-data="id: <?=$this->params[0] ?>"

                    data-load-indicator="Duplicating..."

                    class="btn btn-default oc-icon-copy">

                    Duplicate

                </button>

It not taking the picture for some reason, but at least it's there. I have project which products are based on the same structure. And there is lot's of vestions on the product which cannot be under custom param.

Thanks and good luck!

mike.last22290
mike.last22290

I would also be intersted in this feature. I am trying to get something similar to work but with all the product relationships as well.

What I want is this: User selects item from list of products - there is a checkbox to select, the id of the selection is sent through to controller, we grab data on the product and build up a list of the product relations ready to duplicate.

public function onTesting() { $product_type_id = post('checked'); $product_type = ProductType::with('product', 'productMode', 'productAttributes', 'relatedToProductTypes', 'relatedFromProductTypes', 'accreditations', 'media')->find($product_type_id); $new_product_type = $product_type->replicate(); $new_product_type->push(); return [ 'product_type' => $product_type ]; }

The issue I am having at the moment is that the replicate function doesnt appear to be found, it should be as I have loaded in the ProductType model

Last updated

Jiri Kubak
Jiri Kubak

Hi,

thanks for it i will add this feature in new version ;)

Regards Jiri

mike.last22290
Jiri Kubak
Jiri Kubak

mike.last22290 said:

Awesome thanks

Hi,

duplicate function will be add in a new version today.

Jiri

1-5 of 5