Prestashop - Product images not showing in category loop with friendly URLs - loops

My product images don't show in categories after turning on friendly URLs. If I turn it off, they appear again.
I have tried :
Re-generating pictures in the back-office
Turning off cache
When I inspect the code with frienly URLs on, image links show in a weird format : https://www.website.fr/3689-home_default/.jpg
Prestashop 1.6
EDIT :
It appears the problem comes from the way I query products in my custom category TPL. I am querying products from subcategories manually (i am not displaying all products of the category at once) like this :
{foreach from=$subcategories item=subcategory}
{if $subcategory.id_category == 64659}
{assign var="subcategory_id" value=$subcategory.id_category}
{assign var="subcategory_object" value=$subcategories_objects.$subcategory_id}
{include file="./product-list.tpl" products=$subcategory_object->getProducts('1','1','100','price','asc')}
{/if}
{/foreach}
When I query products with the following line, images appear as normal :
{include file="./product-list.tpl" products=$products}
In the product-list.tpl, this is the line which gets the image :
src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}"
Thank you.

By default you will get array of subcategories only in $subcategories variable; so getting products of that sub category will never work $subcategory_object->getProducts('1','1','100','price','asc') until and unless you do have sub category object.
First you need to get sub category object and for that you need to override default function getSubCategories from classes/Category.php file by making override of Category class.
Follow below mentioned steps(1-2) to create override class and modify code in template mentioned in step(3)
1) Make file Category.php on path override\classes and add below code in it.
this will override default function to get category.
<?php
/**
* #override classes/Category.php
*
*/
class Category extends CategoryCore
{
/**
* #override
* Return current category childs
*
* #param int $id_lang Language ID
* #param bool $active return only active categories
* #return array Categories
*/
public function getSubCategories($id_lang, $active = true)
{
$result = parent::getSubCategories($id_lang, $active);
foreach ($result as &$row) {
// Preapre object of sub category here
$row['object'] = new Category($row['id_category'], $id_lang);
}
return $result;
}
}
2) Delete file class_index.php from cache folder.
Your override function is ready now.
3) Add below code to your template to show products
{foreach from=$subcategories item=subcategory}
{if $subcategory.id_category == 64659}
{include file="./product-list.tpl" products=$subcategory.object->getProducts('1','1','100','price','asc')}
{/if}
{/foreach}
Hope this will work for you.

Related

push an array while foreach other array laravel

I'm using laravel package commentable by faustbrian. i've been getting the comment for a post using just like in documentation in github . I want to search the information for user who post the comment, e.g the user avatar, address, and other information as well. I want to include the user information (which is an array) to the current position index of array (while for each i push it). the problem is, i tried using array_push, array_merge and $data[$key]=>$value as well. but none of them is working when i dd the variable. please help.
public function notaPengurusan($id){
$comments=Complaint::findOrFail($id)->comments->toArray();
foreach ($comments as $comment){
$creator=User::findOrFail($comment['creator_id'])->toArray();
array_push($comment,$creator);
}
dd($comments);
return view('complaint::notapengurusan',compact('comments'));
}
image when i dd the image
You need to use array index and its global variable $comments
foreach ($comments as $key=>$comment){
$creator=User::findOrFail($comment['creator_id'])->toArray();
array_push($comments[$key],$creator);
}
you should add user() relationship in your Comment Model :
public function user(){
return $this->belongsTo('App\Model\User','creator_id');
}
then no need to use for loop and finding user each time , use with('user'):
$comments=Comment::where(['post_id'=>$post_id])->with('user')->orderBy('created_at','desc')->paginate(12);

Inserting image into visualforce email template (without hard-coding IDs)

