Friday 9 December 2016

Star pattern programs with for loop in php


Star pattern programs with for loop in php

Script for following pattern

*
**
***
****
*****
******
*******
********

<?php
for($i=1;$i<=8;$i++){
echo str_repeat('*',$i);
echo "<br/>";
}

OR

for($i=1;$i<=8;$i++){

   for($j=1;$j<$i;$j++){
echo '*';
   }
   echo '<br/>';
}

?>


Script for following pattern

****
****
****
****
****
****

<?php
for ($i=1;$i<=6;$i++){
for($j=1;$j<5;$j++){
echo '*';
}
echo '<br/>';
}
?>


Script for following pattern

*****
****
***
**
*

<?php
for($i=6;$i>0;$i--){
for($j=1;$j<$i;$j++){
echo '*';
}
echo '<br/>';
}
?>

Script for Triangle of Stars in PHP

        *
       **
      ***
     ****
    *****
   ******

<?php
$l = 1;
for($i=8;$i>1;$i--){

for($j=1;$j<$i;$j++){
echo '&nbsp;';
}


for($k=1;$k<$l;$k++){
echo '*';
}
$l++;
echo '<br/>';

}

OR

$l = 1;
for($i=8;$i>1;$i--){

echo str_repeat('&nbsp;',$i);
echo str_repeat('*',$l++);
echo '<br/>';
}

?>

Wednesday 30 November 2016

How to enable paypal payment standard in magento 1.9.2.1


How to enable paypal payment standard in magento 1.9.2.1

In magento 1.9.2.1 Paypal Payment Standard method not exist. If you want use paypal, you have to select Website Payments Standard (Includes Express Checkout). Here i have used small trick to reuse the old method.

Run the following query in your database and check in admin panel in payment method section

update core_config_data set value = '1' where path = 'payment/paypal_standard/active';

Monday 14 November 2016

Radio button validation in javascript check or uncheck


Radio button validation in javascript check or uncheck

<form action="" method="post" name="register_form" id="register_form" enctype="multipart/form-data">

    <div class="text-input">
        <label>Gender: </label>
        <input class="form-control" type="radio" name="gender" id="male" value="male" />
        <label for="male">Male</label>
        <input class="form-control" type="radio" name="gender" id="female" value="female" />
        <label for="female">Female</label>
    </div>
    <div class="text-input" align="center">
        <input type="submit" name="register" value="Submit" onclick="return radioValidation();" />
    </div>

</form>

<script type="text/javascript">
function radioValidation(){

var gender = document.getElementsByName('gender');
var genValue = false;

for(var i=0; i<gender.length;i++){
if(gender[i].checked == true){
genValue = true;
}
}
if(!genValue){
alert("Please Choose the gender");
return false;
}

}
</script>

Wednesday 9 November 2016

PayPal gateway has rejected request. Currency is not supported paypal Express error magento



PayPal gateway has rejected request. Currency is not supported paypal Express error magento

Generally People face this type error becoz of Paypal does not support requested currency. For Example : If you are trying to checkout with Indian Rupee , You would get this type of error due to paypal does not support Indian Rupee. In this condition you have to switch the your base currency to paypal supported currency. But with this solution your store price will be changed. so that here i came with small hack.

I have used small trick to rid this error. It is not good solution but sometime it is useful.

Go to app\code\core\Mage\Paypal\Model\Express\Checkout.php. Find the public function start and find below code

$this->_api->setAmount($this->_quote->getBaseGrandTotal())
            ->setCurrencyCode($this->_quote->getBaseCurrencyCode())
            ->setInvNum($this->_quote->getReservedOrderId())
            ->setReturnUrl($returnUrl)
            ->setCancelUrl($cancelUrl)
            ->setSolutionType($solutionType)
            ->setPaymentAction($this->_config->paymentAction);

Just replace the below code

$this->_api->setAmount($this->_quote->getBaseGrandTotal())
            ->setCurrencyCode('USD')
            ->setInvNum($this->_quote->getReservedOrderId())
            ->setReturnUrl($returnUrl)
            ->setCancelUrl($cancelUrl)
            ->setSolutionType($solutionType)
            ->setPaymentAction($this->_config->paymentAction);

With this trick now you will go to paypal without any error. But you have to convert the price from Base Currency to USD.

Note: This solution is only for Paypal Express Users.

That's it. Enjoy Chandresh Rana's Coding...

How to make custom mini shopping cart in header magento

How to make custom mini shopping cart in header magento

Kindly Copy the below code and paste it into your header.phtml file.

<div class="shopping_cart active">
<?php $cart = Mage::getModel('checkout/cart')->getQuote(); ?>
    <?php $cnt = Mage::helper('checkout/cart')->getSummaryCount(); ?>
    <div class="icon">
        <i class="shopping-bag-icon v-middle"></i>
        <span class="count-number"><?php if($cnt > 0){echo $cnt;}else{echo "0";} ?></span>
    </div>
    <span class="block-cart hidden-xs hidden-sm">
        <b class="hidden-xs hidden-sm m-l-sm">MY BAG</b>
        <p>item(s)</p>
    </span>
    <?php if($cnt > 0): ?>
        <div class="cart_block cart-block exclusive">
            <div class="block_content">
                <p class="cart-subtitle">Recently added item(s)</p>
                <div class="cart_block_list">
                    <div class="products">
                        <?php foreach ($cart->getAllVisibleItems() as $item): ?>
                                <?php $_product = Mage::getModel('catalog/product')->load($item->getProduct()->getId()); ?>
                                <div class="product-item-list">
                                    <a href="<?php echo $_product->getProductUrl() ?>" class="cart-images">
                                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize(72, 99); ?>" class="img-responsive"></a>
                                    <div class="cart-info">
                                        <div class="product-name">
                                            <a href="<?php echo $_product->getProductUrl() ?>" class="cart_block_product_name"><?php echo $_product->getName(); ?></a>
                                        </div>
                                        <span><?php echo $item->getQty(); ?>  x </span>
                                        <span class="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice(), 2); ?> </span>
                                    </div>
                                    <span class="remove_link">
                                           <a href="<?php echo $this->getUrl('checkout/cart/delete',array('id'=>$item->getId(),Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl())); ?>" rel="nofollow" title="remove this product from my cart"><i class="delet-item"></i>
                                            </a>
                                     </span>
                                </div>
                        <?php endforeach; ?>      
                    </div>
                </div>
            </div>
           
            <div class="clearfix"></div>
            <div class="buttons  m-t-sm">
                <div class="row">
                    <div class="col-xs-6 p-r-xs">
                        <button onclick="setLocation('<?php echo $this->getUrl('checkout/cart'); ?>')" type="button" title="View Bag" class="btn btn-theme btn-block"><span>VIEW BAG</span> </button>
                    </div>
                    <div class="col-xs-6 p-l-xs">
                        <button onclick="setLocation('<?php echo $this->getUrl('onepagecheckout'); ?>')" class="btn brown-btn  btn-block" title="Checkout" type="button"><span>CHECKOUT</span> </button>
                    </div>  
                </div>  
            </div>

        </div>

    <?php endif; ?>
</div>