Skip to main content

Store images in special folder on VIEW execution

More
12 years 3 months ago - 12 years 3 months ago #159427 by PeterChain
I have a very specific need that should be easy to solve by a PHP expert so I beg to the community for a little help:

I need all images shown in a product view to be stored in a certain folder of the server for a later download.

Precisely the code should do this on view render:

First: Delete all contents in www.mydomain.com/img_export THIS PART SOLVED. Code will be supplied for other PHP dummies at the end of the project.

Second: Render my view on the page (no problem with this, is a product view so no help needed on this).

Third: As the product view keeps looping picking all VIEWABLE products each image for each full image (not thumbs) shown product would be stored in folder www.mydomain.com/img_export

Additionaly to make it perfect (maybe this should be integrated in the SHOW view):

When view render is finished the folder content would be zipped.
After being zipped an automatic download would be triggered.


i think all this could be accomplished with short pieces of code but I'm not a real PHP coder so all help will be appreciated.

Thanks!
Last edit: 12 years 3 months ago by PeterChain.

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

More
12 years 3 months ago #159446 by PeterChain
*** UPDATE ***

I have this code taken from a product view to be displayed in a lisiting_table but there may be some object data transfer wrong:

Code:
<?php if (!empty ($this->element->images) && count($this->element->images) > 1) { foreach ($this->element->images as $posicio => $image) { $height = $this->config->get('product_image_y'); if(empty($height)) $height=$this->config->get('thumbnail_y'); if ($posicio > 0) { echo $this->image->display($image->file_path, false, '', '','', 140, $height); echo $image->file_path; } } } ?>

This code works fine in a product view showing all pictures for a product and its relative path written under the picture,

but in a listing_table simply does not compute,

I think the expression $this->element->images might be wrong but don't know how to correctly adapt it.

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

More
12 years 3 months ago #159530 by PeterChain
UPDATE:

After trying a zillon code variations I came up with this very simple code which makes half the work:
Code:
<?php defined('_JEXEC') or die('Restricted access'); if(!empty($this->rows)){ foreach($this->rows as $row){ $this->row =& $row; $db = JFactory::getDBO(); echo $this->image->display($this->row->file_path, false, '', '','', 320, $height); echo $this->row->file_path; } }?>

this renders the main picture for each product together with its file_path.

It works but I need to see all pictures for every product, not only the main one. I get this in other parts of the site but recycling the code doesn't work.

This code is included inside listing_div view trigered by a Type of content Product menu.

PLEASE somebody inspire me!

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

More
12 years 3 months ago #159474 by nicolas
Hi,

That code doesn't work on a products listing because the data is not loaded at all.
On products listings, only the main product image is loaded and its data is stored in $this->row.

If you want to display all the images of a product on a listing, first you'll have to load the data of the images of the product from the hikashop_files table with a MySQL query where the file_type is "product" and the file_ref_id is the product id of the product stored in $this->row->product_id.
Then, once you have the data of the files in an array of objects of image data, you can loop on them like you loop on the $this->element->images array on the product page and display them.

If you want to change the folder where the system look for the images with dynamic code, you can set the variables below before calling the display function:
Code:
$this->image->uploadFolder $this->image->uploadFolder_url $this->image->main_uploadFolder $this->image->main_uploadFolder_url
The following user(s) said Thank You: PeterChain

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

More
12 years 3 months ago #159563 by PeterChain
Great!

I'lll try to code a query for this.

Thank you.

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

Time to create page: 0.175 seconds
Powered by Kunena Forum