Javascript: Write input parameter in js function - magento

this here is part of our magento shop system code:
<label for="qty_<?php echo $_product->getId(); ?>"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/3/')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
I will add the functionality that I can add more products into the cart with on click. This works when I will add an parameter to this code: setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/3/'). My change is qty/3/
But this is static. Instead of the 3, I will put here the value of name="qty_<?php echo $_product->getId(); ?>".
I have no idea how this can work.

<!-- line breaks are for legibility, you can put on one line if you prefer -->
<button type="button"
title="<?php echo $this->__('Add to Cart') ?>"
class="button btn-cart"
onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/'
+ $F('qty_<?php echo $_product->getId() ?>'))">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>
I used the $F() shorthand to get the value of an element. It's only parameter is the name of an input, and that is the "qty_<?php echo $_product->getId() ?>" you knew you had to use somewhere.

Related

remove quantity box for specific product

Good morning I installed Magento ver. 1.9.2.1 and I need to delete the box quantity only on some products. I was thinking, for example, when max quantity is set to 1, instead for other products leave the box. Thank you, do you have any suggestions?
Nicola
I tried to modify the file addtochar.phtml but without success. I attach the code
?>getProduct(); ?> ('Add to Cart'); ?> isSaleable()): ?> isGrouped()): ?> __('Qty:') ?> getProductDefaultQty() * 1 ?>" title="quoteEscape($this->('Qty')) ?>" class="input-text qty" /> " id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"> getChildHtml('', true, true) ?> showButtonDesign(); ?>
I hope this code will help you.
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<?php $hiddenFlag = in_array($_product->getId(), array(10,20,30,40)) ? true : false; ?>
<?php if (!$hiddenFlag): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<?php endif;?>
<input type="<?php echo $hiddenFlag ? 'hidden' : 'text' ?>" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
Please pay attention to this line: <?php $hiddenFlag = in_array($_product->getId(), array(10,20,30,40)) ? true : false; ?> it will check if product eligible for a qty visibility.

how to add new fieds and use existing address fields in magento custom regstration form

hi i am new to magento.. i need some help..
i am able to add address fields in form in my view(phtml file) but that fields data is not being
saved . how could i be able to save those fields?
code for address field in phtml file
<div class="form-group margin_top">
<label for="street_1" class="required col-md-4 control-label"><?php echo $this->__('Adresse') ?><em>* :</em></label>
<div class="col-md-6">
<div class="row">
<div class="col-md-3 nopaddingright">
<?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text form-control <?php echo $_streetValidationClass ?>" />
</div>
<div class="col-md-9 address_block">
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="form-control input-text <?php echo $_streetValidationClass ?>" />
<?php endfor; ?>
</div>
<div class="col-md-9 nopaddingright">
<input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="form-control input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
</div>
<div class="col-md-3 address_block">
<input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text form-control validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
</div>
<div class="col-md-12">
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text form-control <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" />
</div>
</div>
</div>
2 . i also need mobile(cell) field to be added into my form how can i add that and save into my
database.
do i need to create Custom module ? please suggest me and help me
Thank you

When viewing products in the category view, I would like to be able to have a “Quantity” box

In MAGENTO,When viewing products in the category view, I would like to be able to have a “Quantity” box that allows the user to enter the quantity needed before clicking the “Add to Cart” button. How can I show this?
In List.phtml file find the below line
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
and replace it with
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>

Magento middle name required

How to make middle name required in magento customer entity?
There is option in System->Configuration->Customer configuration, but it's optional.
To make your Middle Name field Required open the following file:
/app/design/frontend/default/[YOURTHEME]/template/customer/widget/name.phtml
or if it doesn't exist there, open:
/app/design/frontend/base/default/template/customer/widget/name.phtml
Look for the following code:
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text" <?php echo $this->getFieldParams() ?> />
Where it says class="input-text" make it say class="input-text required-entry"
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text required-entry" <?php echo $this->getFieldParams() ?> />
It's toward the end of the line. Look at the other code in the file as well-- they all have the same class.

Magento - Add to cart with quantity field on Upsell products

I'm trying to get my Upsell products, which I use instead of related products on the view.phtml, to work with a Quantity field in front of the Add to cart button. I'am also using AheadWorks Ajax AddToCart Pro 2.5 extension.
Right now, I'am adding the products without quantity fields with this snippet:
<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form>
This works great, but I cannot change the quantity due to the lacking quantity field. Then I try to use this from my list.phtml which works fine, in the category view:
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
Now, the funny thing is, this does not work if I try to use it in upsell.phtml, but I cannot figure out why? This works perfect with Ajax Cart Pro from AW in the Category view's.
In upsell.phtml the product object is called $_link per the following code:
<?php if($_link=$this->getIterableItem()): ?>
If you're trying to include your code in your upsell.phtml then you'll have to change $_product to $_link like this:
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_link->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
It should go after the following line:
<?php if($_link=$this->getIterableItem()): ?>

Resources