Magento: Limit Product Max Quantity Per Customer (NOT per Order) - magento

I know we can easily limit the max quantity of a given product a customer can purchase per order, but is it possible (natively or even with a plugin) to limit max quantity of a given product per CUSTOMER ??
I don't want to use a coupon nor modify the code: it needs to be a sale price with the help of native or extension functionality.
Magento 1.5.1

It is not possible native, but you can make a module that will perform such restrictions.
You need to create a resource model, that will retrieve not canceled and not refunded orders for product(s) with particular product id. Actually it just a simple select to sales/order and sales/order_item table. Method of resource model might look like the following:
public function getPurchasedProductQty(array $productIds, $customerId)
{
$select = $this->_getReadAdapter()->select();
$select
->from(array('order_item' => $this->getTable('sales/order_item')),
array(
'qty' => new Zend_Db_Expr('order_item.ordered_qty - order_item.canceled_qty - order_item.refunded_qty'),
'product_id'))
// Joining order to retrieve info about item and filter out canceled or refunded orders
->join(array('order' => $this->getTable('sales/order')),
'order.entity_id = order_item.order_id',
array())
// Limit it to the current customer
->where('order.customer_id = ?', $customerId)
// Filter out refunded and canceled orders
->where('order.state NOT IN(?)', array(
Mage_Sales_Model_Order::STATE_CLOSED,
Mage_Sales_Model_Order::STATE_CANCELED
))
// Add Product Id Condition
->where('order_item.product_id IN(?)', $productIds);
return $this->_getReadAdapter()->fetchCol($select);
}
Then when you observe sales_quote_item_collection_products_after_load event you just can place your custom logic with checking the restrictions on products that are going to be used in the cart and remove that ones from loaded collection. This logic you should implement yourself.

Assuming that you are trying limit the product qty a registered customer who is currently log in can add to their cart.
(This is a one to one relationship, but could easily modify to accomodate many different products and qty per customer)
Create a custom module that will add a field in customer entity, so admin can set the appropriate qty for each customer.
Field name: [ModuleName]_product_id (see Adding attributes to customer entity)
Field name: [ModuleName]_max_cart_qty (see Adding attributes to customer entity)
In (copy files below to your local template folder) and update the qty input field.
/app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml
/app/design/frontend/base/default/template/checkout/cart/item/default.phtml
Change
<input type="text" class="input-text qty" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" />
to (Add a validation class to make sure the qty is less than or equal )
$addValidationClass = '';
if( Customer is login && ModuleName_product_id == $_product->getId() && [ModuleName]_max_cart_qty > 0){
$addValidationClass = ' validate-digits-range-1-' . [ModuleName]_max_cart_qty
}
<input type="text" class="input-text qty<?php echo $addValidationClass; ?>" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" />
If you want to do server-side validation then create a observer for add to cart event, that compare the above logic to the item currently been add to cart

Below Extension Will Be help to achieve this
https://www.magentocommerce.com/magento-connect/maximum-order-quantity.html
Edit
In this Extension give
Quite often store owners need to restrict the order product quantity with custom message at cart page. This is not possible while using the default admin settings. However, by using this extension you can set the limit for product quantity with custom error message. If maximum quantity limit exceeds the limit then error message will be shown at cart page.
You can set the maximum quantity for each product with custom error message. You can enable/disable globally them using the backend options.

Related

How to add 'Company Name' in customer register and billing info

