/**
  * Handle adding article.
  *
  * @return void
  */
 public function handleAddArticle()
 {
     $hooks = HookFactory::getHooks('Controller/BasketController', 'handleAddArticle');
     // Hook to process basket before adding an article to basket
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'preartAddUid')) {
             $hookObj->preartAddUid($this->basket, $this);
         }
     }
     if (isset($this->piVars['artAddUid']) && is_array($this->piVars['artAddUid'])) {
         foreach ($this->piVars['artAddUid'] as $articleUid => $articleAddValues) {
             $articleUid = (int) $articleUid;
             /**
              * Basket item.
              *
              * @var \CommerceTeam\Commerce\Domain\Model\BasketItem $basketItem
              */
             $basketItem = $this->basket->getBasketItem($articleUid);
             // Safe old quantity for price limit
             if ($basketItem) {
                 $oldCountValue = $basketItem->getQuantity();
             } else {
                 $oldCountValue = 0;
             }
             if (!isset($articleAddValues['count']) || $articleAddValues['count'] < 0) {
                 $articleAddValues['count'] = 1;
             }
             if ((int) $articleAddValues['count'] === 0) {
                 if ($this->basket->getQuantity($articleUid) > 0) {
                     $this->basket->deleteArticle($articleUid);
                 }
                 foreach ($hooks as $hookObj) {
                     if (method_exists($hookObj, 'postDeleteArtUidSingle')) {
                         $hookObj->postDeleteArtUidSingle($articleUid, $articleAddValues, $oldCountValue, $this->basket, $this);
                     }
                 }
             } else {
                 /**
                  * Article.
                  *
                  * @var Article $article
                  */
                 $article = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Article', $articleUid);
                 $article->loadData('basket');
                 $productObj = $article->getParentProduct();
                 $productObj->loadData('basket');
                 foreach ($hooks as $hookObj) {
                     if (method_exists($hookObj, 'preartAddUidSingle')) {
                         $hookObj->preartAddUidSingle($articleUid, $articleAddValues, $productObj, $article, $this->basket, $this);
                     }
                 }
                 if ($article->isAccessible() && $productObj->isAccessible()) {
                     // Only if product and article are accessible
                     if ($this->conf['checkStock'] == 1) {
                         // Instance to calculate shipping costs
                         if ($article->hasStock($articleAddValues['count'])) {
                             if ((int) $articleAddValues['price_id'] > 0) {
                                 $this->basket->addArticle($articleUid, $articleAddValues['count'], $articleAddValues['price_id']);
                             } else {
                                 $this->basket->addArticle($articleUid, $articleAddValues['count']);
                             }
                         } else {
                             $this->noStock = $this->pi_getLL('noStock');
                         }
                     } else {
                         // Add article by default
                         if ((int) $articleAddValues['price_id'] > 0) {
                             $this->basket->addArticle($articleUid, $articleAddValues['count'], $articleAddValues['price_id']);
                         } else {
                             $this->basket->addArticle($articleUid, $articleAddValues['count']);
                         }
                     }
                 }
                 foreach ($hooks as $hookObj) {
                     if (method_exists($hookObj, 'postartAddUidSingle')) {
                         $hookObj->postartAddUidSingle($articleUid, $articleAddValues, $productObj, $article, $this->basket, $this);
                     }
                 }
                 // Check for basket price limit
                 if ((int) $this->conf['priceLimitForBasket'] && $this->basket->getSumGross() > (int) $this->conf['priceLimitForBasket']) {
                     $this->basket->addArticle($articleUid, $oldCountValue);
                     $this->setPriceLimitForBasket(1);
                 }
             }
         }
         foreach ($hooks as $hookObj) {
             if (method_exists($hookObj, 'postartAddUid')) {
                 $hookObj->postartAddUid($this->basket, $this);
             }
         }
     }
 }