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

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’));

Related

Forms fields filtering issue in Magento 1.8.1.0

In account form fields or user registration page form fields for First name and Last name, when i place the following JS code :
<script>alert("Here")</script>
It is saved and is run on page load. This is very strange, because i checked the template files and values are escaped as below:
<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>
I have also confirmed if i am in correct template file by changing the label of field.
I have read the following questions and tried to used them but did not worked for me.
https://magento.stackexchange.com/questions/569/how-to-escape-output-data
https://magento.stackexchange.com/questions/8179/is-there-a-generic-way-i-can-apply-input-filtering-to-magento-form-processing
Regarding to the observer method, it works, but when i try to login to magento admin, i cant, but when iremove the observer, i can login again.
Check the two attached screenshots.
Kindly help me with this issue.
Thank you
I have created an observer. For login forms at admin and front end (and may be some other forms), the form fields for user name and password are in array format like below:
<input type="text" id="username" name="login[username]" value="" class="required-entry input-text">
<input type="password" id="login" name="login[password]" class="required-entry input-text" value="">
TO fix this issue, i have modified the code in observer as below:
public function sanitizeParams($observer)
{
if(!Mage::app()->getStore()->isAdmin())
{
$post = Mage::app()->getRequest()->getParams();
foreach($post as $pkey => $pvalue)
{
if(is_array($post[$pkey]))
{
foreach($post[$pkey] as $key => $value)
{
$post[$pkey][$key] = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
else
{
$post[$pkey] = filter_var($pvalue, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
$_POST = $post;
}
}
And it fixed my problem, and is working fine now.
Thanks.

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

Related category/subcategory dropdowns in magento custom module

I have created custom module for magento admin.There is a form that have 2 drop-downs(one for category and second for its subcategory).How can I relate theme.I want all sub categories in second drop-down on change of first dropdown(state,city like).How can I do this in magento using jquery/ajax.
here i am giving idea to how to get sub category list from ajax call. you should have to try with your self to call ajax on the change event of main category list and get from below code to generate sub category list.
<select id="category" class="myinput-text required-entry widthinput" name="category">
<?php
$parentid=5; // parent id which you want sub category
$categories=explode(',',Mage::getModel('catalog/category')->load($parentid)->getChildren());
foreach($categories as $cat){
$category=Mage::getModel('catalog/category')->load($cat);
?>
<option value="<?php echo $category->getId();?>"><?php echo $category->getName();?></option>
<?php } ?>
</select>
hope it will sure help you.

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

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.

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