Prestashop set a smarty variable on a hook - prestashop

I would like to assign a smarty variable on the hook actionAuthentication which get triggered when an user successfully connects and unset it whenever the user disconnects.
so I can manage my content depending on the connexion with a condition like the following :
<ul id="menu">
<li>
<p>Name :</p>
{if $my_variable}
<span class="employee-name">{$my_variable}</span>
{else}
<span class="employee-name">Firstname Lastname</span>
{/if}
</li>
</ul>
How could I assign a global smarty variable from a hook ?
Here is what I have tried but it doesn't work:
public function hookActionAuthentication()
{
$result = 'Myself';
$this->context->smarty->assign([
'my_variable' => $result
]);
}

You don't need to use hookActionAuthentication($params), you should assign $this->context->customer->fistname.' '.$this->context->customer->lastname.
you can use function isLogged to check if customer is loggued or not
$this->context->customer->isLogged()

Related

Favourite Unfavourite From Axios API in Vuejs

I am fetching data from An Api, Array is coming fine, In the V-For Loop
<div style="width: 20px; float: right">
<i class="fa fa-heart-o" #click="favourite(item.content_id)" v-if="item.is_fav_status == 0"></i>
<i class="fa fa-heart" #click="favourite(item.content_id)" v-if="item.is_fav_status == 1"></i>
</div>
So If, it is coming '0' from response then it is not favourited, and if it is '1' then its favourited already.
Now, If its not favourited, and Upon Click, It is getting Favourite Successfully using some POST Api, But I want to make it reactive, So Icon and Function Change Accordingly, Upon Doing Favourite and Unfavourite
Pass the whole item to the click handler:
#click="favourite(item)"
In there, toggle the value, along with whatever you are already doing with the content_id:
async favourite(item) {
const response = await axios.post(url) // Existing call can use `item.content_id`
item.is_fav_status = !item.is_fav_status; // Toggle the value
}

Use of undefined constant message - assumed 'message' (this will throw an Error in a future version of PHP) laravel 6

Hi I was create one view and created one controller.
I want to give validation to form input field using bydeault Laravel error but I m getting error
"Use of undefined constant message - assumed 'message' (this will throw an Error in a future version of PHP)"
My code of controller and view as follow:
index.blade.php
#extends('app')
#section('title','Services Page')
#section('content')
<h1>Welcome to laravel 6 Services Section</h1>
<h4>lets do something better</h4>
<form action="/service" method="POST">
<input type="text" name="fname" autocomplete="off">
#csrf
<button>Add Service</button>
</form>
#error('fname') {{ message }} #enderror
<ul>
#forelse($services as $service)
<li>{{ $service->name }}</li>
#empty
<li>No services Available</li>
#endforelse
</ul>
#endsection
nd controller as follows :
ServiceController.php
public function store()
{
$name_validate = request()->validate([
'fname' => 'required'
]);
$service = new \App\Service();
$service->name = request('fname');
$service->save();
return redirect()->back();
// dd(request('fname'));
}
But I am getting error when form submit button not validate.
Any issue with this code let me know. I am new learner in laravel
Add the $ to the message:
#error('fname') {{ $message }} #enderror

Scope a single input in Vue built from JSON

I am building a simple quiz with vuejs. I've been working in https://codepen.io/jasonflaherty/pen/NBaJLO on this. I am able to get the correct responses to the checked input, however, it is not scoped to this.input and cascades to all radio buttons. I tried to use bind class with:
<span class="" v-bind:class="{ 'badge badge-success' : isCorrect, 'badge badge-danger' : isWrong, 'showthis' : showIt }">{{response.correct}}</span>
and am currently using:
v-if="isCorrect"
v-if="isWrong"
However, it is the same issue with the scope bound to the same input vs all of them.
What am I missing in vue to make this distinction?
You need to track at the question level rather than the global level.
Here are a couple simple changes you can make. Notice the input changes for value and v-model and also the conditions for the correct/wrong spans. This creates a property, selection on each question to track the currently selected answer for this specific question.
<li v-for="response in question.responses">
<label class="form-check-label">
<input class="form-check-input" type="radio"
:key="index"
:name="question.group"
:value="response.text"
v-model="question.selection">
{{response.text}}
<span v-if="question.selection === response.text && response.correct ==='Correct!' ">
Correct
</span>
<span v-else-if="question.selection === response.text && response.correct !=='Correct!' ">
Wrong
</span>
</label>
</li>
You could clean it up some more by altering your data model. There is no reason to save the correct text in the data. You can simply have the answer as a property and determine the textual response based on the selection.
var quizquestions = {
questions: [
{
text: "Subtract 219 from 500.",
group: "qone",
responses: [281, 719, 218, -219],
answer: 281, // correct answer
selection: null, // for v-model to track selected
},
]
};

