WIX Help Random start in slide deck gallery - random

THE SETUP
On my WIX site I have:
a collection called Ads980x120 with a few entires (ads and links)
a dataset on the page linked to that collection
a 980p x 120p slide deck gallery linked to that dataset (image field and link field)
It currently works perfectly rotating those images on the site.
THE PROBLEM
I do not want the same image to show and start the rotation when the page loads. I want the images to be shown in a random order. This could be option #1: A random starting image and then continuing in the same order, or option #2 a random starting image AND random order. Either one would be fine based on difficulty level.
Lastly, there are some pages that have a couple different galleries so ideally I would be able to paste this code multiple times on the page (once for each gallery) and I would like the links to open into new windows.
I hope this makes sense and thank you in advance for any advice or help!

This is pretty simple to do if you don't mind a little flicker. Using a dataset you can load the gallery and then randomize the images, but you will see the original order for a short bit.
To do this without that kind of flicker, I think you need to use the wix-data API.
Here's the code I came up with. You will have to modify it to fit your collection name and structure as well as your gallery ID. I am also using the Lodash npm module to randomize the order of the images, but you could write this code yourself. Finally, you need to remove all the default images from the gallery. All that being said, you will still have a flicker, but from a blank gallery to one with a random image.
import {rendering} from 'wix-window';
import wixData from 'wix-data';
import _ from 'lodash';
$w.onReady( async () => {
if(rendering.env === 'browser') {
const {items} = await wixData.query('CollectionId').find();
const images = items.map(item => ({src: item.image, title: item.title}));
const shuffledImages = _.shuffle(images);
$w('#galleryId').items = shuffledImages;
}
} );

Related

Laravel elfinder resize and copy uploaded image to multiple dimensions

Hello I'm using backpack which uses elfinder as a file manager, and i want to achive te following:
when an image is uploaded I want to create 3 copies of it
one with it real dimension
the second is 200x200
and the third 50x50
Note: Like WordPress which has this mechanism built in (uploading multiple sizes of the image)
Unfortunately, there's no easy way to do that thanks to elFinder itself. The PHP package for elFinder doesn't have events or anything like that, for you to customize its upload behaviour. And doing it in Javascript would probably not be a good idea.
But thanks to Backpack, there's one thing you could do, that could be useful. You can use Model Events inside your CrudControllers, to do stuff after the cretate/update form has been submitted. For example:
when the updated event happens, check if that file that was upload (with real dimensions) has thumbnails; if so, do nothing;
if not, create the thumbnails using a library like Intervention image that is already included in Backpack;
So it would looks something like this:
public function setup()
{
// ...
Product::saved(function($entry) {
if (!$entry->hasThumbnailsForAttachment()) {
$entry->generateThumbnailsForAttachment()
}
});
}
Then in your Model you could create these two methods, hasThumbnailsForAttachment() and generateThumbnailsForAttachment().
Hope it helps!

Oscommerce display default product image and prevent it from deletion

