Example #1
0
 /**
  * Tries to ping AvaTax service with provided credentials
  *
  * @param int $storeId
  * @return bool|array
  */
 public function ping($storeId = null)
 {
     /** @var OnePica_AvaTax_Model_Service_Avatax16_Config $config */
     $config = $this->getServiceConfig();
     $connection = $config->getTaxConnection();
     $result = null;
     $message = '';
     try {
         /** @var OnePica\AvaTax16\AddressResolution\PingResponse $result */
         $result = $connection->ping();
     } catch (Exception $exception) {
         $message = $exception->getMessage();
     }
     if (!isset($result) || !is_object($result) || !$result->getHasError()) {
         $actualResult = $result;
         $result = new Varien_Object();
         $result->setHasError($result->getHasError());
         $result->setActualResult($actualResult);
         $result->setMessage($message);
     }
     $this->_log(OnePica_AvaTax_Model_Source_Avatax_Logtype::PING, new stdClass(), $result, $storeId, $config->getParams());
     if ($result->getHasError()) {
         if (is_array($result->getErrors())) {
             $messages = array();
             foreach ($result->getErrors() as $messageItem) {
                 $messages[] = $this->__($messageItem);
             }
             $message .= implode(' ', $messages);
         }
     }
     if (!$message) {
         $message = $this->__('The user or account could not be authenticated.');
     }
     return !$result->getHasError() ? true : $message;
 }
 /**
  * Checking quote item quantity
  *
  * Second parameter of this method specifies quantity of this product in whole shopping cart
  * which should be checked for stock availability
  *
  * @param mixed $qty quantity of this item (item qty x parent item qty)
  * @param mixed $summaryQty quantity of this product
  * @param mixed $origQty original qty of item (not multiplied on parent item qty)
  * @return Varien_Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
 {
     $result = new Varien_Object();
     $result->setHasError(false);
     if (!is_numeric($qty)) {
         $qty = Mage::app()->getLocale()->getNumber($qty);
     }
     /**
      * Check quantity type
      */
     $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
     if (!$this->getIsQtyDecimal()) {
         $result->setHasQtyOptionUpdate(true);
         $qty = intval($qty);
         /**
          * Adding stock data to quote item
          */
         $result->setItemQty($qty);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         $origQty = intval($origQty);
         $result->setOrigQty($origQty);
     }
     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     $result->addData($this->checkQtyIncrements($qty)->getData());
     if ($result->getHasError()) {
         return $result;
     }
     if (!$this->getManageStock()) {
         return $result;
     }
     if (!$this->getIsInStock()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.'))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock.'))->setQuoteMessageIndex('stock');
         $result->setItemUseOldQty(true);
         return $result;
     }
     if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) {
         $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
         $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
         return $result;
     } else {
         if ($this->getQty() - $summaryQty < 0) {
             if ($this->getProductName()) {
                 if ($this->getIsChildItem()) {
                     $backorderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1;
                     if ($backorderQty > $qty) {
                         $backorderQty = $qty;
                     }
                     $result->setItemBackorders($backorderQty);
                 } else {
                     $orderedItems = $this->getOrderedItems();
                     $itemsLeft = $this->getQty() > $orderedItems ? ($this->getQty() - $orderedItems) * 1 : 0;
                     $backorderQty = $itemsLeft > 0 ? ($qty - $itemsLeft) * 1 : $qty * 1;
                     if ($backorderQty > 0) {
                         $result->setItemBackorders($backorderQty);
                     }
                     $this->setOrderedItems($orderedItems + $qty);
                 }
                 if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) {
                     if (!$this->getIsChildItem()) {
                         $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', $backorderQty * 1));
                     } else {
                         $result->setMessage(Mage::helper('cataloginventory')->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), $backorderQty * 1));
                     }
                 } elseif (Mage::app()->getStore()->isAdmin()) {
                     $result->setMessage(Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()));
                 }
             }
         } else {
             if (!$this->getIsChildItem()) {
                 $this->setOrderedItems($qty + (int) $this->getOrderedItems());
             }
         }
     }
     return $result;
 }