I've been trying to add 'company name' on customer register and onepage checkout but unsuccessfully so far. I tried https://magento.stackexchange.com/questions/15847/add-company-name-to-billing-shipping-dropdown-in-magento but it didn't help at all.
I can't believe there isn't a simple way of doing that.
The company field is already part of the address entity in Magento, if it isn't showing on register and checkout forms you'll need to update the templates to include it.
I recommend that you look in either the base/default or rwd/default theme and look at:
checkout/onepage/shipping.phtml
persistent/customer/form/register.phtml
persistent/checkout/onepage/billing.phtml
You should see company in there and can copy that into your active theme.
Hope that helps!
Adding a new field to Magento new customer registration can be done in 4 simple steps. Follow the steps given below to get done with it.
Step 1: We have to add php and .html form elements that are necessary to create new input boxes for each additional field in register.phtml.
<div class="input-box">
<label for=”company_name”><?php echo $this->__('Company Name') ?></label><br/>
<input type="text" name="company_name" id="company_name" value="<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company Name') ?>" class="input-text" />
</div>
Step 2: We need to add elements under “getDefaultEntities()” in Setup.php (path: /app/code/core/Mage/Customer/Model/Entity/), one for each additional field created above:
company_name' => array(
'label' => 'Company Name',
'required' => false,
'sort_order' => 64,
),
Step 3: Add to the content of $customer in AccountController.php (path: /app/code/core/Mage/Customer/controllers/) by grabbing the new fields from posted info, in the createPostAction() function:
$customer = Mage::getModel('customer/customer')->
setCompany($this->getRequest()->getPost('company_name'));
Step 4: Finally, we will need to add database records to table eav_attribute, corresponding to the newly created fields. The idea is to add to the associated data model, where newly defined model data is entered as the “attribute_code”, with the corresponding entity_type_id (which for this data happens to be ‘1’).
Using your favourite SQL editor (i.e. phpMySQL or sqlYog — highly recommended), execute the following SQL statement for each field created above (replacing ‘company’ and ‘Company Name’ with the respective field name information as required):
INSERT INTO eav_attribute (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, is_global,is_visible, is_required, is_configurable, is_filterable_in_search) VALUES(’1′, ‘company’, ‘varchar’, ‘text’, ‘Company Name’, ’1′, ’1′, ’0′, ’1′, ’1′);

adding a different customer example:seller through a different regestration page

I am using magento 1.9. I want to add a customer group as seller from the front end using a different registration form keeping the registration form for registration of general category separate.
Add in your registration the following field,
<?php
$groups = Mage::helper('customer')->getGroups()->toOptionArray();
foreach ($groups as $group){
echo '<input type="radio" name="group_id" value="'.$group['value'].'" class="validate-radio" >'.$group['label'].'</input><br/>';
}
?>
And save the fields as following in your controller file.
$customer->setGroupId($this->getRequest()->getPost(‘group_id’));

Magento: Inventory increment qty attribute per store

