View Single Post
  #7  
Old 06-05-2020, 12:49 PM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline
 

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

Default Re: Custom Order Numbering

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:
  1. Grab a list of all Order reference numbers;
  2. Place them in an array;
  3. Find the maximum value;
  4. Extract and increment its 4-digit counter portion;
  5. Format the new order reference; and
  6. 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?
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0
Reply With Quote