Prestashop 1.6 : Use the manufacturers logo as product image - prestashop-1.6

I would like to know how to use the manufacturers' logo as a product image instead of the question mark (404.gif) when the product image is missing.
I guess it's located on classes/module/Module.php, on line 1507 :
copy(_PS_IMG_DIR_.'404.gif', _PS_TMP_IMG_DIR_.md5((int)$modaddons->id.'-'.$modaddons->name).'.jpg');
But I cannot found the correct thing to write instead

On "themes\default-bootstrap\product.tpl" replace this:
<img itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}"/>
By this:
<img itemprop="image" src="{$img_manu_dir}{$product_manufacturer->id}-large_default.jpg" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/>

Related

Asp Mvc : set inline css background-image:url with an image stored in the database

I store images in the database and can retrieve them in a view thanks to a Get Method from my Img Controller that returns a File([] fileContents, string contentType).
No problem to display it in a View with :
<img src="#Url.Action("Get", "Img", new { id = Model.ImgId})"
On the contrary, when I try to pass the URL of an image within an inline background-image: url, it does not work.
1) I tried this in the View using the same Img Controller to get the image :
<div style="background-image: url('#Url.Action("Get", "Img", new { id = Model.ImgId})')"></div>
Which renders this HTML but does not display the image :
<div class="imageBox" style="background-image: url('/Img/Get/2')"></div>
2) I tried this in the User Controller :
string formatWithoutPoint = user.Img.Format.Substring(1);
string imageBase64Data = Convert.ToBase64String(user.Img.Data);
string imageDataURL = string.Format("data:image/" + formatWithoutPoint + ";base64,{0}", imageBase64Data);
ViewBag.ImgSrc = imageDataURL;
And this in the View :
<div class="img" style="background-image: url('#ViewBag.ImgSrc')"></div>
which renders this HTML but does not display the image :
<div style="background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAU...')"></div>
I don't understand... have you any idea?
I know someone had the same problem but he did not share how he finally managed to solve it : ASP MVC: Upload Image from Database as Full Background CSS
Thanks in advance
I am such an idiot !
I was so focused on the background-image: url ('...') because the color syntax of visual studio would not get right that I completely forgot to give a size to that damn div !
Both methods are actually working well and displaying the image.
Sorry about that

Image doesn't show even when I can see it doing inspect in the browser

I have tried for more than two hours and I can not find an answer to this problem. I have this part of the code in a view strongly typed in MVC:
<td>
#foreach (var TitleBook in Directory.GetFiles(Server.MapPath("~/App_Data/Images"), "*.jpg"))
{
var fileName = Path.GetFileName(TitleBook);
if (Convert.ToInt32(fileName.Substring(0,3)) == item.IdBook)
{
<img src="#TitleBook" alt="Alternate Text" height="100" width="100">
}
}
</td>
The name of the image file is created so the three first characters in the filename are numbers.
When I run the code, I get the alternate message for the image in the hmtl view. However, the path to this image is well read and I know it because I can obtain it by doing inspect in the browser and calling only the src part of in another window which shows the image as expected (sorry for my English). The css is handled by the version of boostrap installed in VS2017.
Could someone point to my error here?
Your titleBook is a full physical path. But <img> wants an URL.
Untested:
<img src="~/App_Data/Images/#fileName" alt="Alternate Text" height="100" width="100">
BTW: with Directory.GetFiles(..., $"{item.IdBook:D3}*.jpg")) you wouldn't need the foreach loop.

UMBRACO: How to add image on template

So, I'm currently new to Umbraco and I'm following some tutorial videos on umbraco.tv. I have created my template and is currently using it to setup the Home Page for my website. I have all the front end working and its displaying properly.
My problem is on the images. I'm using a lot of images for my website and I'm trying to link it to content so the images can be easily changed(not sure if I'm making sense).
Navigation bar image
If you click the link above, that's how my current navigation bar look like. I want to be able to change the LOGO using Umbraco's media picker. However, everytime I do so, it either gives me the alt name or a runtime error.
This is the code for the image on the template.
<img src="#Umbraco.Field("navigationLogo")" height="100" width="50" alt="Logo">
I'd appreciate it if you can help me. I'm not sure if I've explained it properly so feel free to ask in detail. Thanks!
Edit -----
I am only coding on browser since it doesn't allow me to login to pull the codes locally (only on trial version since I'm just testing out if its a good CMS).
Not sure if I'm doing it correctly so I apologize. I wrote my code like this
#{
var navigationLogo = #Umbraco.AssignedContent.Site().GetPropertyValue("navigationLogo");
var navigationLogoMediaItem = #Umbraco.TypedMedia(navigationLogo);
<img src="#navigationLogoMediaItem.Url" height="100" width="50" alt="Logo" />
}
It's giving me the following error so far.
Compiler Error Message: CS1061: 'Umbraco.Web.UmbracoHelper' does not contain a definition for 'AssignedContent' and no extension method 'AssignedContent' accepting a first argument of type 'Umbraco.Web.UmbracoHelper' could be found (are you missing a using directive or an assembly reference?
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "WebBase.cshtml";
string navigationLogoMediaItem = "";
if (Model.Content.HasValue("navigationLogo"))
{
navigationLogoMediaItem = Model.Content.GetPropertyValue<IPublishedContent>("navigationLogo").Url;
}
}
<img src="#navigationLogoMediaItem" height="100" width="50" alt="Logo" />
you can try this
I'm going to make a few assumptions so please bear with me here.
Assumption 1) On your home node (assuming a document type of 'home") you have a property on it called "navigationLogo".
Assumption 2) This is a media picker data type
Assumption 3) You are using Umbraco 7.6 or newer.
Assumption 4) You aren't using Models Builder
So, assumptions in place there are a few steps you need to go through.
1) Get the navigation logo where ever you are in the site.
var navigationLogo = #Umbraco.AssignedContent.Site().GetPropertyValue("navigationLogo");
2) next, you'll need to get the media item as I belive you will only have a UDI at this stage.
var navigationLogoMediaItem = #Umbraco.TypedMedia(navigationLogo);
3) You'll want to put a null check in at this point but to get the url of the logo you simple need to do this:
<img src="#navigationLogoMediaItem.Url" height="100" width="50" alt="Logo" />
That should get you what you are after. :-)
You can simply try out this code.
memberImage is your document type field name
#{
var image = Umbraco.TypedMedia(#Umbraco.Field("memberImage").ToString());
<img src="#image.Url" style="max-width:250px">
}

