Magento 2 - Category Image URL showing two paths - magento2

Buit of a strange one, but hopefully it's easy to resolve.
I have uploaded some product Category images to certain category pages in the Admin client but when I view them on the web they don't load. The reason appears to be that it is trying to load two paths in the src attribute, which are slightly different.
Any ideas what I need to do to resolve this... :-)
src="https://www.myurl.com/pub/media/catalog/category//pub/media/catalog/tmp/category/25mm.jpg"
As you can see there are two paths in the URL, one has "tmp" (in bold) and if I modify the SRC this one loads. It appears that it is prepending the URL?
Any ideas would be appreciated.
src="/pub/media/catalog/tmp/category/25mm.jpg" <- This one loads the image?

Since Magento 2.3.4 this problem occurs.
/vendor/magento/module-catalog/Model/Category/Attribute/Backend/Image.php
public function beforeSave($object)
In This method below code is creating issue
$value[0]['url'] = '/' . $baseMediaDir . '/' . $newImgRelativePath;
$value[0]['name'] = $value[0]['url'];
Update it with
$value[0]['url'] = $baseMediaDir . $newImgRelativePath;
$value[0]['name'] = $value[0]['name'];
This will fix issue
Do Not forget to override this file from your module to avoid direct core file changes
Github issue: https://github.com/magento/magento2/issues/28100

Which version of magento 2 do you use?
I've had a similar problem with magento 2.3.4
When you save a category for which you just added an image. The model that handles the category images won't move your image from the tmp folder to the pub/media/catalog/category (which should be the path to the image).
So you have to override to Image.php model from the catgeory to move the file from tmp after is saved.
Hope this will help you.

Related

Concatenation with static resource in Salesforce Lightning Component

I'm facing a weird challenge where I need to include a static resource image inside an aura:iteration loop.
The challenge here is this:
<img src="{!$Resource.testbox}"/>
This will display the image in the lightning component fine.
But if you want different images to be displayed based on a List you're running through aura:iteration the challenge begins.
How do I structure the src to use the variable to set the static resource name?
(the dt.img variable contains 'testbox', I have triple checked)
<aura:iteration items="{!v.extraDecoderTypes}" var="dt" indexVar="idx">
<img src="{!$Resource + dt.img}"/>
</aura:iteration>
In my head this should work fine, but it does not.
So I guess the problem is that $Resource should be $Resource. (with ".").
But if I do that in the code, I will get this error:
expecting an identifier, found '+' at column 12 of expression: $Resource. + dt.img
Trying without the "." will get uploaded to org, but the image will not display.
https://developer.salesforce.com/docs/atlas.en-us.234.0.lightning.meta/lightning/expr_resource_value_provider.htm
does not mention this exact case, but more how to get resource that are below one level in the directory structure.
Any tips would be greatly appreciated!

Programatically add images in simple product (using Object Manager Magento 2.3.7)

I'm using the Object Manager in order to add a few products from a csv (based on https://magecomp.com/blog/import-product-data-programmatically-magento-2/ ). So far everything is working and my images are temporarily stored in "var/tempImages/". When I pass that path into:
//$img is my path to "product.jpg", etc.
->setImage($img)
->setSmallImage($img)
->setThumbnail($img)
Images are not loading at all (doubled checked, they're in said path).
Any pointers on what could be missing to correctly map the path to image (or if I'm in something completely different).
Thanks.

Eclipse Plugin Development: Adding items to a working set with the path of the item?

Hello,
I'm an eclipse plugin development newbie looking for pointers to get me started on a particular project.
I am trying to build an eclipse plugin that will automatically construct a working set from a text file that simply consists of a list of file path names. The files/items need not share any parent directories. The rough idea is represented in the following diagram:
I am not asking for the solution to this task. That's the over-arching goal. To achieve that goal, I want to conquer some smaller goals first.
With that in mind, here's the smaller goal I'm currently trying to tackle:
In Eclipse, how can I prompt the user for a single file's path, and then add that file to an existing working set?
I'm not sure where to start. Should I work directly off of the existing org.eclipse.ui.workingSets extension point? Or should I use a collection of other extension points? How do I convert strings into something that can be added to a working set? Do I write code that directly modifies the workingsets.xml file?
Even with a much simpler goal, I still feel quite overwhelmed with the vastness of eclipse extension options. There are probably many ways to go about implementing something like this, but I just need one to get started.
Thanks a bunch!
To manipulate working sets you use the working set manager interface IWorkingSetManager. Get this with:
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
From this you can get a particular working by name with:
IWorkingSet workingSet = manager.getWorkingSet("name");
The contents of a working set is an array of IAdaptable objects:
IAdaptable [] contents = workingSet.getElements();
You add to the contents by adding to this array and setting the contents:
IAdaptable [] newContents
.... get new array with old contents + new contents
workingSet.setElements(newContents);
A lot of Eclipse objects implement IAdaptable, for a file in the workspace you would use IFile. You can use dialogs such as ResourceSelectionDialog to select resources from the workspace.

Magento layer navigation wrong product count

Problem : Product count is not correct on Layered Navigation in List Page for all attribute but category product counts are fine.
Magento Version : 1.7.0.2
I have removed all override of catalog file and folder and also uploaded magento core catalog file to check that is it problem of core file but Still i am not getting issue.
Example :
Manufacturer
Manufacture 1 (90)
Manufacture 2 (82)
Manufacture 3 (223)
But when i click on Manufacture 1 there will be 3 products.
One thing i found, in below mentioned code if I change Mage::getSingleton('catalog/layer'); to Mage::getModel('catalog/layer'); than product count is fine but product are not display according to filter.
app/code/core/Mage/Catalog/Block/Layer/View.php
Line no - 149
public function getLayer()
{
return Mage::getSingleton('catalog/layer');
}
I appreciate for any help.
Thanks in advance.
That's wrong to change layer singleton to the model. If it helps for you it means you break layer somewhere in your custom code... So this seems to be a problem in your local code. But first did you try to do reindex? Please start with reindexing product flat data and attributes. Then try to debug. Counts for attributes are calculated here: app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php:83 in method getCount(). Try to catch select object and review what actually it selects. xDebug is very useful for cases like this. If you don't use it then you can do in specified method just before return smth like
$a = (string) $select;
die($a);
Then you would have counts select and you can analyze it. Good luck!

Moodle local plugins and save_file

I've created a working form within a local plugin and it is inserting data fine into my custom table.
What I want tyo add now is a filepicker element that upon saving the form puts the file into a specified folder.
The filep[icker itself works fine but when I save the form no file appears, the code I'm using looks like this:
$mform->save_file('lowresCh', '/my_form/', false);
I've tried various things in the 'my_form' bit, but to no avail. The rest of the form still puts its data into the custom table and I can see my file in the mdl_files table (marked as draft).
With full debugging on I can get a warning of:
Warning: copy(/my_form/): failed to open stream: Is a directory in /...../lib/filestorage/stored_file.php on line 390
I don't know if I'm approaching it incorrectly or not, any help or pointers in the right direction would be most appreciated. 
Oh and I have read the Using the File API in Moodle forms page, useful in getting me to the point I'm at, but no further.
I solved it by using the filename as the second argument in save_file() and if I prepend a directory then all of the files will be saved within my plugin in a sub directory which is perfect.
So it looks like this now:
$mform->save_file('lowresCh', 'files/'.$mform->get_new_filename('lowresCh'), false);