I am working on a custom module which adds a column to the
Order model for handling custom order reference numbers. Here is my .\Model\Order.php file:
Code:
<?php
{
/**
*
* @var string
*
* @Column (type="string", length=12)
*/
prodtected $reference = '';
/**
* Get Order reference number
*
* @return string
*/
public function getReference()
{
return $this->reference;
}
/**
* Set Order reference number
*
* @param string $reference
* @return void
*/
public function setReference($reference)
{
$this->reference = $reference;
}
/**
* Set orderNumber
*
* @param string $orderNumber
* @return Order
* /
public function setOrderNumber($OrderNumber)
{
$this->orderNumber = $orderNumber;
// Check if a reference number has already been assigned.
// If not, generate and assign a new one.
if ($this->reference == '') {
$reference = $this->generateReference();
$this->setReference($reference);
}
return $this;
}
/**
* Generates new Order Reference Number in the form SO/2020/0001
*
* @return string
*/
public function generateReference()
{
$dateMin = new DateTime(date("Y")."-01-01");
$dateMax = new DateTime(date("Y")."-12-31");
$result = \XLite\Core\Database::getRepo('\XLite\Model\Order')->createQueryBuilder('o')
->select('o.reference')
->where('o.date BETWEEN :dateMin AND :dateMax')
->setParameter('dateMin', $dateMin->getTimestamp())
->setParameter('dateMax', $dateMax->getTimestamp())
->getResult();
$references = [];
foreach ($result as $order) {
array_push($references, max($order));
}
$reference = "SO/" . date("Y") . "/" . substr(str_repeat(0,4).((int)substr(max($references),-4)+1), -4);
return $reference;
}
}
Here is the workflow logic of the generateReference function:
- Grab a list of all Order reference numbers;
- Place them in an array;
- Find the maximum value;
- Extract and increment its 4-digit counter portion;
- Format the new order reference; and
- Return the newly formatted reference number.
When I log in to place an order as a customer, the checkout process works up until after payment, at which point the site just hangs with the "thinking" cursor.
It does create records in the
Payment\Transaction and
Order models, but
xc_orders.orderNumber is Null and
xc_orders.reference is blank.
Is there a way to properly debug what is causing it to hang?