Post by sturman » Sat Mar 07, 2009 9:44 am

( I have also posted the instructions below in the contributions of the main site, as a zipped text file downloadable here:
http://www.opencart.com/index.php?route ... tion_id=95 )

This upgrade for the admin makes it possible to copy a product, including all settings and options, with two button clicks. To implement this upgrade all you need to do is make these 6 small changes:

1.In system/engine/router.php, change line 4 from:
protected $method;
to:
public $method;

2.In admin/controller/catalog/product.php, change lines 232-235 from:
$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->https('catalog/product/update&product_id=' . $result['product_id'] . $url)
);
to:
$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->https('catalog/product/update&product_id=' . $result['product_id'] . $url),
'text2' => $this->language->get('text_copy'),
'href2' => $this->url->https('catalog/product/insert&product_id=' . $result['product_id'] . $url)
);

3.In the same file, after line 344:
private function getForm() {
add this line:
global $action;

4.In the same file, change line 442 from:
if (!isset($this->request->get['product_id'])) {
to:
if (!isset($this->request->get['product_id']) || $action->method=="insert") {

5.In the file admin/view/template/catalog/product_list.tpl, after line 135:
[ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
add this line:
[ <a href="<?php echo $action['href2']; ?>"><?php echo $action['text2']; ?></a> ]

6.In the file admin/language/english/english.php, after line 26:
$_['text_edit'] = 'Edit';
add this line:
$_['text_copy'] = 'Copy';

That's it! Now when you go to Catalogue/Product in the admin, you will see next to each product not only an Edit link, but also a Copy link. To copy a product just click on the Copy link, then make any changes on any of the tabs if you wish, and click Save.

Newbie

Posts

Joined
Wed Feb 25, 2009 2:09 pm


Post by Qphoria » Sat Mar 07, 2009 11:23 am

I haven't tried this, so maybe I'm wrong.. But looking at this part of the code:

$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->https('catalog/product/update&product_id=' . $result['product_id'] . $url),
'text2' => $this->language->get('text_copy'),
'href2' => $this->url->https('catalog/product/insert&product_id=' . $result['product_id'] . $url)
);


it looks like Copy would duplicate the existing product_id as well. Wouldn't the database reject that since product_id is supposed to be unique?

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by sturman » Sat Mar 07, 2009 7:39 pm

Hi, I can assure you it works, and I would not have posted this without testing it first :-)

Including the id within the copy link makes sure all the data of the existing product with the old id are first loaded in the form. But then the trick is mainly here:

4.In the same file, change line 442 from:
if (!isset($this->request->get['product_id'])) {
to:
if (!isset($this->request->get['product_id']) || $action->method=="insert") {

If you look in admin/controller/catalog/product.php at the code which follows it is more clear what this changes:

if (!isset($this->request->get['product_id']) || $action->method=="insert") {
$this->data['action'] = $this->url->https('catalog/product/insert' . $url);
} else {
$this->data['action'] = $this->url->https('catalog/product/update&product_id=' . $this->request->get['product_id'] . $url);
}

You see, the "insert" part of the URL prompts the system to proceed with a product insert instead of a product update when you click on save. And doing the insert into the database automatically generates a new fresh id!

Henry

Newbie

Posts

Joined
Wed Feb 25, 2009 2:09 pm


Post by Qphoria » Sat Mar 07, 2009 9:52 pm

ah ok gotcha. good work

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by iloveopencart » Sat Mar 07, 2009 11:00 pm

This is an awesome contribution! HUGE time saver. Thanks.

User avatar
Global Moderator

Posts

Joined
Thu Mar 05, 2009 11:15 pm
Location - Phoenix, AZ

Post by 4star » Fri Jan 22, 2010 3:47 am

Any plans to add this to 1.4.0?

Newbie

Posts

Joined
Thu Jan 21, 2010 7:48 am

Post by cc6264 » Fri Jan 22, 2010 11:37 am

Or how to make it work with 1.3x,1.40 ?

Newbie

Posts

Joined
Fri Oct 09, 2009 9:29 am
Location - Sydney,Australia

Post by imaginetech » Fri Jan 22, 2010 12:56 pm

If you look in the contributions section I'm sure the bottom download works for 1.3.2 and 1.3.4.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia

Post by Artlife » Thu Feb 04, 2010 8:09 pm

cc6264 wrote:Or how to make it work with 1.3x,1.40 ?
there is a 1.4 version available, and I just made the instructed changes to my store and it works like a charm. Very grateful for this contribution, what a time saver.

New member

Posts

Joined
Tue Feb 02, 2010 11:41 am

Post by Cyberdude » Sat Feb 06, 2010 4:46 am

how did you do it for 1.4.0 ?

because, i did it also, and copy works, but now, when i click edit, it says, page not found.

???

can you help?

Logohunt.Net, Get Amazing custom logo designs for your business in just a few Hours! Start a online logo design contest for only $29 and watch designer logos roll in the same day!


User avatar
Active Member

Posts

Joined
Wed Feb 03, 2010 10:39 pm
Location - Belgium

Post by Artlife » Sat Feb 06, 2010 5:12 am

stefke1974 wrote:how did you do it for 1.4.0 ?

because, i did it also, and copy works, but now, when i click edit, it says, page not found.

???

can you help?
ok I'm sorry, I didn't see you had posted here first.

well, when you are viewing your products and decide which to copy, click copy, then when the page changes, you are looking at your copied product. so make your changes and then click save, and you'll be returned to your product list which will include your newest product. you can click edit on any of them and make more changes.
now the first time I did it I didn't realize right away I was looking at the copy, I expected the copy to show up on the list. so let's say you click copy and you think it's the original product and you don't click save or you hit the back button then that may cause your copy to be messed up.

if that's not the case then I have to assume you made some mistake in installation.
Use something like Notepad ++ to edit your php files.
Also make sure you are using the version for 1.4.0, you have to scroll all the way down the contribution page.

New member

Posts

Joined
Tue Feb 02, 2010 11:41 am

Post by Cyberdude » Sat Feb 06, 2010 5:54 am

Guys,

thanks to artlife, i found the problem.

my mistake.

i deleted the line public function update() { in product.php.

it works fine now.

thanks artlife. you saved me :D

Logohunt.Net, Get Amazing custom logo designs for your business in just a few Hours! Start a online logo design contest for only $29 and watch designer logos roll in the same day!


User avatar
Active Member

Posts

Joined
Wed Feb 03, 2010 10:39 pm
Location - Belgium
Who is online

Users browsing this forum: No registered users and 10 guests