Example #3
0
 /**
  * Checking quote item quantity
  *
  * @param mixed $qty quantity of this item (item qty x parent item qty)
  * @param mixed $summaryQty quantity of this product in whole shopping cart which should be checked for stock availability
  * @param mixed $origQty original qty of item (not multiplied on parent item qty)
  * @return Varien_Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
 {
     $result = new Varien_Object();
     $result->setHasError(false);
     if (!is_numeric($qty)) {
         $qty = Mage::app()->getLocale()->getNumber($qty);
     }
     /**
      * Check quantity type
      */
     $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
     if (!$this->getIsQtyDecimal()) {
         $result->setHasQtyOptionUpdate(true);
         $qty = intval($qty);
         /**
          * Adding stock data to quote item
          */
         $result->setItemQty($qty);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         $origQty = intval($origQty);
         $result->setOrigQty($origQty);
     }
     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     if (!$this->getManageStock()) {
         return $result;
     }
     //2011-11-15 HiepHM Fix bug not check stock when load order.
     $_session = Mage::getSingleton('adminhtml/session_quote');
     $currentItem = false;
     if ($_session->getOrder()->getId()) {
         $old_order = $_session->getOrder();
         //Check if current item is ordered, then substract the ordered qty before checking.
         foreach ($old_order->getItemsCollection(array_keys(Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()), true) as $orderItem) {
             if ($orderItem->getProductId() == $this->getProductId()) {
                 $currentItem = $orderItem;
                 break;
             }
         }
     }
     if (!$currentItem && !$this->getIsInStock()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.'))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock'))->setQuoteMessageIndex('stock');
         $result->setItemUseOldQty(true);
         return $result;
     }
     $result->addData($this->checkQtyIncrements($qty)->getData());
     if ($result->getHasError()) {
         return $result;
     }
     if (!$this->checkQty($summaryQty, $currentItem)) {
         $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
         $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
         return $result;
     } else {
         if ($this->getQty() - $summaryQty < 0) {
             if ($this->getProductName()) {
                 if ($this->getIsChildItem()) {
                     $backorderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1;
                     if ($backorderQty > $qty) {
                         $backorderQty = $qty;
                     }
                     $result->setItemBackorders($backorderQty);
                 } else {
                     $orderedItems = $this->getOrderedItems();
                     $itemsLeft = $this->getQty() > $orderedItems ? ($this->getQty() - $orderedItems) * 1 : 0;
                     $backorderQty = $itemsLeft > 0 ? ($qty - $itemsLeft) * 1 : $qty * 1;
                     if ($backorderQty > 0) {
                         $result->setItemBackorders($backorderQty);
                     }
                     $this->setOrderedItems($orderedItems + $qty);
                 }
                 if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) {
                     if (!$this->getIsChildItem()) {
                         $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', $backorderQty * 1));
                     } else {
                         $result->setMessage(Mage::helper('cataloginventory')->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), $backorderQty * 1));
                     }
                 }
             }
         }
         // no return intentionally
     }
     return $result;
 }