I am working on an oscommerce project where i want to display default product image (i.e no image available) if product image is not uploaded.And even i want it to prevent from deletion.I have tried to upload product not available image for 2-3 products but when deleting products i.e final last product image also gets deleted from the folder.I want that if user doesn't upload image then by default no_product_available.jpg should be shown in CATEGORIES.php as well as PRODUCT_INFO.php.
Can anyone help me to do this ? I am using oscommerce default template.
I think I understand what you would like to do... Pretty much you're saying that if someone doesn't upload an image with a product or category then you would like the no_image.jpg image to be displayed instead of nothing being displayed. Additionally, you would like for the no_image.jpg to not be deleted if the category or product is deleted. I think I can help with this...
You need to modify the tep_image() function located in catalog/includes/function/html_output.php
Replace...
if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
return false;
}
With...
if (!is_file($src)) {
$src = "images/no_image.jpg";
}
Now when you use the tep_image() function if no image was uploaded or if the file is specified but missing from the server then no_image.jpg will be displayed. When the category or product is deleted the is no_image.jpg file is not associated with the category or product so nothing is deleted. Obviously, replace "images/no_image.jpg" with the correct location and filename for your default no image file. Also, you may wish to modify the code above to get the specific behavior you want but this is a good starting point to achieve what you want.
The index.php and product_info.php pages use tep_image()... So, you should be all set there. If you're making your own page or modifying an existing one then you would of course need to use the tep_image() function to get the no_image.jpg output functionality. The parameters for tep_image() are...
tep_image($src, $alt = '', $width = '', $height = '', $parameters = '')
UPDATE:
tep_image should already be in both the index.php (the page that generates the category/product list pages) and product_info.php. Just open either file and search for "tep_image" without quotes or parentheses. You should find several instances in both files. Examine the code to understand what has already been done so that when you add a new image you understand the correct syntax.
Pretty much just place tep_image where you want your new image to show up on the page. You need to be familiar with HTML and PHP to read through the page and determine where you want the image placed. If you want to move the current image then you might be able to just cut and paste the current tep_image code to a your new location.
You can also use "Inspect Element" in Chrome in the right click menu to help determine location. Just open the page you want to add an image to and right click in the area you want to add an image to. Then look at the surrounding page source code. Now you have an idea what to look for in the PHP file.
BTW, the index.php page is a little tricky. That page is responsible for the homepage, category listing pages, and product listing pages. Also, there are several other module PHP pages that are Included (so the source code is in a different file that you'll need to track down if that's the area you want to add the image to). Make sense ;-)
Give it a try and write back with what want specifically and you did to achieve it. There are lots of people that have helped me in the past. So, I'm happy to help.

limiting the number of images you can upload

UPDATED QUESTION
OK new idea.
.on('deleteComplete', function(event, id, fileName, responseJSON) {
}
how can I call the sessionRequestComplete function. I think this might "refresh" the array and solve this issue.
Matt
I am trying to limit the number of images a person can upload.
I also need to include the ability to have the orginal file plus two scaled images.
When I tired to use the
validation: {
itemLimit:6
}
option I needed to triple the number of items since I was have the system upload three images.
I got this all to work but the issue I am having is if I delete an image and then add a new image and to this a couple of times, the system will then alert me that I have exceeded the itemlimit.
is there a way to "refresh" the items in the current session of the uploader in the deleteComplete function.
thanks.
Matt
The itemLimit validation rule is quite literal. You'll need to keep this in mind when you determine a proper number. if you are using it with scaled image generation turned on.
If you are looking to adjust this value dynamically, or expect it to work differently, please open up a feature request.

Magento how to display a block with a small image over the actual product image by using product id

I have a table which contain some product ids and small images. I need to display the image over the actual product image. how can i display the small image in every place where the product image is appeared, that is: product view, related product, list, grid.. without changing there template.
Is there any programmatic way to display the small image everywhere without the need to change something in every template where the product image is display.
Yes this is quite possible. Not easy though.
There is a helper for that
Mage_Catalog_Helper_Image
Within the helper extend the init function and rewrite the assignment of the watermark. Enable it in backend in system > configuration > design > watermark. Then use the helper init function to assign the additional image you have.
When you are finished, make sure you clean the cache AND image cache. Otherwise the images are not generated.
It is still possible that some images wont have the additional image overlay. But this is more of a template issue that doesn't use the helper function.

Thumbnail different from actual image

Here is a scenerio, on my products page I want to add an image of the product dimensions but for this image I want to use thumbnail which is different from the actual image which will say Dimensions. This will be applied to all the products across the store. So there will be one thumnail image for all the products that will be associated with it’s dimensional image. I want to show it on the gallery page as last image.
Any help would be greatly appreciated.
Regards,
Avian
If I'm understanding you correctly, you just want every product to have a thumbnail that can be set to be one of several images.
You will need to create a custom attribute for your products, and then programmatically set your current inventory to your defaults. (Or manually change them) There is a knowledgebase article that will assist you with custom options (if applicable), or another article I found via Google to assist in custom attributes.
It's likely not the best way of doing it, but an example of the JavaScript method I was talking about is simply to add the following into a JS file on your server.
document.observe("dom:loaded", function() {
$$('.catalog-product-view .image-thumb:last img').each(function(item){item.src = 'http://domain.com/path/to/image.jpg'});
}

Resources