/**
  * @param ShopgateCart $cart
  * @return array
  */
 public function checkStock(ShopgateCart $cart)
 {
     $result = array();
     foreach ($cart->getItems() as $item) {
         $cartItem = new ShopgateCartItem();
         $cartItem->setItemNumber($item->getItemNumber());
         list($productId, $attributeId) = ShopgateHelper::getProductIdentifiers($item);
         /** @var ProductCore $product */
         if (version_compare(_PS_VERSION_, '1.5.2.0', '<')) {
             $product = new BWProduct($productId, true, $this->getPlugin()->getLanguageId());
         } else {
             $product = new Product($productId, $this->getPlugin()->getLanguageId());
         }
         if (empty($attributeId) && !empty($productId) && $product->hasAttributes()) {
             $result[] = $cartItem;
             continue;
         }
         $product->loadStockData();
         /**
          * validate attributes
          */
         if ($product->hasAttributes()) {
             $invalidAttribute = false;
             $message = '';
             if (!$attributeId) {
                 $cartItem->setError(ShopgateLibraryException::UNKNOWN_ERROR_CODE);
                 $cartItem->setErrorText('attributeId required');
                 $message = 'attributeId required';
                 $invalidAttribute = true;
             } else {
                 $validAttributeId = false;
                 if (version_compare(_PS_VERSION_, '1.5.0', '<')) {
                     $attributeIds = BWProduct::getProductAttributesIds($productId);
                 } else {
                     $attributeIds = $product->getProductAttributesIds($productId, true);
                 }
                 foreach ($attributeIds as $attribute) {
                     if ($attributeId == $attribute['id_product_attribute']) {
                         $validAttributeId = true;
                         continue;
                     }
                 }
                 if (!$validAttributeId) {
                     $invalidAttribute = true;
                     $message = 'invalid attributeId';
                 }
             }
             if ($invalidAttribute) {
                 $cartItem->setError(ShopgateLibraryException::UNKNOWN_ERROR_CODE);
                 $cartItem->setErrorText($message);
                 $result[] = $cartItem;
                 continue;
             }
         }
         if ($product->id) {
             if (version_compare(_PS_VERSION_, '1.5.0', '<')) {
                 $quantity = $product->getStockAvailable();
                 //getQuantityAvailableByProduct($productId, $attributeId, $this->getPlugin()->getContext()->shop->id);
             } else {
                 $quantity = StockAvailable::getQuantityAvailableByProduct($productId, $attributeId, $this->getPlugin()->getContext()->shop->id);
             }
             $cartItem->setStockQuantity($quantity);
             $cartItem->setIsBuyable($product->available_for_order && ($attributeId ? Attribute::checkAttributeQty($attributeId, ShopgateItemsCartExportJson::DEFAULT_QTY_TO_CHECK) : $product->checkQty(ShopgateItemsCartExportJson::DEFAULT_QTY_TO_CHECK)) || Product::isAvailableWhenOutOfStock($product->out_of_stock) ? 1 : 0);
         } else {
             $cartItem->setError(ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND);
             $cartItem->setErrorText(ShopgateLibraryException::getMessageFor($cartItem->getError()));
         }
         $result[] = $cartItem;
     }
     return $result;
 }