1

我在模块中使用以下行

    $firstNextMonth = date("Y-m-d H:i:s", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));
    $d = DateTime::createFromFormat('Y-m-d H:i:s', $firstNextMonth);
    $firstNextMonthTs = $d->getTimestamp();

但是当我在登台服务器中运行代码时,我得到了 magento 的错误

"Fatal Error: 'Uncaught Error: Class 'Magenest\\Stripe\\Model\\DateTime' not found in \/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php:480\nStack trace:\n#0 \/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php(829): Magenest\\Stripe\\Model\\StripePaymentMethod->authorize(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), '4.8')\n#1 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment\/Operations\/CaptureOperation.php(82): Magenest\\Stripe\\Model\\StripePaymentMethod->capture(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), '4.8')\n#2 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment\/Processor.php(85): Magento\\Sales\\Model\\Order\\Payment\\Operations\\CaptureOperation->capture(Object(Magento\\Sales\\Model\\Order\\Payment\\Interceptor), Object(Magento\\Sales\\Model\\Order\\Invoice))\n#3 \/var\/www\/html\/magento2-theme-videx\/htdocs\/vendor\/magento\/module-sales\/Model\/Order\/Payment.php(' in '\/var\/www\/html\/magento2-theme-videx\/htdocs\/app\/code\/Magenest\/Stripe\/Model\/StripePaymentMethod.php' on line 480"

看起来像 magento 或 php 它试图找到 DateTime 类而不是运行命令

php 版本为 PHP 7.0.27 (cli) (build: Jan 25 2018 22:40:53) (NTS)

有任何想法吗 ?

4

1 回答 1

2

添加“使用 Magento\Framework\Stdlib\DateTime;” 类声明之前的行而不是使用代码 DateTime 类,如下所示:

$firstNextMonth = date("Y-m-d H:i:s", strtotime(date('m', strtotime('+1 month')).'/01/'.date('Y').' 00:00:00'));
$d = \DateTime::createFromFormat('Y-m-d H:i:s', $firstNextMonth);
$firstNextMonthTs = $d->getTimestamp();
于 2018-09-07T06:54:54.240 回答