Example #4
0
 /**
  * Checking quote item quantity
  *
  * Second parameter of this method specifies quantity of this product in whole shopping cart
  * which should be checked for stock availability
  *
  * @param mixed $qty quantity of this item (item qty x parent item qty)
  * @param mixed $summaryQty quantity of this product
  * @param mixed $origQty original qty of item (not multiplied on parent item qty)
  * @return Varien_Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
 {
     $result = new Varien_Object();
     $result->setHasError(false);
     if (!is_numeric($qty)) {
         $qty = Mage::app()->getLocale()->getNumber($qty);
     }
     /**
      * Check quantity type
      */
     $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
     if (!$this->getIsQtyDecimal()) {
         $result->setHasQtyOptionUpdate(true);
         $qty = intval($qty);
         /**
          * Adding stock data to quote item
          */
         $result->setItemQty($qty);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         $origQty = intval($origQty);
         $result->setOrigQty($origQty);
     }
     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     /*Custom Code to overlook Max item Qty Check for Premium */
     //commenting code as this fetaure is being disabled tempriorly
     /*
     		try
     		{
     $cat_array = $this->getProduct()->getCategoryIds();
     
     if(is_array($cat_array) && sizeof($cat_array) == 1 && sizeof($cat_array) > 0){
     	$cat_id = $cat_array[0];
     	$cat_url_key = Mage::getModel('catalog/category')->load($cat_id)->getUrlKey();
     	if($cat_url_key != 'premium-packaging'){
     		if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
     			$result->setHasError(true)
     				->setMessage(
     					Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1)
     				)
     			->setErrorCode('qty_max')
     			->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))
     			->setQuoteMessageIndex('qty');
     			return $result;
     		}
     	}
     }
     if(is_array($cat_array) && sizeof($cat_array) != 1 && sizeof($cat_array) > 0){
     */
     if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     /*
     	}
     }catch(Exception $e){
     		Mage::log('Exception occured during the check for Max Qty --- '.$e);
     }
     */
     /*Custom code Ends here */
     $result->addData($this->checkQtyIncrements($qty)->getData());
     if ($result->getHasError()) {
         return $result;
     }
     if (!$this->getManageStock()) {
         return $result;
     }
     if (!$this->getIsInStock()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.'))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock'))->setQuoteMessageIndex('stock');
         $result->setItemUseOldQty(true);
         return $result;
     }
     if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) {
         $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
         $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
         return $result;
     } else {
         if ($this->getQty() - $summaryQty < 0) {
             if ($this->getProductName()) {
                 if ($this->getIsChildItem()) {
                     $backorderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1;
                     if ($backorderQty > $qty) {
                         $backorderQty = $qty;
                     }
                     $result->setItemBackorders($backorderQty);
                 } else {
                     $orderedItems = $this->getOrderedItems();
                     $itemsLeft = $this->getQty() > $orderedItems ? ($this->getQty() - $orderedItems) * 1 : 0;
                     $backorderQty = $itemsLeft > 0 ? ($qty - $itemsLeft) * 1 : $qty * 1;
                     if ($backorderQty > 0) {
                         $result->setItemBackorders($backorderQty);
                     }
                     $this->setOrderedItems($orderedItems + $qty);
                 }
                 /* Extra Code added to set backorder message for Premium products in cart */
                 //commenting code as this fetaure is being disabled tempriorly
                 /*
                 $_outOfStockProductId = $this->getProduct()->getCategoryIds();
                 
                 if(is_array($_outOfStockProductId) && isset($_outOfStockProductId[0])){
                 	$_catId = $_outOfStockProductId[0];
                 }else{
                 	$_catId = $_outOfStockProductId;
                 }
                 
                 $_outOfStockProductCatUrlKey = Mage::getModel('catalog/category')->load($_catId)->getUrlKey();
                 */
                 /* End of extra code */
                 if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) {
                     if (!$this->getIsChildItem()) {
                         /*
                         	//commenting code as this fetaure is being disabled tempriorly
                         	if($_outOfStockProductCatUrlKey == 'premium-packaging'){
                         		$result->setMessage(
                         			Mage::helper('cataloginventory')->__('The requested quantity for Premium Package is not available. %s of the items will be backordered. You can still checkout or reduce the number of premium packages included in order.', ($backorderQty * 1))
                         		);
                         	}else{
                         */
                         $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', $backorderQty * 1));
                         // }
                     } else {
                         $result->setMessage(Mage::helper('cataloginventory')->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), $backorderQty * 1));
                     }
                 } elseif (Mage::app()->getStore()->isAdmin()) {
                     $result->setMessage(Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()));
                 }
             }
         } else {
             if (!$this->getIsChildItem()) {
                 $this->setOrderedItems($qty + (int) $this->getOrderedItems());
             }
         }
     }
     return $result;
 }
