SHARE
TWEET

Untitled

a guest Nov 20th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Efarma_CatalogInventory_Helper_StockManagement extends Mage_Core_Helper_Abstract
  4. {
  5.     public function getFinalQty($product)
  6.     {
  7.         $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
  8.  
  9.         $prodQty = (float)$stockItem->getQty();
  10.         $prodMaxSaleQty = (float)$stockItem->getMaxSaleQty();
  11.  
  12.         $finalQty = $stockItem->checkQty($prodQty);
  13.  
  14.         $maxFinalQty = is_bool($finalQty) ? $prodQty : $finalQty ;
  15.         $maxQty = ($prodMaxSaleQty < $maxFinalQty) ? $prodMaxSaleQty : $maxFinalQty;
  16.  
  17.         // Gestione dei deal
  18.         $helper = Mage::helper('dailydeal');
  19.         $deal = $helper->getDealByProduct($product);
  20.         if ($deal) {
  21.             $maxDealQty = (float)$deal->getDealQty();
  22.  
  23.             if ($maxQty > $maxDealQty) {
  24.                 $maxQty = $maxDealQty;
  25.             }
  26.         }
  27.  
  28.         return $maxQty;
  29.     }
  30.  
  31.     public function getFinalQtyByProductId($productId)
  32.     {
  33.         $product = Mage::getModel('catalog/product')->load($productId);
  34.         return $this->getFinalQty($product);
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top