Example #1
0
 /**
  * Remove article from product for frontendviewing, if articles
  * with no stock should not shown.
  *
  * @param \CommerceTeam\Commerce\Domain\Model\Product $product Product
  * @param int $dontRemoveArticles Switch to show or not show articles
  *
  * @return \CommerceTeam\Commerce\Domain\Model\Product Cleaned up product object
  */
 public static function removeNoStockArticles(\CommerceTeam\Commerce\Domain\Model\Product $product, $dontRemoveArticles = 1)
 {
     if ($dontRemoveArticles == 1) {
         return $product;
     }
     $articleUids = $product->getArticleUids();
     $articles = $product->getArticleObjects();
     foreach ($articleUids as $arrayKey => $articleUid) {
         /**
          * Article.
          *
          * @var \CommerceTeam\Commerce\Domain\Model\Article $article
          */
         $article = $articles[$articleUid];
         if ($article->getStock() <= 0) {
             $product->removeArticleUid($arrayKey);
             $product->removeArticle($articleUid);
         }
     }
     return $product;
 }
 /**
  * Generates payment drop down list for this shop.
  *
  * @param array $basketArray Array of template marker
  *
  * @return array Template marker
  */
 public function makePayment(array $basketArray = array())
 {
     $this->paymentProduct = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Model\\Product', $this->conf['payProdId'], $this->getFrontendController()->sys_language_uid);
     $this->paymentProduct->loadData();
     $this->basketPaymentArticles = $this->basket->getArticlesByArticleTypeUidAsUidlist(PAYMENTARTICLETYPE);
     $select = '<select name="' . $this->prefixId . '[payArt]" onChange="this.form.submit();">';
     $addPleaseSelect = false;
     $addDefaultPaymentToBasket = false;
     // Check if a Payment is selected if not, add standard payment
     if (empty($this->basketPaymentArticles)) {
         // Check if Payment selection is forced
         if ($this->conf['payment.']['forceSelection']) {
             // Add Please Select Option
             $select .= '<option value="-1" selected="selected">' . $this->pi_getLL('lang_payment_force') . '</option>';
             $addPleaseSelect = true;
         } else {
             // No payment article is in the basket, so add the first one
             $addDefaultPaymentToBasket = true;
         }
     }
     $allowedArticles = array();
     if ($this->conf['payment.']['allowedArticles']) {
         $allowedArticles = explode(',', $this->conf['payment.']['allowedArticles']);
     }
     // Check if payment articles are allowed
     $newAllowedArticles = array();
     /**
      * Article.
      *
      * @var Article $article
      */
     foreach ($this->paymentProduct->getArticleObjects() as $articleUid => $article) {
         if (empty($allowedArticles) || in_array($articleUid, $allowedArticles)) {
             $article->loadData();
             $payment = $this->getPaymentObject($article->getClassname());
             if ($payment->isAllowed()) {
                 $newAllowedArticles[] = $articleUid;
             }
         }
     }
     // If default Paymentarticle is, for example, credit card
     // but when we have an article in the basket with the only possible
     // payment method like debit, this ensures that there is still the correct
     // payment article in the basket.
     // @todo: Refactor default handling
     if (count($newAllowedArticles) == 1 && $this->conf['defaultPaymentArticleId'] != $newAllowedArticles[0]) {
         $this->conf['defaultPaymentArticleId'] = $newAllowedArticles[0];
     }
     $allowedArticles = $newAllowedArticles;
     unset($newAllowedArticles);
     // Hook to allow to define/overwrite individually, which payment
     // articles are allowed
     $hooks = HookFactory::getHooks('Controller/BasketController', 'makePayment');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'paymentAllowedArticles')) {
             $allowedArticles = $hook->paymentAllowedArticles($this, $allowedArticles);
         }
     }
     $first = false;
     $priceNet = '';
     $priceGross = '';
     /**
      * Article.
      *
      * @var Article $article
      */
     foreach ($this->paymentProduct->getArticleObjects() as $articleUid => $article) {
         if (empty($allowedArticles) || in_array($articleUid, $allowedArticles)) {
             $select .= '<option value="' . $articleUid . '"';
             if ($articleUid == $this->basketPaymentArticles[0] || $addDefaultPaymentToBasket && $articleUid == $this->conf['defaultPaymentArticleId'] && !$addPleaseSelect) {
                 $addDefaultPaymentToBasket = false;
                 $first = true;
                 $select .= ' selected="selected"';
                 $this->basket->addArticle($articleUid);
                 $priceNet = Money::format($article->getPriceNet(), $this->currency);
                 $priceGross = Money::format($article->getPriceGross(), $this->currency);
             } elseif (!$first) {
                 $priceNet = Money::format($article->getPriceNet(), $this->currency);
                 $priceGross = Money::format($article->getPriceGross(), $this->currency);
                 $this->basket->deleteArticle($articleUid);
             }
             $select .= '>' . $article->getTitle() . '</option>';
         }
     }
     $select .= '</select>';
     // Set Prices to 0, if "please select " is shown
     if ($addPleaseSelect) {
         $priceGross = Money::format(0, $this->currency);
         $priceNet = Money::format(0, $this->currency);
     }
     $basketArray['###PAYMENT_SELECT_BOX###'] = $select;
     $basketArray['###PAYMENT_PRICE_GROSS###'] = $priceGross;
     $basketArray['###PAYMENT_PRICE_NET###'] = $priceNet;
     $this->basket->storeData();
     return $basketArray;
 }