| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/awebpaca/boutiques/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/ |
Upload File : |
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_CatalogInventory
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* CatalogInventory Stock Status per website Resource Model
*
* @category Mage
* @package Mage_CatalogInventory
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_CatalogInventory_Model_Mysql4_Stock_Status extends Mage_Core_Model_Mysql4_Abstract
{
/**
* Resource model initialization
*
*/
protected function _construct()
{
$this->_init('cataloginventory/stock_status', 'product_id');
}
/**
* Save Product Status per website
*
* @param Mage_CatalogInventory_Model_Stock_Status $object
* @param int $productId
* @param int $status
* @param float $qty
* @param int $stockId
* @param int|null $websiteId
* @return Mage_CatalogInventory_Model_Mysql4_Stock_Status
*/
public function saveProductStatus(Mage_CatalogInventory_Model_Stock_Status $object,
$productId, $status, $qty = 0, $stockId = 1, $websiteId = null)
{
$websites = array_keys($object->getWebsites($websiteId));
foreach ($websites as $websiteId) {
$select = $this->_getWriteAdapter()->select()
->from($this->getMainTable())
->where('product_id=?', $productId)
->where('website_id=?', $websiteId)
->where('stock_id=?', $stockId);
if ($row = $this->_getWriteAdapter()->fetchRow($select)) {
$bind = array(
'qty' => $qty,
'stock_status' => $status
);
$where = array(
$this->_getWriteAdapter()->quoteInto('product_id=?', $row['product_id']),
$this->_getWriteAdapter()->quoteInto('website_id=?', $row['website_id']),
$this->_getWriteAdapter()->quoteInto('stock_id=?', $row['stock_id']),
);
$this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where);
}
else {
$bind = array(
'product_id' => $productId,
'website_id' => $websiteId,
'stock_id' => $stockId,
'qty' => $qty,
'stock_status' => $status
);
$this->_getWriteAdapter()->insert($this->getMainTable(), $bind);
}
}
return $this;
}
/**
* Retrieve product status
* Return array as key product id, value - stock status
*
* @param int|array $productIds
* @param int $websiteId
* @param int $stockId
*
* @return array
*/
public function getProductStatus($productIds, $websiteId, $stockId = 1)
{
if (!is_array($productIds)) {
$productIds = array($productIds);
}
$select = $this->_getReadAdapter()->select()
->from($this->getMainTable(), array('product_id', 'stock_status'))
->where('product_id IN(?)', $productIds)
->where('stock_id=?', $stockId)
->where('website_id=?', $websiteId);
return $this->_getReadAdapter()->fetchPairs($select);
}
/**
* Retrieve product(s) data array
*
* @param int|array $productIds
* @param int $websiteId
* @param int $stockId
*
* @return array
*/
public function getProductData($productIds, $websiteId, $stockId = 1)
{
if (!is_array($productIds)) {
$productIds = array($productIds);
}
$data = array();
$select = $this->_getReadAdapter()->select()
->from($this->getMainTable())
->where('product_id IN(?)', $productIds)
->where('stock_id=?', $stockId)
->where('website_id=?', $websiteId);
$query = $this->_getReadAdapter()->query($select);
while ($row = $query->fetch()) {
$data[$row['product_id']] = $row;
}
return $data;
}
/**
* Retrieve websites and default stores
* Return array as key website_id, value store_id
*
* @return array
*/
public function getWebsiteStores() {
$select = Mage::getModel('core/website')->getDefaultStoresSelect(false);
return $this->_getReadAdapter()->fetchPairs($select);
}
/**
* Retrieve Product Type
*
* @param array|int $productIds
* @return array
*/
public function getProductsType($productIds)
{
if (!is_array($productIds)) {
$productIds = array($productIds);
}
$select = $this->_getReadAdapter()->select()
->from(
array('e' => $this->getTable('catalog/product')),
array('entity_id', 'type_id'))
->where('entity_id IN(?)', $productIds);
return $this->_getReadAdapter()->fetchPairs($select);
}
/**
* Retrieve Product part Collection array
* Return array as key product id, value product type
*
* @param int $lastEntityId
* @param int $limit
* @return array
*/
public function getProductCollection($lastEntityId = 0, $limit = 1000) {
$select = $this->_getReadAdapter()->select()
->from(
array('e' => $this->getTable('catalog/product')),
array('entity_id', 'type_id'))
->order('entity_id ASC')
->where('entity_id>?', $lastEntityId)
->limit($limit);
return $this->_getReadAdapter()->fetchPairs($select);
}
/**
* Add stock status to prepare index select
*
* @param Varien_Db_Select $select
* @param Mage_Core_Model_Website $website
* @return Mage_CatalogInventory_Model_Mysql4_Stock_Status
*/
public function addStockStatusToSelect(Varien_Db_Select $select, Mage_Core_Model_Website $website)
{
$websiteId = $website->getId();
$select->joinLeft(
array('stock_status' => $this->getMainTable()),
'e.entity_id=stock_status.product_id AND stock_status.website_id='.$websiteId,
array('salable' => 'stock_status.stock_status')
);
return $this;
}
/**
* Add stock status limitation to catalog product price index select object
*
* @param Varien_Db_Select $select
* @param string|Zend_Db_Expr $entityField
* @param string|Zend_Db_Expr $websiteField
* @return Mage_CatalogInventory_Model_Mysql4_Stock_Status
*/
public function prepareCatalogProductIndexSelect(Varien_Db_Select $select, $entityField, $websiteField)
{
$select->join(
array('ciss' => $this->getMainTable()),
"ciss.product_id = {$entityField} AND ciss.website_id = {$websiteField}",
array()
);
$select->where('ciss.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
return $this;
}
/**
* Add only is in stock products filter to product collection
*
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @return Mage_CatalogInventory_Model_Stock_Status
*/
public function addIsInStockFilterToCollection($collection)
{
$websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
$collection->getSelect()
->join(
array('stock_status_index' => $this->getMainTable()),
'e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = ' . $websiteId
. ' AND stock_status_index.stock_id = ' . Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID,
array())
->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
return $this;
}
}