Advertisement
Guest User

Fix les commandes vides PS 1.5

a guest
Nov 21st, 2013
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.04 KB | None | 0 0
  1. <?php
  2.  
  3. // A copier dans /modules/orderfix/orderfix.php
  4. class OrderFix extends Module
  5. {
  6.     function __construct() {
  7.    
  8.         $this->name = 'orderfix';
  9.         $this->tab = 'administration';
  10.         $this->version = '0.1';
  11.         $this->author = 'Lenacus';
  12.        
  13.         parent::__construct();
  14.         $this->page = basename(__FILE__, '.php');
  15.  
  16.         $this->displayName = 'Correcteur de commande';
  17.         $this->description = 'Corrige automatiquement les pertes d\'articles en regénérant la commande depuis le panier';
  18.     }
  19.    
  20.     function install() {
  21.         return (!parent::install() OR !$this->registerHook('DisplayInvoice')) ? false : true;
  22.     }
  23.    
  24.     public function uninstall() {
  25.         return (!parent::uninstall()) ? false : true;
  26.     }
  27.    
  28.     public function hookDisplayInvoice($params) {
  29.    
  30.         $order  = new Order($params['id_order']);
  31.         $cart   = new Cart($order->id_cart);
  32.  
  33.         if (count($order->getProducts()) < count($cart->getProducts()))
  34.             $this->fixIt($order, $cart);
  35.  
  36.         return true;
  37.            
  38.     }
  39.    
  40.     private function fixIt($order, $cart) {
  41.  
  42.         $A_order    = array();
  43.        
  44.         $sql = 'SELECT `id_order_invoice` FROM `'._DB_PREFIX_.'order_invoice` WHERE `id_order`='.$order->id;
  45.         $id_order_invoice = Db::getInstance()->getValue($sql);
  46.         if (!$id_order_invoice) $id_order_invoice = 0;
  47.    
  48.         foreach($order->getProducts() as $product)
  49.             $A_order[$product['id_product']] = true;
  50.            
  51.         foreach($cart->getProducts() as $product) {
  52.             if (!isset($A_order[$product['id_product']])) {
  53.                 $sql = '
  54.                     INSERT INTO `'._DB_PREFIX_.'order_detail`
  55.                         (
  56.                             `id_order`,
  57.                             `id_order_invoice`,
  58.                             `id_shop`,
  59.                             `product_id`,
  60.                             `product_attribute_id`,
  61.                             `product_name`,
  62.                             `product_quantity`,
  63.                             `product_quantity_in_stock`,
  64.                             `product_price`,
  65.                             `product_reference`,
  66.                             `total_price_tax_incl`,
  67.                             `total_price_tax_excl`,
  68.                             `unit_price_tax_incl`,
  69.                             `unit_price_tax_excl`,
  70.                             `original_product_price`
  71.                         )
  72.                     VALUES
  73.                         (
  74.                             '.$order->id.',
  75.                             '.$id_order_invoice.',
  76.                             '.$cart->id_shop.',
  77.                             '.$product['id_product'].',
  78.                             '.$product['id_product_attribute'].',
  79.                             \''.pSQL($product['name']).'\',
  80.                             '.$product['cart_quantity'].',
  81.                             '.$product['cart_quantity'].',
  82.                             '.$product['price'].',
  83.                             \''.pSQL($product['reference']).'\',
  84.                             '.$product['total_wt'].',
  85.                             '.$product['total'].',
  86.                             '.$product['price_wt'].',
  87.                             '.$product['price'].',
  88.                             '.$product['price'].'
  89.                         )';
  90.                 Db::getInstance()->Execute($sql);
  91.                 $id_order_detail = Db::getInstance()->Insert_ID();
  92.                 Db::getInstance()->Execute('
  93.                     INSERT INTO `'._DB_PREFIX_.'order_detail_tax`
  94.                         (
  95.                             `id_order_detail`,
  96.                             `id_tax`,
  97.                             `unit_amount`,
  98.                             `total_amount`
  99.                         )
  100.                     VALUES
  101.                         (
  102.                             '.$id_order_detail.',
  103.                             '.$cart->id_shop.',
  104.                             '.($product['price_wt'] - $product['price']).',
  105.                             '.($product['total_wt'] - $product['total']).'
  106.                         )'
  107.                 );
  108.                
  109.             }
  110.         }
  111.  
  112.         header('Location: '.$_SERVER['REQUEST_URI']);
  113.    
  114.     }
  115.    
  116. }
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement