VirtueMart 4 для Joomla 3
A free solution for e-commerce with open-source code, VirtueMart can't be used separately because it is a plugin for Joomla CMS. A small team of developers, only five people, work on VirtueMart, and there is a small community that takes part in the project in various ways.
In VirtueMart, there is no such freedom for declaring payment module methods as in OpenCart. The class of the payment module is inherited from the abstract class vmPSPlugin
, which in turn is inherited from another abstract class. Thus, there is a method plgVmOnShowOrderBEPayment
for displaying order information on the backend side. It is this very method that we are going to override in the payment module to expand the displayed order information, for instance, to include payment information.
A table of payment information in VirtueMart is created in a certain way. In the builder, it is indicated:
$this->tableFields = array_keys($this->getTableSQLFields());
Then, the getTableSQLFields
method is defined, which contains the payment and order fields and, in our case, looks the following way.
function getTableSQLFields()
{
$SQLfields = array(
"id" => "int(11) unsigned NOT NULL AUTO_INCREMENT",
"virtuemart_order_id" => "int(11) UNSIGNED DEFAULT NULL",
"cdekpay_order_id" => "int(11) UNSIGNED DEFAULT NULL",
"order_number" => "char(64)", // VirtueMart string order number
"virtuemart_paymentmethod_id" => "mediumint(1) UNSIGNED DEFAULT NULL",
"paylink" => "char(255) DEFAULT NULL",
"status" => "char(255) DEFAULT NULL",
"currency_code" => "char(3) NOT NULL DEFAULT 'TST' ",
"total" => "bigint UNSIGNED DEFAULT NULL",
"success_notified" => "boolean DEFAULT false",
"cancellation_requested_notified" => "boolean DEFAULT false",
"success_cancellation_notified" => "boolean DEFAULT false",
"cancelled_notified" => "boolean DEFAULT false",
"voided_notified" => "boolean DEFAULT false",
"refund_total" => "bigint UNSIGNED DEFAULT NULL",
);
return $SQLfields;
}
The function updateStatusForOneOrder
is used to update the order status.
$orderModel = new VirtueMartModelOrders();
// получаем заказ по номеру заказа VirtueMart
$vmOrder = $orderModel->getOrder($oldOrder["virtuemart_order_id"]);
// берем статус «Оплачен» из настроек модуля
$vmOrder["order_status"] = $this->cdekpaySDK->getStatuses()->paid;
// обновляем статус заказа
$orderModel->updateStatusForOneOrder($oldOrder["virtuemart_order_id"], $vmOrder);
HikaShop для Joomla 3
HikaShop is a Joomla-based e-commerce solution with a free basic version and two paid versions with enhanced functionality. Developing payments for HikaShop is similar to developing a module for VirtueMart. Just like in VirtueMart, there is a basic class for the payment module, hikashopPaymentPlugin
, in HikaShop whose methods must be implemented.
To prevent DDoS attacks, the project lead developer introduced limits on the parallel running of cron jobs in the payment module. The cron jobs themselves regularly query CDEK Pay to check payment statuses in case a reply on successful payment or order cancellation wasn't received through the webhook. Later, it is planned to include this functionality in other payment modules.
First of all, we need a table to store the statuses of cron jobs. For this purpose, we define a table in the cdekpay.install.sql
file in the following way:
CREATE TABLE IF NOT EXISTS `#__hikashop_cdekpay_cron_jobs` (
`job_name` varchar (256) NOT NULL,
`job_process_id` int(10) unsigned NOT NULL,
`job_started_at` datetime NOT NULL DEFAULT current_timestamp(),
`job_completed_at` datetime NULL,
`job_error` text NULL,
PRIMARY KEY (`job_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
To create a table during module installation, we need to add the following code in the configuration file cdekpay.xml
.
<install>
<sql>
<file driver="mysql" charset="utf8">cdekpay.install.sql</file>
</sql>
</install>
When a cron job starts or receives an external request to start, we need to calculate how much time has passed since the previous start. To protect against attacks, the frequency of starts is limited so that the delay amounts to a minimum of 60 minutes.
InSales
There is no need to install InSales anywhere, since it is a SaaS which has: