Show $params array('{item}' =>…) - php

Need some help. Have this code in PaymentModule.php in Prestashop:
$params = array(
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'{voucher_num}' => $voucher->code,
'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
I use $params['firstname'] for showing customer firstname and get nothing. I insert $params['firstname'] in /modules/bankwire/bankwire.php
Please tell me where I make a mistake?
Thanks

In your array you have a {firstname} key, but no firstname key.
If you want to get value, you should use: $params['{firstname}']

Try
$params = array(
'voucher_amount' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'voucher_num' => $voucher->code,
'firstname' => $this->context->customer->firstname,
'lastname' => $this->context->customer->lastname,
'id_order' => $order->reference,
'order_name' => $order->getUniqReference()
);
or in the case that volkerk is right, try
$params['{firstname}']

there is variables for email template, it's just assoc array, for access use
$params['{voucher_amount}']

Related

How to update data in laravel - there is array value in data

There is field affiliated_facility which is in array and i am trying to update my values:
My controller code:
<?php
$affiliated_facility = implode(",", $userProfile['affiliated_facility']);
$userBasicInfoId = UserBasicInfo::where('user_id', $userProfile['id'])->value('id')->update([
'work_phone' => $userProfile['work_phone'],
'fax' => $userProfile['fax'],
'extension' => $userProfile['extension'],
'primary_facility' => $userProfile['primary_facility'],
'employed_by' => $userProfile['employed_by'],
'emergency_phone' => $userProfile['emergency_phone'],
'designation' => $userProfile['designation'],
'department' => $userProfile['department'],
'employment_type' => $userProfile['employment_type'],
'biography' => $userProfile['biography'],
'hiring_date' => $userProfile['hiring_date'],
'from' => $userProfile['from'],
'to' => $userProfile['to'],
'affiliated_facility' => $affiliated_facility]); // this is in array so i used implode in top of this code
if ($userBasicInfoId) {
$userBasicInfo = $this->userBasicInfo->find($userBasicInfoId);
$userBasicInfo->fill($userProfile)->save();
} else {
$userBasicInfo = $this->userBasicInfo->create($request->only($this->userBasicInfo->getModel()->fillable));
}
?>
But when I hit my request it says
Call to a member function update() on integer
There is some mistakes in my code i want to update my record and there is one field coming which is in array
"affiliated_facility": [1,2]
can someone please help me to modify this code i am stuck on this your help will be highly appreciated!
Thankyou in advance
UserBasicInfo::where('user_id', $userProfile['id']) is a Builder instance. you should get Model instance to update it. So, try:
UserBasicInfo::where('user_id', $userProfile['id'])->first()->update([...]);

How do I loop through an object and display its data within an associative array

First of all this is my code:
Log::create([
'action' => $event->changes[0], //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);
$event->changes is an array which contains many items but i only know how to get 1 specific item at a time using the index [0] or [1] etc.
How do I get all the values to display instead of 1 at a time? Obviously I don't want to create a new log for each single action but I cant figure out how to do this.
As always any help is appreciated thank you.
You need to serialize the $event->changes if you want it within one log entry.
It actually depends on the structure of changes array, but it seems to be an array of strings, so you may for example use the implode(', ', $changes), so the snippet would look the following:
Log::create([
'action' => implode(', ', $event->changes), //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);

php fedex set signature Label ADULT

I am working on wordpress site and using woocommerce extension http://www.woothemes.com/products/fedex-shipping-module/
I am Passing the values Signature value to adults. But it is not working
Please correct me where i am wrong
$request['RequestedShipment']['RateRequestTypes'] = $this->request_type;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
$request['RequestedShipment']['SpecialServicesRequested'][] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
`
Do i need to change something from the from the RateService_v13.wsdl file
Please suggest
Thanks
I resolved this issue
For further user having the same issue can resolve this by below code
$item['SpecialServicesRequested'] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
$request['RequestedShipment']['RequestedPackageLineItems'][] = $item;
If Suppose anyone is using Fedex Integration with Laravel you may use below code.
In place of _DIRECT you may use _ADULT or any other option.
$packageLineItem1 = new FedexShipServiceCT\RequestedPackageLineItem();
$packageLineItem1
->setSequenceNumber(1)
->setItemDescription('Product')
->setSpecialServicesRequested(new FedexShipServiceCT\PackageSpecialServicesRequested(array(
'SignatureOptionDetail' => new FedexShipServiceCT\SignatureOptionDetail(array(
'OptionType' => FedexShipServiceST\SignatureOptionType::_DIRECT
))
)))
->setDimensions(new FedexShipServiceCT\Dimensions(array(
'Width' => 1,
'Height' => 1,
'Length' => 1,
'Units' => FedexShipServiceST\LinearUnits::_IN
)))
->setWeight(new FedexShipServiceCT\Weight(array(
'Value' => 1,
'Units' => FedexShipServiceST\WeightUnits::_LB
)));
Thanks

Converting undefined indexes to null in PHP

I'm not sure if the title of this question is necessarily the accurate description of what I need to do, but I'll go ahead and ask my question and see what everyone thinks...
Basically, I am receiving data from a source that I have no control over, and I need to transpose it into a suitable format for inserting into my database using CakePHP. So, here's how I'm doing it:
public function submitApp($data) {
$array = array(
'Student' => array(
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'address' => $data['address'],
'dob' => $data['dob'],
'gender' => $data['gender']
),
'Application' => array(
'course_id' => $data['course_id'],
'question1' => $data['question1'],
'question2' => $data['question2'],
'question3' => $data['question3'],
'question4' => $data['question4'],
),
'ApplicationQualification' => $data['Qualifications']
);
// Logic to save $array goes here
}
The problem is that sometimes not all of the keys in $data will be submitted to my app but I still want my app to work with what it gets.
I know that I can wrap each key in a conditional like this:
if (!isset($data['name'])) { $data['name'] = null; }
...and then building the array, but this seems like a pretty clumsy way of doing it. Is there a more efficient way to do this?
You could use a simple ternary statement
'name' => array_key_exists('name', $data) ? $data['name'] : null
Alternatively, you can set up a default array and then merge the given values in
$defaults = [
'name' => null,
'email' => null,
// etc
];
$data = array_merge($defaults, $data);

Exploding array for url

I'm developing a site for analyzing a store's data.
I need the url part of my array to look like this:
array(
'url' => 'http://some.website.com:8080/SASStoredProcess/do?_username=user-123',
'_password' => 'passwd',
'_program' => '/Utilisateurs/DARTIES3-2012/Mon dossier/analyse_dc',
'annee' => '2012',
'ind' => 'V',
'_action' => 'execute'
);
I currently have this and am struggling to convert it to the desired format:
array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
Please can somebody help me to convert the URL in the second code block to look like the first code block? Thanks in advance.
So this will extract the url in the form you want, as $url:
$myArray = array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
parse_str($myArray['url']);
echo $url;
You will need to decide where it needs to go next and how you get it there.
You might want to use: parse_url() and parse_str() over your $array['url']

Categories