XPath Node selection

I am using HtmlAgilityPack to parse data for a Windows Phone 8 app. I have managed four nodes but I am having difficulties on the final one.
Game newGame = new Game();
newGame.Title = div.SelectSingleNode(".//section//h3").InnerText.Trim();
newGame.Cover = div.SelectSingleNode(".//section//img").Attributes["src"].Value;
newGame.Summary = div.SelectSingleNode(".//section//p").InnerText.Trim();
newGame.StoreLink = div.SelectSingleNode(".//img[#class= 'Store']").Attributes["src"].Value;
newGame.Logo = div.SelectSingleNode(".//div[#class= 'text-col'").FirstChild.Attributes["src"].Value;
That last piece of code is the one I am having problems with. The HTML on the website looks like this (simplified with the data I need)
<div id= "ContentBlockList" class="tier ">
<section>
<div class="left-side"><img src="newGame.Cover"></div>
<div class="text-col">
<img src="newGame.Logo http://url.png" />
<h3>newGame.Title</h3>
<p>new.Game.Summary</p>
<img src="newGame.StoreLink" class="Store" />
</div>
</div>
</section>
As you can see, I need to parse two images from this block of HTML. This code seems to take the first img src and uses it correctly for the game cover...
newGame.Cover = div.SelectSingleNode(".//section//img").Attributes["src"].Value;
However, I'm not sure how to get the second img src to retrieve the store Logo. Any ideas?
newGame.Cover = div.SelectSingleNode(".//img[2]").Attributes["src"].Value;
You didn't post the entire thing but, this should do the trick.
You can try this way :
newGame.Cover = div.SelectSingleNode("(.//img)[2]")
.GetAttributeValue("src", "");
GetAttributeValue() is preferable over Attributes["..."].Value because, while the latter throws exception, the former approach returns the 2nd parameter (empty string in the example above) when the attribute is not found.
Side note : your HTML markup is invalid as posted (some elements are not closed, <section> for example). That may cause confusion.

Graph background-image resizing without PHP

I've read several helpful answers in re. image resizing using PHP and max-height etc.: Image resize script
However, my problem is that I want to resize an image of a graph that I am retrieving from another site (USGS), and putting into a site (zenfolio) that supports HTML and JavaScript, but not PHP. I have tried adjusting the specified height and width, but keep on ending up resizing only the amount of the image that shows on the page, and not the image itself (sorry I cannot post images as I am a new user).
I just posted them as png's above to demonstrate the problem, but the images are generated as follows:
<div id="riverlevels">
<center>
<div id="MyWidget" style="background-image:url(http://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=12354500&parm_cd=00065&period=21);width:576px;Height:400px;">
<br/>
Montana River Photography </div>
</center>
</div>
</div>
This same image can be generated using this JavaScript, but for some reason that does not allow me to display more than one variable graph per page (I want to show both discharge (00060), and gage height (00065)):
<script type="text/javascript">
wStation = "12354500";
wDays = "21";
wType = "00065";
wWidth = "576px";
wHeight = "400px";
wFColor = "#000033";
wTitle = "";
document.write('<div id="gageheight"></div>');
document.write('<scr'+'ipt type="text/JavaScript"src="http://batpigandme.com/js/showstring.js"></scr'+'ipt>');
As you can tell, I have to use a separate site that I own to create the JavaScript file. The graphs are currently located in various iterations at:
montanariverphoto.com/test
clark fork gage height
I sincerely apologize if I have missed an obvious answer to this! I basically created this widget by reverse engineering a widget from another site, so perhaps my call is incorrect all together.
Does it absolutely have to be a background image? Scaling them is possible (using background-size), but this property is not well supported (basically it won't work in Internet Explorer). Your code would work almost as-is if you can use an image tag instead:
<img src="http://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=12354500&parm_cd=00065&period=21" width="576" height="400" alt="..." />
for your other problem, ids need to be unique on a page. In your code example you are creating a div with the id of gageheight, and this is ID is hardcoded into your javascript file at http://batpigandme.com/js/showstring.js. Since you can only have one element with this ID on the page, if you repeat the code later on it won't work. You'd need to change this script so that you could pass in the ID as a variable, something like:
wTitle = "";
wElement = "gageheight";
document.write('<div id="gageheight"></div>');
document.write('<scr'+'ipt type="text/JavaScript"src="http://batpigandme.com/js/showstring.js"></scr'+'ipt>');
and then in your JS:
var myElement = document.getElementById(wElement);
var JavaScriptCode = document.createElement("script");
JavaScriptCode.setAttribute('type', 'text/javascript');
JavaScriptCode.setAttribute("src", 'http://batpigandme.com/js/data2.js');
myElement.appendChild(JavaScriptCode);

Resources