/** * 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; }