I have one simple question.
My problem is:
Is there are any free extensions that could turn "Enable Qty Increments" and "Qty Increments" from global scope to store view?
Also I have found this question inventory settings
It's have some kind of answer, but I need to confirm this.
If there are no free extension that could fulfill my needs, do I need to write my own extension (as answer in previous link says) or there is an easy way to change scope from global to store view. ?
My Magento version is CE 1.9.1.0
What you could do to achieve the same thing is create a new product text attribute called pack_size, give it a per store view scope, then set the order quantity against it per product, per store view.
Then, in your addtocart.phtml file, here;
app/design/frontend/XXX/YYY/template/catalog/product/view/addtocart.phtml
Where XXX YYY is the name of your theme, and replace the quantity input box with;
<?php $pack = $_product->getData('pack_size'); ?>
<?php if(($pack == 1) || (!$pack)) { ?>
<input type="text" name="qty" id="qty" maxlength="4" value="1" />
<?php } else { ?>
<select name="qty" id="qty" maxlength="12">
<?php
$countme = 1;
while ($countme < 101) {
echo '<option value="'.($pack*$countme).'">'.($pack*$countme).'</option>';
$countme++; } ?>
</select>
Now if the value of pack_offer is set and greater than 1, the user will only be able to choose a multiple of that qty.
Depending on your theme, you may also need to implement this in the cart page.

Magento - add product to cart with fixed quantity

I'm adding a product programmatically in an action to the cart.
Is it possible to set a fixed quantity in this step, which the user can't change afterwards?
You cannot set a fixed quantity that can't be manipulated by the user in some way or another, however you can mask it from the users view.
There are two ways to achieve this, first option is the non coding way around it but won't be as user friendly as the second:
First option:
Goto products backend -> Inventory and set 'Maximum Qty Allowed in Shopping Cart' to the fixed quantity. You can use the above answer to set the fixed quantity.
Second option:
If not, then you can modify the default.phtml (cart item render) to prevent the quantity adjustment field being rendered. You could use anything here to define the product, you could attach some custom options to identify the product.
Your looking for the line with the following:
<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
Wrap it in an if else statement to differentiate the product you are adding programatically (you could use for example, Sku, product ID or a custom option). Instead of rendering the input field, just render a static 1 instead with no option to modify the quantity.
You could also add an option to the quote item and then pull via getOptionByCode() for the differentiation.
Doing both options would be a complete solution to your problem.
Yes.
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
$cart = $this->_getCart();
$params = $this->getRequest()->getParams();
try {
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
As you can see, in your CartController you have add action.
The code above shows that this controller expects a param called "qty", that you can use.
I'm using magento1.8

Magento: How to Add Order / Payment information to Admin-BackEnd

I´ve been able to add a custom field called Bank Name to the credit card payment option which saves into the DB, however I am now trying to display such information on the back-end under Customer > Manage Customer > (Select an customer) > Orders > (Select an Order) and there´s a field called Payment Information which displays the credit card payment info and this is where I want the Bank Name to appear.
I have already tried to edit the following files with no success.
app\design\adminhtml\default\default\template\payment\form\cc.phtml and ccsave.phtml by adding the following.
<div class="input-box">
<label for="<?php echo $_code ?>_cc_bankname><?php echo Mage::helper('payment')->__('Bank Name') ?> <span class="required">*</span></label><br/>
<input type="text" id="<?php echo $_code ?>_cc_bankname" name="payment[cc_bankname]" title="<?php echo Mage::helper('payment')->__('Bank Name') ?>" class="input-text validate-cc-number" value="<?php echo $this->getInfoData('cc_bankname')?>"/>
</div>
but this only enables the option to edit the attribute when manually creating a new order for the customer.
Does anyone know which file should be edited and how? I´ve tried to edit the cc.phtml and ccsave.phtml files under add/design/adminhtml and also under mage but no luck.
Forgot to mention I´m working with Magento 1.7
::::::::::::::::EDIT::::::::::::::::
After further search thru the payment files, I found that there are two files that need to be edited but I still need some help.
I adited \app\code\local\Mage\Payment\Block\Info\cc.phtml by adding two functions to the file.
First a public function
public function getCcBankname()
{
return $this->getInfo()->getCcBankname();
}
Then a protected function
if ($this->getInfo()->getCcBankname()) {
$data[Mage::helper('payment')->__('Bank Name')] = $this->getInfo()->getCcBankname();
}
Then I edited the following file \app\code\local\Mage\Payment\Block\Info\ccsave.phtml by adding this.
$transport = new Varien_Object(array(Mage::helper('payment')->__('Bank Name') => $info->getCcBankname(),));
Now this modifications allowed for the Bank Name to appear on the Backend exactly where I wanted it BUT the problem is that it not populating the data that´s store on the DB.
Anyone knows why it´s not pulling the data from the DB?
:::::::::::::::: EDIT #2 ::::::::::::::::
Well it seems that everything I did worked but there was just one little problem. The bank name data should be set on two different Tables. sales_flat_order_payment and sales_flat_quote_payment but for some reason the data is only saving on sales_flat_quote_payment. I manually entered the data on sales_flat_order_payment and it worked, I was able to visualize the Bank Name on the backend.
Now I have to figure out how to get the data to save on sales_flat_order_payment whenever a payment is processed and why it´s being saved on sales_flat_quote_payment but not on the other.
For the payment method ccsave, the "Payment Information" section of
Customer > Manage Customer > (Select customer) > Orders > (Select Order)
is usually created by the template
app/design/adminhtml/default/default/template/payment/info/default.phtml

Resources