Example #1
0
 /**
  * Adjusts the stock for an aborted/failed order
  *
  * @param String $orderNumber
  */
 public function restockShopForOrder($orderNumber)
 {
     try {
         $sql = Shopware()->Db()->select()->from('s_order_details', array('articleID', 'quantity'))->join('s_articles_details', '`s_order_details`.`articleID` = `s_articles_details`.`articleID`', array('instock', 'sales'))->where('`s_order_details`.`ordernumber` = ?', array($orderNumber));
         $articles = Shopware()->Db()->fetchAll($sql);
         if (!$articles || is_array($articles) || count($articles) === 0) {
             return;
         }
         foreach ($articles as $article) {
             Shopware()->Db()->update('s_articles_details', array('instock' => $article['instock'] + $article['quantity'], 'sales' => $article['sales'] - $article['quantity']), '`articleID` = ' . $article['articleID']);
         }
     } catch (Exception $exception) {
         $this->log->logManually(__CLASS__, __METHOD__ . ": " . $exception->getMessage());
     }
 }