Returning $key in AngularFire 5

I have the following code that works with AngularFire 5:
export class NavigationComponent {
items: Observable<any[]>;
constructor(db: AngularFireDatabase) {
this.items = db.list('/pages', ref => {
let query = ref.limitToLast(100).orderByChild('sortOrder');
return query;
}).valueChanges();
}
}
But now need to return item.$key which apparently is no longer returned by default in AngularFire 5. I see mention in the migration guide of needing to "map" this, but can't seem to get the right syntax working on the above code.
Update: followed the advice below, and it seemed to have worked but there appears to be some difference still between the behavior between old and new.
<nav class="nav-standard">
<app-logo></app-logo>
<div class="nav-dropdown">
<ul *ngFor="let item of items | async | filter : 'parent' : '00000000-0000-0000-0000-000000000000'" class="nav-dropdown">
<li>
<a mat-button class="mat-button" href="{{item.path}}" data-id="{{item.key}}" target="{{item.target}}" title="{{item.tooltip}}" [attr.data-sort]="item.sortOrder" *ngIf="item.content; else elseBlock">{{item.menuText}}</a>
<ng-template #elseBlock>
<a mat-button class="mat-button" data-id="{{item.key}}" target="{{item.target}}" title="{{item.tooltip}}">{{item.menuText}}</a>
</ng-template>
<ul class="nav-dropdown-content">
<li *ngFor="let childItem of items | async | filter : 'parent' : item.key" class="">
<a class="mat-button" href="{{childItem.path}}" data-id="{{childItem.key}}" target="{{childItem.target}}" title="{{childItem.tooltip}}" [attr.data-sort]="childItem.sortOrder">{{childItem.menuText}}</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
The nested *ngFor never seems to fire, whereas before it did. It appears that items in the nested *ngFor is null ?? I found if I create another Observable in my component called childItems and assign duplicate logic to that, it works okay -- but to me that feels dirty and wrong. How can I get the data in the observable to persist long enough to use it in the nested *ngFor ?
item key information isn't 'free' anymore upon the new AngularFire API changes. Instead of use '.valueChanges()' to turn reference into Observable, you can use '.snapshotChanges()':
.snapshotChanges()
.map(changes => {
return changes.map(change => ({key: change.payload.key, ...change.payload.val()}));
})
from then on you can reference item key by using 'item.key' (notice that you cannot use '$key').

Using VueJS with a PHP Variable

I'm attempting to bind a HTML element which contains a string echoed via PHP so that I can use it with VueJS. Essentially what I am going to be doing is switching between GBP and USD depending on some php/mysql database queries (USD is default value). Here is a simplified example of what I have tried so far.
<div id="app">
<?php $string = 'GBP'; ?>
<!-- Hide this from the front end but bind to Vue somehow -->
<span v-el:currency style="display: none;"><?php echo $string; ?></span>
<p>Payment currency: {{ currency }}</p>
</div>
Of course I could just echo the php variable again, but the main reason I want to bind it to a VueJS element is so I can use the value of this element in my JS to do something like this...
if (this.currency === 'GBP') {
return "Paying in GBP";
} else {
return "Paying in USD";
}
Worth noting that I already have a fair bit of VueJS working within this #app so it's nothing to do with the configuration of Vue being wrong, more a case of just not knowing the correct way to approach the issue.
I would not interleave PHP and javascript inside a component.
Why don't you create a new script at the end with the variables you need?
<!-- bottom of the body -->
<script>var currency = <?php echo $yourVar; ?></script>
And then it will be a global variable and you just take it from there.