public function reduceProductsFromStocks($order_id) { $order_params_model = new shopOrderParamsModel(); $reduced = $order_params_model->getOne($order_id, 'reduced'); if ($reduced) { return; } $items_model = new shopOrderItemsModel(); $items = $items_model->select('*')->where("type='product' AND order_id = " . (int) $order_id)->fetchAll(); $sku_stock = array(); foreach ($items as $item) { if (!isset($sku_stock[$item['sku_id']][$item['stock_id']])) { $sku_stock[$item['sku_id']][$item['stock_id']] = 0; } $sku_stock[$item['sku_id']][$item['stock_id']] -= $item['quantity']; } $items_model->updateStockCount($sku_stock); $order_params_model->setOne($order_id, 'reduced', 1); }
/** * Verify that the plugin is suitable for payment of the order * @param int $order_id * @return bool|string */ private function isSuitable($order_id) { $order_params_model = new shopOrderParamsModel(); if (!$this->merchant_id) { return 'Invalid plugin id'; } else { if ($this->merchant_id != $order_params_model->getOne($order_id, 'payment_id')) { return 'Plugin does not suitable to payment of the order'; } $shop_plugin_model = new shopPluginModel(); if ($plugin = $shop_plugin_model->getById($this->merchant_id)) { if (!$plugin['status']) { return 'Plugin status is disabled'; } } else { return 'Plugin deleted'; } } return true; }