Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // A copier dans /modules/orderfix/orderfix.php
- class OrderFix extends Module
- {
- function __construct() {
- $this->name = 'orderfix';
- $this->tab = 'administration';
- $this->version = '0.1';
- $this->author = 'Lenacus';
- parent::__construct();
- $this->page = basename(__FILE__, '.php');
- $this->displayName = 'Correcteur de commande';
- $this->description = 'Corrige automatiquement les pertes d\'articles en regénérant la commande depuis le panier';
- }
- function install() {
- return (!parent::install() OR !$this->registerHook('DisplayInvoice')) ? false : true;
- }
- public function uninstall() {
- return (!parent::uninstall()) ? false : true;
- }
- public function hookDisplayInvoice($params) {
- $order = new Order($params['id_order']);
- $cart = new Cart($order->id_cart);
- if (count($order->getProducts()) < count($cart->getProducts()))
- $this->fixIt($order, $cart);
- return true;
- }
- private function fixIt($order, $cart) {
- $A_order = array();
- $sql = 'SELECT `id_order_invoice` FROM `'._DB_PREFIX_.'order_invoice` WHERE `id_order`='.$order->id;
- $id_order_invoice = Db::getInstance()->getValue($sql);
- if (!$id_order_invoice) $id_order_invoice = 0;
- foreach($order->getProducts() as $product)
- $A_order[$product['id_product']] = true;
- foreach($cart->getProducts() as $product) {
- if (!isset($A_order[$product['id_product']])) {
- $sql = '
- INSERT INTO `'._DB_PREFIX_.'order_detail`
- (
- `id_order`,
- `id_order_invoice`,
- `id_shop`,
- `product_id`,
- `product_attribute_id`,
- `product_name`,
- `product_quantity`,
- `product_quantity_in_stock`,
- `product_price`,
- `product_reference`,
- `total_price_tax_incl`,
- `total_price_tax_excl`,
- `unit_price_tax_incl`,
- `unit_price_tax_excl`,
- `original_product_price`
- )
- VALUES
- (
- '.$order->id.',
- '.$id_order_invoice.',
- '.$cart->id_shop.',
- '.$product['id_product'].',
- '.$product['id_product_attribute'].',
- \''.pSQL($product['name']).'\',
- '.$product['cart_quantity'].',
- '.$product['cart_quantity'].',
- '.$product['price'].',
- \''.pSQL($product['reference']).'\',
- '.$product['total_wt'].',
- '.$product['total'].',
- '.$product['price_wt'].',
- '.$product['price'].',
- '.$product['price'].'
- )';
- Db::getInstance()->Execute($sql);
- $id_order_detail = Db::getInstance()->Insert_ID();
- Db::getInstance()->Execute('
- INSERT INTO `'._DB_PREFIX_.'order_detail_tax`
- (
- `id_order_detail`,
- `id_tax`,
- `unit_amount`,
- `total_amount`
- )
- VALUES
- (
- '.$id_order_detail.',
- '.$cart->id_shop.',
- '.($product['price_wt'] - $product['price']).',
- '.($product['total_wt'] - $product['total']).'
- )'
- );
- }
- }
- header('Location: '.$_SERVER['REQUEST_URI']);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement