public function postExecute($order_id = null, $result = null)
 {
     $data = parent::postExecute($order_id, $result);
     $log_model = new waLogModel();
     $log_model->add('order_complete', $order_id);
     $order_model = new shopOrderModel();
     if (is_array($order_id)) {
         $order = $order_id;
         $order_id = $order['id'];
     } else {
         $order = $order_model->getById($order_id);
     }
     shopCustomers::recalculateTotalSpent($order['contact_id']);
     if ($order !== null) {
         $log_model = new shopOrderLogModel();
         $state_id = $log_model->getPreviousState($order_id);
         $app_settings_model = new waAppSettingsModel();
         $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order');
         if (!$update_on_create && $state_id == 'new') {
             // jump through 'processing' state - reduce
             // for logging changes in stocks
             shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was completed', array('order_id' => $order_id));
             $order_model = new shopOrderModel();
             $order_model->reduceProductsFromStocks($order_id);
             shopProductStocksLogModel::clearContext();
         }
         $order_model->recalculateProductsTotalSales($order_id);
     }
     return $data;
 }
 public function postExecute($order_id = null, $result = null)
 {
     $data = parent::postExecute($order_id, $result);
     if ($order_id != null) {
         $log_model = new waLogModel();
         $log_model->add('order_delete', $order_id);
         $order_model = new shopOrderModel();
         $app_settings_model = new waAppSettingsModel();
         if ($data['before_state_id'] != 'refunded') {
             $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order');
             // for logging changes in stocks
             shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was deleted', array('order_id' => $order_id));
             if ($update_on_create) {
                 $order_model->returnProductsToStocks($order_id);
             } else {
                 if (!$update_on_create && $data['before_state_id'] != 'new') {
                     $order_model->returnProductsToStocks($order_id);
                 }
             }
             shopProductStocksLogModel::clearContext();
         }
         $order = $order_model->getById($order_id);
         if ($order && $order['paid_date']) {
             // Remember paid_date in log params for Restore action
             $olpm = new shopOrderLogParamsModel();
             $olpm->insert(array('name' => 'paid_date', 'value' => $order['paid_date'], 'order_id' => $order_id, 'log_id' => $data['id']));
             // Empty paid_date and update stats so that deleted orders do not affect reports
             $order_model->updateById($order_id, array('paid_date' => null, 'paid_year' => null, 'paid_month' => null, 'paid_quarter' => null));
             $order_model->recalculateProductsTotalSales($order_id);
             shopCustomers::recalculateTotalSpent($order['contact_id']);
         }
     }
     return $data;
 }
 public function postExecute($order_id = null, $result = null)
 {
     $data = parent::postExecute($order_id, $result);
     if ($order_id != null) {
         $log_model = new waLogModel();
         $log_model->add('order_restore', $order_id);
         $order_model = new shopOrderModel();
         $app_settings_model = new waAppSettingsModel();
         if ($this->state_id != 'refunded') {
             // for logging changes in stocks
             shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was restored', array('order_id' => $order_id));
             $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order');
             if ($update_on_create) {
                 $order_model->reduceProductsFromStocks($order_id);
             } else {
                 if (!$update_on_create && $this->state_id != 'new') {
                     $order_model->reduceProductsFromStocks($order_id);
                 }
             }
             shopProductStocksLogModel::clearContext();
         }
         $order = $order_model->getById($order_id);
         if ($order && $order['paid_date']) {
             shopAffiliate::applyBonus($order_id);
             shopCustomers::recalculateTotalSpent($order['contact_id']);
         }
     }
     return $data;
 }
 public function execute(&$params)
 {
     $master_id = $params['id'];
     $merge_ids = $params['contacts'];
     $all_ids = array_merge($merge_ids, array($master_id));
     $m = new waModel();
     //
     // All the simple cases: update contact_id in tables
     //
     foreach (array(array('shop_cart_items', 'contact_id'), array('shop_checkout_flow', 'contact_id'), array('shop_order', 'contact_id'), array('shop_order_log', 'contact_id'), array('shop_product', 'contact_id'), array('shop_product_reviews', 'contact_id'), array('shop_affiliate_transaction', 'contact_id')) as $pair) {
         list($table, $field) = $pair;
         $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)";
         $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids));
     }
     //
     // shop_affiliate_transaction
     //
     $balance = 0.0;
     $sql = "SELECT * FROM shop_affiliate_transaction WHERE contact_id=? ORDER BY id";
     foreach ($m->query($sql, $master_id) as $row) {
         $balance += $row['amount'];
         if ($row['balance'] != $balance) {
             $m->exec("UPDATE shop_affiliate_transaction SET balance=? WHERE id=?", $balance, $row['id']);
         }
     }
     $affiliate_bonus = $balance;
     //
     // shop_customer
     //
     // Make sure it exists
     $cm = new shopCustomerModel();
     $cm->createFromContact($master_id);
     $sql = "SELECT SUM(number_of_orders) FROM shop_customer WHERE contact_id IN (:ids)";
     $number_of_orders = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "SELECT MAX(last_order_id) FROM shop_customer WHERE contact_id IN (:ids)";
     $last_order_id = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "UPDATE shop_customer SET number_of_orders=?, last_order_id=?, affiliate_bonus=? WHERE contact_id=?";
     $m->exec($sql, ifempty($number_of_orders, 0), ifempty($last_order_id, null), ifempty($affiliate_bonus, 0), $master_id);
     if ($number_of_orders) {
         shopCustomers::recalculateTotalSpent($master_id);
     }
     wa('shop')->event('customers_merge', $params);
     return null;
 }
 public function postExecute($order_id = null, $result = null)
 {
     $data = parent::postExecute($order_id, $result);
     $order_model = new shopOrderModel();
     if (is_array($order_id)) {
         $order = $order_id;
         $order_id = $order['id'];
     } else {
         $order = $order_model->getById($order_id);
     }
     shopCustomers::recalculateTotalSpent($order['contact_id']);
     if ($order_id != null) {
         $log_model = new waLogModel();
         $log_model->add('order_refund', $order_id);
         $order_model = new shopOrderModel();
         $order_model->updateById($order_id, array('paid_date' => null, 'paid_year' => null, 'paid_month' => null, 'paid_quarter' => null));
         // for logging changes in stocks
         shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was refunded', array('order_id' => $order_id));
         $order_model->returnProductsToStocks($order_id);
         shopAffiliate::cancelBonus($order_id);
         $order_model->recalculateProductsTotalSales($order_id);
     }
     return $data;
 }
示例#6
0
<?php

$order_model = new shopOrderModel();
$sql = "SELECT * FROM shop_order WHERE state_id = 'deleted' AND paid_date IS NOT NULL";
foreach ($order_model->query($sql) as $order) {
    $order_id = $order['id'];
    shopCustomers::recalculateTotalSpent($order['contact_id']);
    $order_model->updateById($order_id, array('paid_date' => null, 'paid_year' => null, 'paid_month' => null, 'paid_quarter' => null));
    $order_model->returnProductsToStocks($order_id);
    shopAffiliate::cancelBonus($order_id);
    $order_model->recalculateProductsTotalSales($order_id);
}