Views: 2660
Last Modified: 27.02.2023
Standard cash register handler is not suitable for you? Use the product API and write your own handler. To do this, you need the following:
- Inherit the class \Bitrix\Sale\Cashbox\Cashbox and implement the required methods:
Note: additionally you can use the following interfaces:
- \Bitrix\Sale\Cashbox\IPrintImmediately - required for sending a receipt to be printed immediately after it's created;
- \Bitrix\Sale\Cashbox\ICheckable - required, when you need to request information about the receipt printing results.
use \Bitrix\Sale\Cashbox\Cashbox,
\Bitrix\Sale\Cashbox\Check,
\Bitrix\Sale\Cashbox\IPrintImmediately,
\Bitrix\Sale\Cashbox\ICheckable;
class CashboxCustom extends Cashbox implements IPrintImmediately, ICheckable
{
/**
* @param Check $check
* @return array
*/
public function buildCheckQuery(Check $check)
{
// building a query with information about the cash register receipt
}
/**
* @param $id
* @return array
*/
public function buildZReportQuery($id)
{
// building query to print z-report
// when z-print is not required, returns an empty array
}
public function printImmediately(Check $check)
{
// algorithm for sending receipt for printing
}
public function check(Check $check)
{
// algorithm for requesting receipt status
}
/**
* @return string
*/
public static function getName()
{
// handler name
return Localization\Loc::getMessage('SALE_CASHBOX_CUSTOM_TITLE');
}
/**
* @param array $data
* @throws Main\NotImplementedException
* @return array
*/
protected static function extractCheckData(array $data)
{
// retrieving receipt data to be saved
}
public static function getVersion() ?: float
{
// version, operated by handler
return null;
}
}
- Connect cash register handler to the system using the event OnGetCustomCashboxHandlers. Event handler must return an array type: array(full_class_name => file_path):
AddEventHandler("sale", "OnGetCustomCashboxHandlers", 'myCashboxFunction');
function myCashboxFunction()
{
return new \Bitrix\Main\EventResult(
\Bitrix\Main\EventResult::SUCCESS,
array(
'\CashboxCustom' => '/bitrix/php_interface/include/cashboxcustom.php',
)
);
}
Resulting admin site section shows your handler in the cash register settings.
Related links: