문제

I am trying to create functionality that allows backorders for a specific customer group only. I've searched the Magento code for something like if ($backorders_enabled){...} with no success/luck. I'm starting to think about checking each cart item quantity and and changing the value to it's inventory's value if the user is not logged and in the specific group.

Any idea what is the right way to enable backorders for a specific customer group ?

도움이 되었습니까?

해결책 2

The solution was overriding the method Mage_CatalogInventory_Model_Stock_Item::checkQty

    if ($this->getQty() - $this->getMinQty() - $qty < 0) {
        switch ($this->getBackorders()) {
            case Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NONOTIFY:
            case Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY:
//////////// new code
                $customer = Mage::getSingleton('customer/session')->getCustomer();
                if ($customer && $customer->getGroupId() == '2') { //if the customer is logged in an in the correct group then allow it
                    break;
                }
                else { //otherwise don't allow it
                    return false;
                }
                break;          }
    }
    return true;
`

다른 팁

I found a method that identifies an item on stock

app/code/core/Mage/CatalogInventory/Model/Stock/Item.php

class Mage_CatalogInventory_Model_Stock_Item

public function verifyStock($qty = null)
{
    if ($qty === null) {
        $qty = $this->getQty();
    }
    if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_NO && $qty <= $this->getMinQty()) {
        return false;
     }
    return true;
}

You can try to change it to the following:

/**
 * Chceck if item should be in stock or out of stock based on $qty param of existing item qty
 *
 * @param float|null $qty
 * @return bool true - item in stock | false - item out of stock
 */
public function verifyStock($qty = null)
{
    if ($qty === null) {
        $qty = $this->getQty();
    }


    if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_NO 
        && $qty <= $this->getMinQty()) {
        return false;
    }

    $backorderedCustomerGoupsIds = array(2, 3);    // move admin to config better
    if ($this->getBackorders() != Mage_CatalogInventory_Model_Stock::BACKORDERS_NO && 
        !in_array($this->getCustomerGroupId(), $backorderedCustomerGoupsIds)
        ) {
        return false;
    }

    return true;
}

Copy file app/code/core/Mage/CatalogInventory/Model/Stock/Item.php to app/code/local/Mage/CatalogInventory/Model/Stock/Item.php.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top