0

i have a problem with the configuration of the stock, im explain: I need limit the product max qty per customer, the shop need sells certain qty of products per customer, this shop have 40 customers and need distribute the general stock to each customer, how i can do it?, i hope can help me guys! thanks for ur time! have a great day!

2
  • So each client is only allowed to purchase 1/40th of the stock? And these clients are logged in I presume? Commented Nov 29, 2014 at 19:01
  • Yes thats right Sander!, and yes all clients log in. Commented Nov 29, 2014 at 19:30

2 Answers 2

4

To restrict the qty use the setting Maximum Qty Allowed in Shopping Cart to 1

enter image description here

If you want to additionally check for previous orders of this item and prevent them being added to the cart you could solve this similar to my answer here https://magento.stackexchange.com/a/9606/9

And then in your observer class

<?php

class Fooman_Example_Model_Observer
{
    public function catalogProductTypePrepare($observer)
    {
        $customerId = Mage::getSingleton('customer/session')->getCustomerId();
        $product = $observer->getEvent()->getProduct();
        //Add code here to look up previous orders
        if($orderedBefore){
            Mage::throwException('You can only buy this product once.');
        }
    }
}
1
  • Thanks for u help, but i need do it with each customer, you post a different solution than i need, i need make the same but not in shopping cart, if not for each customer. i need restrict limit of products bought per costumer, if i have 100 articles on stock spread 10 articles per customer of total of the stock, you got it? Commented Nov 30, 2014 at 1:45
0

tried this module as base for developing a module ?

http://www.magentocommerce.com/magento-connect/max-sales-qty-by-stock.html

the module limits the max saled qty per customer to xx% of current stock.

appendum

If you need this feature per customer, you could add custom customer attribute:

/app/code/local/Your/Customattribute/sql/your_customattribute_setup/install-0.1.0.php

<?php
$installer = $this;

$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute("customer", "customattribute",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Custom Attribute",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => "Custom Attribute"

        ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "customattribute");


$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'customattribute',
    '999'  //sort_order
);

$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
//$used_in_forms[]="checkout_register";
//$used_in_forms[]="customer_account_create";
//$used_in_forms[]="customer_account_edit";
//$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
                ->setData("is_used_for_customer_segment", true)
                ->setData("is_system", 0)
                ->setData("is_user_defined", 1)
                ->setData("is_visible", 1)
                ->setData("sort_order", 100)
                ;
        $attribute->save();



$installer->endSetup();

/app/code/local/Your/Customattribute/etc/config.xml

 <?xml version="1.0"?>
<config>
    <modules>
        <Tom_PercentStock>
            <version>0.1.0</version>
        </Tom_PercentStock>
    </modules>
    <global>
        <models>
            <cataloginventory>
                <rewrite>
                    <stock_item>Tom_PercentStock_Model_Item</stock_item>
                </rewrite>
            </cataloginventory>
            <percentstock>
                <class>Tom_PercentStock_Model</class>
            </percentstock>   
        </models>
        <helpers>
            <percentstock>
                <class>Tom_PercentStock_Helper</class>
            </percentstock>
        </helpers>
        <resources>
            <Your_Customattribute_setup>
                <setup>
                    <module>Your_Customattribute</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </Your_Customattribute_setup>
            <Your_Customattribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </Your_Customattribute_write>
            <Your_Customattribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </Your_Customattribute_read>
        </resources>
    </global>
    <adminhtml>
        <translate>
            <modules>
                <Tom_PercentStock>
                    <files>
                        <default>Tom_PercentStock.csv</default>
                    </files>
                </Tom_PercentStock>
            </modules>
        </translate>
    </adminhtml>
</config>

and edit app\code\community\Tom\PercentStock\Model\Item.php

/**
 * Retrieve Maximum Qty Allowed in Shopping Cart data wraper
 *
 * @return float
 */
public function getMaxSaleQty() {
    if($this -> getUseConfigMaxSaleQty()) {
        $customerSession = MAge::getSingleton('customer/session');
        if(Mage::getStoreConfig(self::XML_PATH_ENABLE_PERCENT && $customerSession->isLoggedIn())) {
            $customer = $customerSession->getCustomer();

            return (float) $customer->getCustomattribute();
        }
        return (float)Mage::getStoreConfig(self::XML_PATH_MAX_SALE_QTY);
    }
    return (float)$this -> getData('max_sale_qty');
}

In this case the value you entered in the custom attribute is returned as maximum amount of sold items per customer.

7
  • I see this module but in the overview only appears it: " This Module allows you to dynamically change the maximum Qty Allowed in Shopping Cart by percent of current Stock". It only modify the shopping cart rules, not work for each customer to define some stock. Commented Nov 30, 2014 at 1:39
  • I have installed that plugin but it not show the same rules if it show on magentoconect review, why?, can help me please thanks! Commented Nov 30, 2014 at 13:30
  • could you provide a Screenshot or a list of Options you can see in backend?
    – tomtone
    Commented Nov 30, 2014 at 13:41
  • And can help me to explain how configure the steps of you show me on your post?, im not have much experience to create modules. Thanks again for u help! Commented Nov 30, 2014 at 13:42
  • Here the screenshot! oi57.tinypic.com/2mcc6r7.jpg Commented Nov 30, 2014 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.