Example #5
0
 /**
  * override for changing the current stock qty based on the quote_item
  * (this is a bad design from Magento, checkQuoteItemQty should receive the quoteItem in the original code too)
  *
  * @param mixed $qty
  * @param mixed $summaryQty
  * @param int $origQty
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  *
  * @return Varien_Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0, $quoteItem = null, $product = null)
 {
     if ($quoteItem && ITwebexperts_Payperrentals_Helper_Data::isReservationOnly($product) && (!$quoteItem->getChildren() || Mage::app()->getStore()->isAdmin())) {
         $qtyOption = 1;
         if ($quoteItem->getParentProductQty()) {
             $qty = $quoteItem->getParentProductQty();
             $qtyOption = $quoteItem->getParentProductQtyOption();
         }
         $quoteItemId = $quoteItem->getId();
         if ($quoteItem->getParentItem() && $quoteItem->getParentItem()->getProduct()) {
             if ($quoteItem->getParentItem()->getProduct()->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) {
                 $quoteItemId = $quoteItem->getParentItem()->getItemId();
             }
         }
         $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($product, $quoteItem);
         list($startDate, $endDate) = array($turnoverArr['before'], $turnoverArr['after']);
         $result = new Varien_Object();
         $result->setHasError(false);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         /**
          * Check quantity type
          */
         $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
         if (!$this->getIsQtyDecimal()) {
             $result->setHasQtyOptionUpdate(true);
             $qty = intval($qty);
             /**
              * Adding stock data to quote item
              */
             $result->setItemQty($qty);
             if (!is_numeric($qty)) {
                 $qty = Mage::app()->getLocale()->getNumber($qty);
             }
             $origQty = intval($origQty);
             $result->setOrigQty($origQty);
         }
         if ($qty < ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)) {
             $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
             return $result;
         }
         if ($qty > ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)) {
             $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
             return $result;
         }
         $result->addData($this->checkQtyIncrements($qty)->getData());
         if ($result->getHasError()) {
             return $result;
         }
         $option = $quoteItem->getOptionByCode('info_buyRequest');
         $buyRequest = $option ? unserialize($option->getValue()) : null;
         if (Mage::app()->getStore()->isAdmin() && Mage::getSingleton('adminhtml/session_quote')->getOrderId()) {
             $editedOrderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId();
             $order = Mage::getModel('sales/order')->load($editedOrderId);
             $buyRequestArray = (array) $buyRequest;
             foreach ($order->getAllItems() as $oItem) {
                 if ($oItem->getProduct()->getId() != $product->getId()) {
                     continue;
                 }
                 if (is_object($oItem->getOrderItem())) {
                     $item = $oItem->getOrderItem();
                 } else {
                     $item = $oItem;
                 }
                 if ($item->getParentItem()) {
                     continue;
                 }
                 //check for bundles
                 if (count($item->getChildrenItems()) > 0) {
                     foreach ($item->getChildrenItems() as $child) {
                         $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child);
                         $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $item->getQtyOrdered());
                     }
                 } else {
                     $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item);
                     $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $item->getQtyOrdered());
                 }
             }
             $buyRequest = new Varien_Object($buyRequestArray);
         }
         if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
             if (strtotime($buyRequest['start_date']) > strtotime($buyRequest['end_date'])) {
                 $message = Mage::helper('payperrentals')->__('Start Date is bigger then End Date. Please change!');
                 $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
                 return $result;
             }
         }
         $isAvailable = false;
         if (ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId())) {
             $isAvailable = true;
         }
         if (ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest)) {
             if (!$isAvailable) {
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, null, null, $buyRequest);
                 Mage::unregister('quote_item_id');
                 if ($maxQty >= $qty) {
                     $isAvailable = true;
                 }
             }
             if ($isAvailable) {
                 return $result;
             } else {
                 $message = Mage::helper('payperrentals')->__('There is not enough quantity for buy this product');
                 $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
                 return $result;
             }
         }
         if (!Mage::app()->getStore()->isAdmin() && !Mage::getSingleton('checkout/session')->getIsExtendedQuote() && isset($buyRequest['start_date']) && isset($buyRequest['end_date']) && ITwebexperts_Payperrentals_Helper_Inventory::isExcludedDay($product->getId(), $buyRequest['start_date'], $buyRequest['end_date'])) {
             $message = Mage::helper('payperrentals')->__('There are blocked dates or excluded days on your selected dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         } else {
             if (!$isAvailable && isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest);
                 Mage::unregister('quote_item_id');
                 if ($maxQty >= $qty) {
                     $isAvailable = true;
                 }
             }
         }
         if (ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart($product) && !$buyRequest['start_date']) {
             $message = Mage::helper('payperrentals')->__('Please select Global Dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         }
         if (!Mage::app()->getStore()->isAdmin() && !ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest) && (isset($buyRequest['start_date']) && strtotime($buyRequest['start_date']) < strtotime(date('Y-m-d')) || isset($buyRequest['end_date']) && strtotime($buyRequest['end_date']) < strtotime(date('Y-m-d')))) {
             $message = Mage::helper('payperrentals')->__('The selected Dates are in the past. Please select new dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         }
         if (Mage::app()->getStore()->isAdmin() && ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId()) && ITwebexperts_Payperrentals_Helper_Inventory::showAdminOverbookWarning()) {
             Mage::register('quote_item_id', $quoteItemId);
             $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest, true);
             Mage::unregister('quote_item_id');
             if ($maxQty < $qty) {
                 $message = Mage::helper('cataloginventory')->__('Product is not available for the selected dates');
                 $result->setHasError(false)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr');
                 return $result;
             }
         }
         Mage::dispatchEvent('before_stock_check', array('buyrequest' => $buyRequest, 'isavailable' => &$isAvailable));
         if (!$isAvailable) {
             if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
                 //Mage::register('no_quote', 1);
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest);
                 Mage::unregister('quote_item_id');
                 $maxQty = intval($maxQty / $qtyOption);
                 //Mage::unregister('no_quote', 1);
                 if ($maxQty > 0) {
                     $message = Mage::helper('payperrentals')->__('Max quantity available for these dates is: ' . $maxQty . ', your quantity has been adjusted.');
                     // Mage::getSingleton('checkout/session')->addError($message);
                     $result->setHasQtyOptionUpdate(true);
                     //$result->setOrigQty($maxQty);
                     $result->setQty($maxQty);
                     $result->setItemQty($maxQty);
                     $result->setMessage($message)->setQuoteMessage($message);
                     return $result;
                 }
                 $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
             } else {
                 $message = Mage::helper('cataloginventory')->__('Please select Start and End Dates');
             }
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr');
             return $result;
         }
         return $result;
     }
     $return = parent::checkQuoteItemQty($qty, $summaryQty, $origQty);
     return $return;
 }
