Exemplo n.º 1
0
 /**
  * Generates a ShopgateCartItem for the checkCart Response
  *
  * @param Mage_Catalog_Model_Product $product
  * @param boolean                    $isBuyable
  * @param int                        $qtyBuyable
  * @param int|float                  $priceExclTax
  * @param int|float                  $priceInclTax
  * @param array                      $errors
  * @param bool                       $stockQuantity
  *
  * @return ShopgateCartItem
  */
 public function generateShopgateCartItem($product, $isBuyable = false, $qtyBuyable = 0, $priceInclTax = 0, $priceExclTax = 0, $errors = array(), $stockQuantity = false)
 {
     $item = new ShopgateCartItem();
     $item->setItemNumber($product->getShopgateItemNumber());
     $item->setOptions($product->getShopgateOptions());
     $item->setInputs($product->getShopgateInputs());
     $item->setAttributes($product->getShhopgateAttributes());
     $item->setIsBuyable((int) $isBuyable);
     $item->setQtyBuyable($qtyBuyable);
     $item->setStockQuantity($stockQuantity);
     $item->setUnitAmount($priceExclTax);
     $item->setUnitAmountWithTax($priceInclTax);
     foreach ($errors as $error) {
         $item->setError($error['type']);
         $item->setErrorText($error['message']);
     }
     return $item;
 }
Exemplo n.º 2
0
 /**
  * @param $cart
  * @return array
  */
 protected function _addItems($cart)
 {
     $resultItems = array();
     foreach ($cart->getItems() as $item) {
         list($productId, $attributeId) = ShopgateHelper::getProductIdentifiers($item);
         /** @var ProductCore $product */
         $product = new Product($productId);
         $resultItem = new ShopgateCartItem();
         $resultItem->setItemNumber($item->getItemNumber());
         $resultItem->setStockQuantity($product->getQuantity($product->id, $attributeId));
         $resultItem->setUnitAmount($product->getPrice(false, $attributeId));
         $resultItem->setUnitAmountWithTax($product->getPrice(true, $attributeId));
         $resultItem->setOptions($item->getOptions());
         $resultItem->setAttributes($item->getAttributes());
         $resultItem->setInputs($item->getInputs());
         /**
          * validate product
          */
         if (!$this->_validateProduct($product, $attributeId)) {
             $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND, sprintf('ProductId #%s AttributeId #%s', $productId, $attributeId));
             $resultItems[] = $resultItem;
             continue;
         }
         $addItemResult = $this->getPlugin()->getContext()->cart->updateQty($item->getQuantity(), $productId, $attributeId, false, 'up', $this->_deliveryAddress && $this->_deliveryAddress->id ? $this->_deliveryAddress->id : 0);
         $this->getPlugin()->getContext()->cart->save();
         if ($addItemResult != 1) {
             $resultItem->setIsBuyable(false);
             $resultItem->setQtyBuyable($product->getQuantity($productId, $attributeId));
             /**
              * add error
              */
             switch ($addItemResult) {
                 case -1:
                     $resultItem->setQtyBuyable($attributeId ? (int) Attribute::getAttributeMinimalQty($attributeId) : (int) $product->minimal_quantity);
                     $minimalQuantity = $attributeId ? (int) Attribute::getAttributeMinimalQty($attributeId) : (int) $product->minimal_quantity;
                     $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_UNDER_MINIMUM_QUANTITY, sprintf(Tools::displayError('You must add %d minimum quantity'), $minimalQuantity));
                     break;
                 default:
                     $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE, Tools::displayError('There isn\'t enough product in stock.'));
                     break;
             }
         } else {
             $resultItem->setIsBuyable(true);
             $resultItem->setQtyBuyable((int) $item->getQuantity());
         }
         $resultItems[] = $resultItem;
     }
     return $resultItems;
 }