Prestashop 1.6每个时间段的订单号序列重置

Prestashop 1.6每个时间段的订单号序列重置

问题描述:

SYNOPSIS

I am running my eCommerce shop using Prestashop 1.6. I have already reconfigured my Order Numbers to the format SO/2018/000001 based on ps_orders.ps_id_order using this answer as a guide. Updating override/classes/PaymentModule.php with this block:

$oNum = str_pad($order->id, 6, '0', STR_PAD_LEFT);
$oYear = substr(date(Y),0,4);
$order->reference = "SO/$oYear/$oNum";
$order->update();

I then used the following query to update set determine the next id_order:

ALTER TABLE ps_orders AUTO_INCREMENT = 10

This made my reference longer than the defined field, so I also had to adjust the definition in /override/class/Order.php:

'reference' => array('type' => self::TYPE_STRING, 'size' => 14),

And in /override/class/OrderPayment.php:

'order_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'size' => 14),

With all that done, my order numbers were formatted the way I wanted, but are not exactly as desired.

DESIRED RESULT

Rather than using the ps_orders table's key index field as the basis of my order numbers, I would like to use a separate sequence which resets each year. Similar to how the OrderInvoiceCore class uses the number field to generate the actual invoice number based on the Invoice Options set in the back office.

PLEASE ADVISE

What is the best way to go about achieving this desired result? I am thinking that adding a sequence to the OrderCore class, and using that to generate my order reference numbers in place of ps_orders.id_order would do the trick. If that is the best solution in my case, how do I go about implementing such?

大纲 h2>

我正在使用Prestashop 1.6运行我的电子商务商店。 我已经使用 ps_orders.ps_id_order code>的 SO / 2018/000001 code>格式 30053257/2464491“>此答案作为指南。 使用此块更新 override / classes / PaymentModule.php code>: p>

  $ oNum = str_pad($ order-> id,6,'0'  ,STR_PAD_LEFT); 
 $ oYear = substr(date(Y),0,4); 
 $ order-> reference =“SO / $ oYear / $ oNum”; 
 $ order-> update()  ; 
  code>  pre> 
 
 

然后我使用以下查询更新集确定下一个 id_order code>: p>

   ALTER TABLE ps_orders AUTO_INCREMENT = 10 
  code>  pre> 
 
 

这使我的 reference code>比定义的字段长,所以我还必须调整 /override/class/Order.php code>中的定义: p>

 'reference'=> 数组('type'=> self :: TYPE_STRING,'size'=> 14),
  code>  pre> 
 
 

并在 / override / class / OrderPayment .php code>: p>

 'order_reference'=>  array('type'=> self :: TYPE_STRING,'validate'=>'isAnything','size'=> 14),
  code>  pre> 
 
 

With 完成所有操作后,我的订单编号按照我想要的方式进行了格式化,但并不完全符合要求。 p>

期望的结果 h2>

而不是使用 ps_orders code>表的键索引字段作为我的订单号的基础,我想使用一个单独的序列,每年重置一次。 类似于 OrderInvoiceCore code>类如何使用 number code>字段根据后台设置的 Invoice Options code>生成实际发票编号。 p>

请提出建议 h2>

实现这一理想结果的最佳方法是什么? 我想在 OrderCore code>类中添加一个序列,并使用它来生成我的订单参考号代替 ps_orders.id_order code>就可以了。 如果这是我的最佳解决方案,我该如何实现这样的? p> div>

You can get the number of orders in current year and add one to it, when generating the reference.

$nextid = (int)Db::getInstance()->ExecuteS("SELECT count(`id_order`) FROM `"._DB_PREFIX_."orders` WHERE `date_add` > '".date('Y')."-01-01'") + 1;

I would do it by overriding the add function in Order class to something like:

public function add($autodate = true, $null_values = true)
{
    $nextid = Db::getInstance()->ExecuteS("SELECT count(`id_order`) FROM `__DB_PREFIX__orders` WHERE `date_add` > '".date('Y')."-01-01'") + 1;
    $this->reference = "SO/".date('Y')."/".str_pad($nextid, 6, '0', STR_PAD_LEFT);

    parent::add($autodate, $null_values);
}