Example #6
0
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
 {
     $result = new Varien_Object();
     $result->setHasError(false);
     if (!is_numeric($qty)) {
         $qty = Mage::app()->getLocale()->getNumber($qty);
     }
     /**
      * Check quantity type
      */
     $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
     if (!$this->getIsQtyDecimal()) {
         $result->setHasQtyOptionUpdate(true);
         $qty = intval($qty);
         /**
          * Adding stock data to quote item
          */
         $result->setItemQty($qty);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         $origQty = intval($origQty);
         $result->setOrigQty($origQty);
     }
     if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
         return $result;
     }
     $result->addData($this->checkQtyIncrements($qty)->getData());
     if ($result->getHasError()) {
         return $result;
     }
     if (!$this->getManageStock()) {
         return $result;
     }
     if (!$this->getIsInStock()) {
         $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.'))->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock.'))->setQuoteMessageIndex('stock');
         $result->setItemUseOldQty(true);
         return $result;
     }
     if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) {
         $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
         $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
         return $result;
     } else {
         if (Mage::getStoreConfig("advancedinventory/setting/usemultistock")) {
             $productId = $this->getProductId();
             if (Mage::app()->getStore()->isAdmin()) {
                 $stores = Mage::getModel('pointofsale/pointofsale')->getPlacesByStoreId(Mage::getSingleton('adminhtml/session_quote')->getQuote()->getStoreId());
             } else {
                 $stores = Mage::getModel('pointofsale/pointofsale')->getPlacesByStoreId(Mage::app()->getStore()->getStoreId());
             }
             $_qty = 0;
             $backOrderAllowed = 0;
             $useDefaultConfigBackOrder = 1;
             $defaultBackOrdeValue = Mage::getStoreConfig("cataloginventory/item_options/backorders");
             $manageLocalStock = 0;
             $noStock = 0;
             foreach ($stores as $s) {
                 $stock = Mage::getModel('advancedinventory/stock')->getStockByProductIdAndPlaceId($productId, $s['place_id']);
                 $_qty += $stock->getQuantity_in_stock();
                 if (!$stock->getManageStock()) {
                     $noStock++;
                 }
                 if ($stock->getBackorder_allowed() > $backOrderAllowed) {
                     $backOrderAllowed = $stock->getBackorder_allowed();
                 }
                 if (!$stock->getUse_config_setting_for_backorders()) {
                     $useDefaultConfigBackOrder = $stock->getUse_config_setting_for_backorders();
                 }
                 $manageLocalStock += $stock->getManage_local_stock();
             }
             if ($manageLocalStock) {
                 $this->setQty(number_format($_qty, 4));
                 if ($noStock) {
                     $this->_backorders = 1;
                 } else {
                     if ($useDefaultConfigBackOrder && $defaultBackOrdeValue) {
                         $this->_backorders = $defaultBackOrdeValue;
                     } else {
                         if (!$useDefaultConfigBackOrder && $backOrderAllowed) {
                             $this->_backorders = $backOrderAllowed;
                         } else {
                             $this->_backorders = $this->getBackorders();
                         }
                     }
                 }
             } else {
                 $this->_backorders = $this->getBackorders();
             }
         } else {
             $this->_backorders = $this->getBackorders();
         }
         if ($this->getQty() - $summaryQty < 0) {
             if ($this->getProductName()) {
                 if ($this->getIsChildItem()) {
                     $backorderQty = $this->getQty() > 0 ? ($summaryQty - $this->getQty()) * 1 : $qty * 1;
                     if ($backorderQty > $qty) {
                         $backorderQty = $qty;
                     }
                     $result->setItemBackorders($backorderQty);
                 } else {
                     $orderedItems = $this->getOrderedItems();
                     $itemsLeft = $this->getQty() > $orderedItems ? ($this->getQty() - $orderedItems) * 1 : 0;
                     $backorderQty = $itemsLeft > 0 ? ($qty - $itemsLeft) * 1 : $qty * 1;
                     if ($backorderQty > 0) {
                         $result->setItemBackorders($backorderQty);
                     }
                     $this->setOrderedItems($orderedItems + $qty);
                 }
                 if ($this->_backorders == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) {
                     if (!$this->getIsChildItem()) {
                         $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', $backorderQty * 1));
                     } else {
                         $result->setMessage(Mage::helper('cataloginventory')->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), $backorderQty * 1));
                     }
                 } elseif (Mage::app()->getStore()->isAdmin()) {
                     $result->setMessage(Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()));
                 }
             }
         } else {
             if (!$this->getIsChildItem()) {
                 $this->setOrderedItems($qty + (int) $this->getOrderedItems());
             }
         }
     }
     return $result;
 }
