| Server IP : 74.208.250.37 / Your IP : 216.73.216.114 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : miferval ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/brainwavemx/app/Model/ |
Upload File : |
<?php
declare(strict_types=1);
namespace App\Model;
use Mosaico\Model\BaseModel;
class OrderModel extends BaseModel
{
public function getLastId(): int
{
$query = $this->connect()->query("
SELECT max(id_order) as id FROM
bigcommerce_orders
");
is_bool($query) ?
$response = 0 :
$response = $query->row['id'];
return (int) $response;
}
public function addBigcommerceOrder(array $value): void
{
$query = $this->connect()->query("
INSERT IGNORE INTO bigcommerce_orders SET
id_order = " . $value['id_order'] . ",
id_customer = " . $value['id_customer'] . ",
date_created = '" . $value['date_created'] . "',
subtotal_ex_tax = " . $value['subtotal_ex_tax'] . ",
subtotal_tax = " . $value['subtotal_tax'] . ",
subtotal_inc_tax = " . $value['subtotal_inc_tax'] . ",
base_shipping_cost = " . $value['base_shipping_cost'] . ",
shipping_cost_ex_tax = " . $value['shipping_cost_ex_tax'] . ",
shipping_cost_inc_tax = " . $value['shipping_cost_inc_tax'] . ",
shipping_cost_tax = " . $value['shipping_cost_tax'] . ",
base_handling_cost = " . $value['base_handling_cost'] . ",
handling_cost_ex_tax = " . $value['handling_cost_ex_tax'] . ",
handling_cost_inc_tax = " . $value['handling_cost_inc_tax'] . ",
handling_cost_tax = " . $value['handling_cost_tax'] . ",
base_wrapping_cost = " . $value['base_wrapping_cost'] . ",
wrapping_cost_ex_tax = " . $value['wrapping_cost_ex_tax'] . ",
wrapping_cost_inc_tax = " . $value['wrapping_cost_inc_tax'] . ",
wrapping_cost_tax = " . $value['wrapping_cost_tax'] . ",
total_ex_tax = " . $value['total_ex_tax'] . ",
total_inc_tax = " . $value['total_inc_tax'] . ",
total_tax = " . $value['total_tax'] . ",
items_total = " . $value['items_total'] . ",
currency_code = '" . $value['currency_code'] . "',
currency_exchange_rate = " . $value['currency_exchange_rate'] . "
");
}
public function addOrderProducts(array $value): void
{
$query = $this->connect()->query("
INSERT INTO bigcommerce_order_products SET
id_order = " . $value['id_order'] . ",
id_product = " . $value['id_product'] . ",
name = '" . $value['name'] . "',
sku = '" . $value['sku'] . "',
base_price = " . $value['base_price'] . ",
price_ex_tax = " . $value['price_ex_tax'] . ",
price_inc_tax = " . $value['price_inc_tax'] . ",
price_tax = " . $value['price_tax'] . ",
base_total = " . $value['base_total'] . ",
total_ex_tax = " . $value['total_ex_tax'] . ",
total_inc_tax = " . $value['total_inc_tax'] . ",
total_tax = " . $value['total_tax'] . ",
quantity = " . $value['quantity'] . "
");
}
public function getOrders(int $id_order = 0): bool|object
{
$id_order == 0 ? $query_string = '' : $query_string = 'WHERE id_order >=' . $id_order;
$query = $this->connect()->query("
SELECT
id_order,
id_customer,
date_created,
subtotal_ex_tax,
subtotal_tax,
subtotal_inc_tax,
base_shipping_cost,
shipping_cost_ex_tax,
shipping_cost_inc_tax,
shipping_cost_tax,
base_handling_cost,
handling_cost_ex_tax,
handling_cost_inc_tax,
handling_cost_tax,
base_wrapping_cost,
wrapping_cost_ex_tax,
wrapping_cost_inc_tax,
wrapping_cost_tax,
total_ex_tax,
total_inc_tax,
total_tax,
items_total,
currency_code,
currency_exchange_rate
FROM bigcommerce_orders
" . $query_string . "
");
return $query;
}
public function getOrderProducts(int $id_order = 0): bool|object
{
$query = $this->connect()->query("
SELECT
id_order,
id_product,
name,
sku,
base_price,
price_ex_tax,
price_inc_tax,
price_tax,
base_total,
total_ex_tax,
total_inc_tax,
total_tax,
quantity
FROM bigcommerce_order_products
WHERE id_order = " . $id_order . "
");
return $query;
}
public function updateOrderErpStatus(int $order_id, int $status, string $message): void
{
$query = $this->connect()->query("
UPDATE bigcommerce_orders SET
erp_status = " . $status . ",
error = '" . $message . "'
WHERE id_order = " . $order_id . "
");
}
public function getExchangeRate(): bool|object
{
$query = $this->connect()->query("
SELECT currency_code, currency_exchange_rate
FROM moneda
WHERE currency_code = 'MXP'
");
return $query;
}
public function addBigcommerceCustomer(array $value): void
{
$query = $this->connect()->query("
INSERT IGNORE INTO bigcommerce_customers SET
id_bigcommerce = " . $value['id_bigcommerce'] . ",
first_name = '" . $value['first_name'] . "',
last_name = '" . $value['last_name'] . "',
email = '" . $value['email'] . "',
phone = '" . $value['phone'] . "'
");
}
public function addBigcommerceCustomerAddress(array $value): void
{
$query = $this->connect()->query("
INSERT IGNORE INTO bigcommerce_customer_billing_address SET
id_bigcommerce = " . $value['id_bigcommerce'] . ",
first_name = '" . $value['first_name'] . "',
last_name = '" . $value['last_name'] . "',
email = '" . $value['email'] . "',
phone = '" . $value['phone'] . "',
street_1 = '" . $value['street_1'] . "',
street_2 = '" . $value['street_2'] . "',
city = '" . $value['city'] . "',
state = '" . $value['state'] . "',
zip = '" . $value['zip'] . "',
country = '" . $value['country'] . "',
rfc = '" . $value['rfc'] . "',
tipo_persona = '" . $value['tipo_persona'] . "',
regimen_fiscal = '" . $value['regimen_fiscal'] . "',
uso_cfdi = '" . $value['uso_cfdi'] . "'
");
}
}