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

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

Related

Add new field in bundle item option in admin section

I am new bie in magento.I am creating a bundle product from admin section .when I add the bundle item there is only the title field for information but I need to add one more field for the description like I created a bundle item for computers but I need to show description about it .
Please help .my requirement is to add new field for description along with the title in bundle item option.
any help will be appreciated .
you can add extra field to magento bundle products by editing app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml and few database changes.
EDIT:
first we have to add our custom field to catalog_product_option_type_value table in the database, using a instraller script
<?php
/* #var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->getConnection()
->addColumn($installer->getTable('catalog/product_option_type_value'), 'your_custom_field_name’, 'VARCHAR(128) NULL');
$installer->endSetup();
then copy the file in location app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml
to app\design\adminhtml\default\default\template\companyname\catalog\product\edit\options\type\select.phtml. override the core file
Rewrite: ‘Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select’ block and replace constructor file in it by indicating our phtml file
public function __construct()
{
parent::__construct();
$this->setTemplate('companyname/catalog/product/edit/options/type/select.phtml');
$this->setCanEditPrice(true);
$this->setCanReadPrice(true);
}
open companyname/catalog/product/edit/options/type/select.phtml ile in OptionTemplateSelect varilable in tag we add the line: under 'sort order' field
'<th class="type-title"><?php echo Mage::helper('catalog')->__('your_custom_field_name') ?></th>'+
Add OptionTemplateSelectRow tag to the variable:
'<td><input type="text" class="input-text select-type-details" id="product_option_{{id}}_select_{{select_id}}_title" name="product[options][{{id}}][values][{{select_id}}][your_custom_field_name]" value="{{your_custom_field_name}}">{{checkboxScopeTitle}}</td>'+
now check in backend you should see the custom field by now. to make it required you can add required-entry class to above input field
now for retrieve values from database re-write the block:
Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option
In: 'getOptionValues()' method, cycle: foreach ($option->getValues() as $_value) {
add new key: 'your_custom_field_name' to the variable: $value and the value for it: $_value->getYourCustomField();
now custom field will appear in database
In order for the new attribute to appear on the frontend rewrite the class: Mage_Catalog_Block_Product_View_Options_Type_Select and add the newly added attribute to it. But be aware that depending on the type of Custom Options there different kinds of htmls generate.
please refer this article for more details

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

Joomla - Custom Field doesn't show-up on Edit/Update

I've followed this Tutorial to add a custom field to the article content type and I was successful to make a new one with adding the following code:
In File : root/administrator/components/com_content/models/forms/article.xml
Code :
<field name="newText" type="editor" class="inputbox"
label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL"
description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"
filter="ContentHelper::filterText" buttons="true" />
In File : root/administrator/components/com_content/views/article/tmpl/edit.php
Code :
//Our new textbox
<div class="clr"></div>
<label>Article Text - New Text</label>
<div class="clr"></div>
<?php echo $this->form->getInput('newText'); ?>
and altered Database to add a new column for that new field.
ALTER TABLE 'j_content' ADD 'newText' VARCHAR( 255 ) NOT NULL;
On Article posting the data is successfully getting stored in Database.
The new custom field is visible when I'm posting a brand new article. But when I'm editing/updating the same new post, that newly added field is missing.
Is there a way to get this field even when we are editing the post/article.
Please, never overwrite core files or change the core database! This is not a good tutorial because it is not update-safe.
If you need additional fields for your content items, use a special core extension for this instead.
I recommend this one:
http://fieldsattach.com/. This method is update-safe.

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