The "official" solution for including images in visualforce email templates suggests hard coding IDs in your template to reference an image file stored as a document.
https://help.salesforce.com/HTViewHelpDoc?id=email_template_images.htm&language=en_US
Is there a better way that avoids hard coding instance ID and OID? I tried using the partner URL to grab the instance ID, but I got the following error
Error Error: The reference to entity "oid" must end with the ';' delimiter.
Using:
{!LEFT($Api.Partner_Server_URL_140,FIND(".com/",$Api.Partner_Server_URL_140)+3)/
to replace "https://na2.salesforce.com/"
in
"na2.salesforce.com/servlet/servlet.ImageServer?id=01540000000RVOe&oid=00Dxxxxxxxxx&lastMod=1233217920"
Should I use a static resource instead?
I've arrived here looking for an answer for this question related to hardcoded ID and OID in Visualforce e-mail templates. Well, I found a workaround for that.
First I needed to create a Visualforce Component:
<apex:component access="global" controller="LogomarcaController">
<apex:image url="{!LogoUrl}" />
</apex:component>
In the respective controller class, I've created a SFInstance property to get the correct URL Salesforce Instance, LogoUrl property to concatenate SFInstance and IDs... And Finally I've used Custom Settings (Config_Gerais__c.getInstance().ID_Documento_Logomarca__c) to configurate the ID of Image (in my case, Document Object) on Sandbox or Production:
public class LogomarcaController {
public String LogoUrl {
get {
id orgId = UserInfo.getOrganizationId();
String idDocumentoLogomarca = Config_Gerais__c.getInstance().ID_Documento_Logomarca__c;
return this.SfInstance + '/servlet/servlet.ImageServer?id=' + idDocumentoLogomarca + '&oid=' + orgId ;
}
}
public String SfInstance
{
get{
string SFInstance = URL.getSalesforceBaseUrl().toExternalForm();
list<string> Dividido = SFInstance.split('.visual', 0);//retira o restante a partir de .visual
SFInstance = dividido[0];
dividido = SFInstance.split('://',0);//retira o https://
SFInstance = dividido[1];
if(!SFInstance.contains('sybf')) //managed package prefix, if you need
{
SFInstance = 'sybf.'+ SFInstance;
}
return 'https://'+SFInstance;
}
}
}
And finally, I've added the component in Visualforce template:
<messaging:emailTemplate subject="Novo OfĂ­cio - {!relatedTo.name}" recipientType="User" relatedToType="Oficio__c" >
<messaging:htmlEmailBody >
<c:Logomarca />
</messaging:htmlEmailBody>
<messaging:plainTextEmailBody >
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
PS: Some of my variables, properties and comments are in my native language (portuguese). If you have some problems understanding them, please ask me!
We ran into a similar problem and after trying various solutions, the following worked for us. In our case the image is uploaded as a content asset(https://help.salesforce.com/articleView?id=000320130&type=1&language=en_US&mode=1)
Solution:
<img src="{!LEFT($Api.Partner_Server_URL_260,FIND('/services',$Api.Partner_Server_URL_260))}/file-asset-public/<Image_Name_Here>?oid={!$Organization.Id}&height=50&width=50"/>

Add a custom head title to a filtered view page in Drupal

I have a site that filters the blogs by specific expeditions.
Currently, when I click on the blog related to that specific expedition it displays the head title (in browser window) as "| mysite". So all the filtered views have the same head title.
I would like to add a custom head title for each filtered view.
So, for example, I would like the blogs that have do with Expedition 1 to have a filtered view with the head title "Expedition 1 blogs | Mysite".
Does anyone have any suggestions?
I suggest you do this :
for Views 3:
If you have a view and you want to be able to programmatically change the title of, you can do it by implementing hook_views_pre_render in your custom module:
<?php
/**
* Implements hook_views_pre_view().
*/
function MODULENAME_views_pre_render($view) {
if ($view->name == 'my_view_name') {
if ($view->current_display == 'my_display_name') {
$view->set_title('my new title');
}
}
}
?>
I hope it helps.
This question may be related to this one where the following solution was given:
In template.php:
function YOUR_THEME_preprocess_page(&$vars){
// You can test if you're in your specific views of course
$path = $_GET['q'];
if (strpos($path,'YOUR_PATH_STRING') !== false) {
drupal_set_title('YOUR_TITLE');
}
}
I also saw the reference to the Page Title module that could suit you.
You can set views page title programmatically by using below hook in modules.
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
if($view->name == 'VIEW_MACHINE_NAME'){
$view->display[$view->current_display]->display_options["title"] =
$view->display[$view->current_display]->handler->options["title"] =
$view->human_name .' - '.$_GET['field_video_by_event_value'];
}
}

Template database population

Need to populate a template:
<div id="atk-layout" class="atk-wrapper">
<?$pastor?>
<?$missionstatement?>
<?$tmissionstatement?>
<div id="atk-footer-guard"></div>
</div>
In the Page I have this:
<?php
class View_Belfry extends View {
function init(){
parent::init();
q=$this->api->db->dsql();
$q->table('gum')->getAll();
foreach($q as $row){
switch ($row['sequence']) {
case 0:
$Pastor = $row['content'];
break;
case 1:
$MissionStatement = $row['content'];
break;
case 2:
$TMissionStatement = $row['content'];
break;
}
$this->template->set('Pastor',$Pastor); <<<<<
in the above line how do you add more than one Element
I either get a blank page or one Field displayed using different syntaxes
What is the syntax for multiple content tags in a template. Or am I missing some design feature? I get the first tag or a blank screen. The table field names don't match the template content names because the table field name "section" holds the name.
Like so:
Database table:
<?php
class Model_Gum extends Model_Table {
public $table="gum";
function init(){
parent::init();
$this->addField('section');
$this->addField('content')->type('text');
$this->addField('publish')->type('boolean');
$this->addField('sequence');
}
}
Thanks
You are trying to display array in View.
To display multiple content you need to use Lister, CompleteLister, Grid or CRUD class.
Also you are using dsql for no reason. It's more simple to use model.
$m = $this->add('Model_Gum');
Now add CompleteLister View (or other).
$l = $this->add('Your_Lister');
$l->setModel($m);
Create Your_Lister class witch extends on of the lister View and make necessary conditions inside
function formatRow(){
parent::formatRow();
}

Styling/Theming Drupal 7 Content Type Record

I developed a Content type of "Car Sales" with following fields:
Manufacturer
Model
Make
Fuel Type
Transmission (Manual/Automatic)
Color
Registered? (Yes/No)
Mileage
Engine Power
Condition (New/Reconditioned/Used)
Price
Pictures (Multiple uploads)
I have developed View of this Content Type to display list of cars. Now I want to develop a screen/view for individual Car Sale Record like this:
Apart from arranging fields, please note that I want to embed a Picture Gallery in between. Can this be achieved through Drupal 7 Admin UI or do I need to create custom CSS and template files? If I need to edit certain template files/css, what are those? I'm using Zen Sub Theme.
I would accomplish this by creating a page, and then creating a node template to accompany it. Start by creating a new node, and then record the NID for the name of the template.
Then, in your template, create a new file, and name it in the following manner: node--[node id].tpl.php
Then, in that file, paste in the following helper function (or you can put it in template.php if you're going to use it elsewhere in your site):
/**
* Gets the resulting output of a view as an array of rows,
* each containing the rendered fields of the view
*/
function views_get_rendered_fields($name, $display_id = NULL) {
$args = func_get_args();
array_shift($args); // remove $name
if (count($args)) {
array_shift($args); // remove $display_id
}
$view = views_get_view($name);
if (is_object($view)) {
if (is_array($args)) {
$view->set_arguments($args);
}
if (is_string($display_id)) {
$view->set_display($display_id);
}
else {
$view->init_display();
}
$view->pre_execute();
$view->execute();
$view->render();
//dd($view->style_plugin);
return $view->style_plugin->rendered_fields;
} else {
return array();
}
}
Then add the following code to your template:
<?php
$cars = views_get_rendered_fields('view name', 'default', [...any arguments to be passed to the view]);
foreach ($cars as $car): ?>
<div>Put your mockup in here. It might be helpful to run <?php die('<pre>'.print_r($car, 1).'</pre>'); ?> to see what the $car array looks like.</div>
<?php endforeach;
?>
Just change the placeholders in the code to whatever you want the markup to be, and you should be set!
As I mentioned above, it's always helpful to do <?php die('<pre>'.print_r($car,1).'</pre>'); ?> to have a visual representation of what the array looks like printed.
I use views_get_rendered_fields all the time in my code because it allows me to completely customize the output of the view.
As a Reminder: Always clear your caches every time you create a new template.
Best of luck!

Resources