I am using magento 2.4.4. I am getting wrong "purchase date in CSV".
Purchase date on order - Aug 31, 2021 9:19:46 PM. On csv - 2021-09-01 01:19:46.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI have fixed using this, try.
File name :Magento\Ui\Model\Export\MetadataProvider
public function getRowData(DocumentInterface $document, $fields, $options): array
{
$row = [];
foreach ($fields as $column) {
if (isset($options[$column])) {
$key = $document->getCustomAttribute($column)->getValue();
if (isset($options[$column][$key])) {
$row[] = $options[$column][$key];
} else {
$row[] = $key;
}
} else {
if($column == "created_at"){
$convertedDate = $this->localeDate->date(
new DateTime($document->getCustomAttribute($column)->getValue(), new DateTimeZone('GMT')),
$this->locale,
true
);
$created_at = new DateTime($convertedDate->format($this->dateFormat));
$row[] = $created_at->format('Y-m-d H:i:s');
}else{
$row[] = $document->getCustomAttribute($column)->getValue();
}
}
}
return $row;
}
Just checked in version 2.4.3 and 2.4.4 and both versions works correct for Order and export into CSV
First: check your locale in configuration
Second: check the date in database (sales_order
)
How and why it should work:
See vendor/magento/module-sales/etc/adminhtml/di.xml
<?xml version="1.0"?>
<!-- ... -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- ... -->
<type name="Magento\Ui\Model\Export\MetadataProvider">
<arguments>
<argument name="data" xsi:type="array">
<item name="sales_order_grid" xsi:type="array">
<item name="created_at" xsi:type="string">created_at</item>
</item>
<!-- ... -->
</argument>
</arguments>
</type>
</config>
Please check if you didn't overwrite this in di or has incorrect plugin for
See implementation in \Magento\Ui\Model\Export\MetadataProvider
namespace Magento\Ui\Model\Export;
// ...
class MetadataProvider
{
// ...
public function convertDate($document, $componentName): void
{
if (!isset($this->data[$componentName])) {
return;
}
foreach ($this->data[$componentName] as $field) {
$fieldValue = $document->getData($field);
if (!$fieldValue) {
continue;
}
$convertedDate = $this->localeDate->date(
new DateTime($fieldValue, new DateTimeZone('UTC')),
$this->locale,
true
);
$document->setData($field, $convertedDate->format($this->dateFormat));
}
}
}
The method calls in \Magento\Ui\Model\Export\ConvertToCsv::getCsvFile
cataloginventory_stock
might be an old table, it shouldn't have more than one record or so I'd imagine. Be aware that custom extensions can also cause tons of issues with inventory stock. Since I think we'd need more information on your database and what data/tables are most likely missing, try this article: stackoverflow.com/questions/57213282/… and this one: magecomp.com/blog/…