Documentation

Cash registers and receipts

Event Description Available from version
OnSaleCheckPrepareData Allows modify specific data in a receipt: update product name, remove products with 0 cost and etc. Two parameters are passed on input:
  • arra with receipt data;

    Click on [+], to show detailed description for array

  • тип чека (например, credit, advancepayment and etc.).
// delete delivery with 0 price
AddEventHandler("sale", "OnSaleCheckPrepareData", "CheckProductPrint");
function CheckProductPrint($a, $type)
{
	if ($a['DELIVERY']['SUM'] == 0)
		unset($a['DELIVERY']);

	return $a;
}
OnGetCustomCashboxHandlers Event is triggered when building list of cash register handlers. Allows adding your own cash register handler.
// adding your own cash register
AddEventHandler("sale", "OnGetCustomCashboxHandlers", "GetCustomCashboxHandlers");
function GetCustomCashboxHandlers()
{
	$data = array('\Bitrix\Sale\Cashbox\cashboxnew' => '/bitrix/php_interface/include/cashboxnew.php');
	$event = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::SUCCESS, $data);
	
	return $event;
}
OnGetCustomCheckList Event is triggered when building list of supported receipts. Allows adding your own receipt.
// adding your own receipt type
AddEventHandler("sale", "OnGetCustomCheckList", "GetCustomCheckList");
function GetCustomCheckList()
{
	$data = array('\Bitrix\Sale\Cashbox\SellExCheck' => '/bitrix/php_interface/include/sellexcheck.php');
	$event = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::SUCCESS, $data);
	
	return $event;
}
OnPrintableCheckSend Event allows redefining standard notification mechanism for sending receipt print. Passes 2 parameters on input: payment object used to print the receipt and receipt object to be printed.
// re-defining standard receipt printing mechanism
AddEventHandler("sale", "OnPrintableCheckSend", "PrintableCheckSend");
function PrintableCheckSend()
{
	/*
		Send receipt via SMS
	*/
	
	$event = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::SUCCESS);
	
	return $event;
}
onSaleCashboxRestrictionsClassNamesBuildList Event allows adding your own restrictions on cash registers.
onSaleCashboxRestrictionsClassNamesBuildList

// adding your own receipt type
AddEventHandler("sale", "onSaleCashboxRestrictionsClassNamesBuildList", 
"GetSaleCashboxRestrictionsClassNamesBuildList");
function GetSaleCashboxRestrictionsClassNamesBuildList()
{
	$data = array(
	        '\Bitrix\Sale\Cashbox\Restrictions\Site' => '/bitrix/php_interface/include/site.php'
	);
	$event = new Bitrix\Main\EventResult(Bitrix\Main\EventResult::SUCCESS, $data);
	
	return $event;
}
OnCheckCollateDocuments Event is designed to implement custom logic for generating receipts in automatic mode.

Let's review an example: with order total more than 10000, a prepayment is charged. The remaining amount is charged after the order is checked by a manager. This process will have several payments. For the first payment, print an advance payment receipt, for the second payment - full payment with an advance. This example will look as follows:
AddEventHandler("sale", "OnCheckCollateDocuments", "OnCheckCollateDocuments");

function OnCheckCollateDocuments($entities)
{
	foreach ($entities as $entity)
	{
		if ($entity instanceof \Bitrix\Sale\Payment)
		{
			$order = $entity->getCollection()->getOrder();
			if ($order->isPaid())
			{
				$related = [];

				foreach ($entity->getCollection() as $payment)
				{
					if ($payment->getId() != $entity->getId())
					{
						$related[\Bitrix\Sale\Cashbox\Check::PAYMENT_TYPE_ADVANCE][] = $payment;
					}
				}
			
				foreach ($order->getShipmentCollection() as $shipment)
				{
					if (!$shipment->isSystem())
					{
						$related[\Bitrix\Sale\Cashbox\Check::SHIPMENT_TYPE_NONE][] = $shipment;
					}
				}

				return new \Bitrix\Main\EventResult(
					\Bitrix\Main\EventResult::SUCCESS, 
					    [['TYPE' => 'sell', 'ENTITIES' => [$entity], 'RELATED_ENTITIES' => $related]]
				);
			}
			else
			{
				if ($entity->isPaid() && !$order->isPaid())
				{
					return new \Bitrix\Main\EventResult(
						\Bitrix\Main\EventResult::SUCCESS, 
							[['TYPE' => 'advancepayment', 'ENTITIES' => [$entity], 'RELATED_ENTITIES' => []]]
					);
				}
			}
		}
	}
}
© «Bitrix24», 2001-2024
Up