Example #7
0
 function add_products_to_quote($params)
 {
     $errors = array();
     if (!isset($params['quote_id'])) {
         $this->_fault('data_invalid', 'Quotation ID missing');
     } else {
         $quoteId = $params['quote_id'];
         $_qquoteadv = Mage::getModel('qquoteadv/qqadvcustomer')->load($quoteId);
         if (!count($_qquoteadv->getData())) {
             $this->_fault('not_exists', 'Quotation ID (' . $quoteId . ') does not exist');
         }
     }
     if (!isset($params['products']) || !is_array($params['products']) || !count($params['products'])) {
         $this->_fault('data_invalid', 'Products missing');
     } else {
         //check that the proucts exist
         $productIds = $params['products'];
         foreach ($productIds as $productId) {
             $product = Mage::getModel('catalog/product')->load($productId);
             if (!$product->getData('entity_id')) {
                 $this->_fault('not_exists', 'Product ID (' . $productId . ') does not exist');
             }
         }
     }
     if (!count($errors)) {
         $hasOptions = FALSE;
         $options = FALSE;
         $storeId = $_qquoteadv->getStoreId();
         $modelProduct = Mage::getModel('qquoteadv/qqadvproduct');
         $qty = 1;
         foreach ($productIds as $productId) {
             $productsCollection = $modelProduct->getCollection()->addFieldToFilter('quote_id', $quoteId)->addFieldToFilter('product_id', $productId);
             $attribute = serialize(array('product' => $productId, 'qty' => $qty));
             // don't add if it has already been added
             if (!count($productsCollection)) {
                 $qproduct = array('quote_id' => $quoteId, 'product_id' => $productId, 'qty' => $qty, 'attribute' => $attribute, 'has_options' => $hasOptions, 'options' => $options, 'store_id' => $storeId);
                 $checkQty = $modelProduct->addProduct($qproduct);
                 if (is_null($checkQty)) {
                     // product has not been added redirect with error
                     $checkQty = new Varien_Object();
                     $checkQty->setHasError(true);
                     $checkQty->setMessage(Mage::helper('qquoteadv')->__('product can not be added to quote list'));
                 }
                 if ($checkQty->getHasError()) {
                     $this->_fault('save_error', $checkQty->getMessage());
                 } else {
                     $quoteadvProductId = $checkQty->getData('id');
                     $ownerPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty);
                     $originalPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty);
                     //#current currency price
                     $currencyCode = $_qquoteadv->getCurrency();
                     $ownerCurPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty, $currencyCode);
                     $originalCurPrice = Mage::helper('qquoteadv')->_applyPrice($quoteadvProductId, $qty, $currencyCode);
                     $item = array('quote_id' => $quoteId, 'product_id' => $productId, 'request_qty' => $qty, 'owner_base_price' => $ownerPrice, 'original_price' => $originalPrice, 'owner_cur_price' => $ownerCurPrice, 'original_cur_price' => $originalCurPrice, 'quoteadv_product_id' => $quoteadvProductId);
                     $requestitem = Mage::getModel('qquoteadv/requestitem')->setData($item);
                     $requestitem->save();
                 }
             }
         }
     }
     return array('success' => true);
 }