Magento - how to hide the time in the transctional Emails - magento

I'm searching how to hide the time and show only the date in the "new order" email:
I have seen that it's generated with this code :
({{var order.getCreatedAtFormated(''long'')}})
but I don't find a solution how to show only the date.
Thanks for help.

Supported formatting types are: long, medium , full, short
thanks for the comment:
HOW SHOULD I HELP MYSELF FINDING THIS OUT
first thing if you don't know how to interact wit method search for it in codebase as this reveals in what file the method is defined and you can see what parameters it takes in and how it processes the parameters
grep ' getCreatedAtFormated' app/code/ -rsn
app/code/core/Mage/Sales/Model/Order.php:1988: public function getCreatedAtFormated($format)
ok, now we found that file , open up and see the line 1988 has the method
/**
* Get formated order created date in store timezone
*
* #param string $format date format type (short|medium|long|full)
* #return string
*/
public function getCreatedAtFormated($format)
{
return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
}
cool now you see it is actually using core helper's formatDate method. Go ahead open up that file
app/code/core/Mage/Core/Helper/Data.php:135: public function formatDate($date=null, $format='short', $showTime=false)
you can see from grep that it takes in third parameter that you can't pass to that method as it wraps this with forced in value.
So your solution is to use the helper and get the variable order.getCreatedAtStoreDate() and pass it to helpers formatting method

Related

Codeigniter 4 - how to get the first row and the last row of a result

I am trying to get the first row and the last row of a query result. I see from Ci4's docs, there are two methods to help, namley, getFirstRow([$type = 'object']) and getLastRow([$type = 'object']) but I am having difficulty using them. Here is my method so far:
function getLoginFailCount($login_fail_ip, $max_login_attempts = 3, $within_seconds = 320){
$builder = $this->builder('login_fail');
$builder->where('login_fail_ip', $login_fail_ip);
$builder->orderBy('login_fail_created_at','DESC');
$query = $builder->get(3);
print_r($query->getFirstRow($query));
}
I get an error at getFirstRow as follows;
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow() must be
of the type string, object given
How can I get getFirstRow() to work? Doesn't this doc definition say I need to pass it an object? Why does the error say it my be of type string
Well in the documentation for getFirstRow() it states that you can use
$row = $query->getFirstRow() // which will give you an object
OR
$row = $query->getFirstRow(‘array’) // which will give you an Array
So your error message, which states...
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow()
must be of the type string, object given
Would make you look and say to yourself, I had better go and read the documentation. So you can either pass in nothing, or a String 'array'.
So now can you see why
$query->getFirstRow($query))
does not make any sense! Why would you pass in the $query object as parameter.
You may have misread the documentation. I see you stated getFirstRow([$type = 'object'])
You might have got a little confused by that...
[$type = 'object'] means that the $type is defaulted to be the string 'object' so the returned type is an object by default with No Parameter being passed in.
If you want it to return an array, then you would specify the string 'array'. So then the $type parameter would be set to the string 'array' and return an array instead of an object.
Does that help!

How to get file as a resource with Storage?

I am trying to lock a file with the flock function but I am not able to do it. I work with Laravel 8 and Storage Class.
The code is as follows:
$disk = Storage::disk('communication');
$file_name = 'received.json';
$file_exists = $disk->exists($file_name);
if($file_exists){
flock($disk->get($file_name), LOCK_EX);
...
}
The problem I'm having is that when I invoke the get() function on the file path, it returns the contents of the file (a string), which causes the following error:
flock() expects parameter 1 to be resource, string given
I need to know how to get file as a resource and not the content of the file.
Could someone help me and tell me how to do it?
Thank you very much in advance.
You can use Storage::readStream() method
if($file_exists){
$stream=Storage::disk('communication')->readStream($file_name);
flock($stream, LOCK_EX);
}
As per php doc
flock(resource $stream, int $operation, int &$would_block = null): bool
First param needed stream.flock() allows you to perform a simple
reader/writer model which can be used on virtually every platform
(including most Unix derivatives and even Windows).
Ref:https://www.php.net/manual/en/function.flock.php

Why doesn't asterisk work in Xcode Quick Help markup?

As Markup Formatting Reference states, you can use *,+ or - characters as prefixes for markup keywords. For example, take a look at Parameter:
Now, when I try to use *, markup doesn't work:
/**
* Parameter piece: A piece to validate.
* Parameter matchBlock: Called only if necessary.
*/
init(piece: MSPiece?, matchBlock: MatchBlock) { ... }
The above code results in:
But if we put + or - instead of *,
/**
+ Parameter piece: A piece to validate.
- Parameter matchBlock: Called only if necessary.
*/
init(piece: MSPiece?, matchBlock: MatchBlock) { ... }
The documentation will be correct:
Why doesn't * work? It would be actually cool to use an asterisk because /** */ comment stats and ends with asterisk and it would be really neat.
It was a bug and it's fixed in Xcode 10.0.

Using protected $dateFormat throws trailing error

I am trying to format the date at the model using:
protected $dateFormat = "Y-m-d";
and I am getting this error:
"The separation symbol could not be found Trailing data" on line 582 of C:\wamp64\www\israplanet.com\vendor\nesbot\carbon\src\Carbon\Carbon.php
Using
protected $dateFormat = "Y";
causes this error:
"Trailing data" on line 582 of C:\wamp64\www\israplanet.com\vendor\nesbot\carbon\src\Carbon\Carbon.php
This example is from the October docs.
Whats is wrong here?
I'm not familiar with the example you have given (ie: using protected $dateFormat = "Y-m-d";) but when I do something like this I tend to use an accessor on the model:
public function getFormattedDateAttribute($value)
{
return $this->created_at->format('Y-m-d');
}
Obviously created_at would need to be replaced with the name of the date field. You'd then be able to access it in Twig as {{ array.formatted_date }}.
I cannot name this as good answer, but for now i at least can continue.
I simply changed format of the columns (created_at and updated_at) to date format and it stores the way i wanted it, but i always trying to fix problems (this habbit takes a lot of my time).
another option is to use handlebar helper for this.
But i want to understand the problem in the root.
(btw - thanks for answers)

TYPO3/Extbase - How to trim values before validation/saving objects?

In Extbase usually I handle form validation myself within the controller, especially when I need advanced scenarios, but now I've simple, but large form with many fields, so I decided not to waste time and just use TYPO3's validators. So far so good in general it works, anyway I cannot force Extbase to trim values before validation and in result Extbase saves lot of spaces... so it's invalid, sample:
/**
* #var string
* #validate StringLength(minimum=2, maximum=255)
* #validate NotEmpty
*/
protected $fooName = '';
As I said I've tens of fields and would love to avoid manual validating it... is there any solution?
Note: I tried extbase_filter ext, which would be great solution if it worked (unfortunately doesn't take any effect at TYPO3 ver.: 6.2.6.
Also for obvious reasons using JS for trimming values before form send isn't a solution too.
You can do trim-ing inside your set* methods. Validation in Extabase's MVC process happens after set-ers invoked.
So, your example would be:
/**
* #var string
* #validate StringLength(minimum=2, maximum=255)
* #validate NotEmpty
*/
protected $fooName = '';
public function setFooName($fooName)
{
$this->fooName = trim($fooName);
}

Resources