Category Archives: Magento

Magento update product attribute without trigger reindex

Magento update product attribute without trigger reindex
Create a file updateAttribute.php on the root directory of your project folder and paste the the below code on your newly created (updateAttribute.php) file.

require_once('app/Mage.php'); 
umask(0);
Mage::app('admin');
// $product_id thhis is your product id(entity_id)
// $attribue_code this is your product attribute code (LIKE magento1 default code staus,description, etc )
// $value this is product code value 

FIRST WAY:- 
$product = Mage::getModel('catalog/product')->load($product_id); 
$resource = $product->getResource();
$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);

SECOND WAY:-


First run this code 
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');

Second run your product attribute code ..


NOTE:- if you run below code then reindex event will be trigger manually.. 
Third run below code.

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

Below is the example how to run the code..




$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');

$product = Mage::getModel('catalog/product')->load($product_id); 
$resource = $product->getResource();
$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);

magento 1 update product attribute without reindex programmatically

update your product attribute without reindex programmatically.
Create a file updateAttribute.php on the root directory of your project folder and paste the the below code on your newly created (updateAttribute.php) file.

require_once('app/Mage.php'); 
umask(0);
Mage::app('admin');
// $product_id thhis is your product id(entity_id)
// $attribue_code this is your product attribute code (LIKE magento1 default code staus,description, etc )
// $value this is product code value 


$product = Mage::getModel('catalog/product')->load($product_id); 
$resource = $product->getResource();
$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);


Hide Shipping method from cart page in magento

you can Hide Shipping method from cart page in magento on 2 ways

1 way to hide current shipping method on cart through Qutoe:-

$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if($shippingMethod){
    $quote->getShippingAddress()->setShippingMethod(null);  
    $quote->save(); 
}
 

2 way to hide current shipping method on cart through Session:-

if($shippingMethod=Mage::getSingleton('checkout/session')
->getQuote()->getShippingAddress()
            ->getShippingMethod()){
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()
            ->unsetShippingMethod($shippingMethod);
}

 

Get configurable option and value if parent and child known

Suppose configurable product id is $configProductId and the Simple
product id is $simpleProductId.
Fetch configurable attributes values.

$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($configProductId);
$attributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); 

Now load simple product by simple product id.

$child = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($simpleProductId);


foreach ($attributes as $attribute){
    //ID of the option will give
    echo $attribute['store_label'].' = '.$child->getData($attribute['attribute_code']).'<br />'; 

    //LABEL of the option Will give
    foreach ($attribute['values'] as $value){
        $childValue = $child->getData($attribute['attribute_code']);
        if ($value['value_index'] == $childValue){
            echo $attribute['store_label'].' = '.$value['store_label'].'<br />';
        }
    }
}

Magento update configurable option drop down on product detail page

create a configurable.phtml file in the given directory
app/design/frontend/magma/default/template/catalog/product/view/type/options
and put the below code on that file..

Clear your cache and than refresh your browser.







<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>

<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>


                 
                 
    <dl>
    <?php foreach($_attributes as $_attribute): ?>
        <label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label>        
            <span class="input-box">
                <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" 
id="attribute<?php echo $_attribute->getAttributeId() ?>" 
class="required-entry super-attribute-select">
                    <option><?php echo $this->__('Choose an Option...') ?></option>
                  </select>
              </span>        
    <?php endforeach; ?>
    </dl>
    
    
                 
                 
    <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
        
         
         
 function replaceSelectOption() {
    jQuery('.product_attribute_option_link').remove();
    jQuery('#selected_combination').text('');
    jQuery(".super-attribute-select").each(function () {
        var drop_down = jQuery(this);
        drop_down.hide();
        drop_down.find("option[value!='']").each(function () {
            var option = jQuery(this);
            jQuery("<a>", {
                text: option.text(),
                href: '#product-options-wrapper',
                class: 'product_attribute_option_link',
                'data-id': drop_down.attr('id'),
                'data-name': drop_down.attr('name'),
                'data-value': option.val(),
                'data-label': option.text(),
                click: function () {
                    drop_down.val(option.val());
                    var obj = drop_down.get();
                    Event.observe(obj[0], 'change', function () {
                    });
                    fireEvent(obj[0], 'change');
                    replaceSelectOption();
                    var selected_combination = [];
                    jQuery(".super-attribute-select").each(function () {
                        if (jQuery(this).val()) {
                            jQuery(".product_attribute_option_link[data-value=" + jQuery(this).val() + "]").addClass('product_attribute_option_link_selected');
                            selected_combination.push(jQuery(this).find("option:selected").text());
                        }
                    });
                    jQuery.each(selected_combination, function (index, selection) {
                        jQuery('#selected_combination').append(selection);
                        if (index + 1 < selected_combination.length)
                            jQuery('#selected_combination').append(" - ");
                    });
                    return false;
                }
            }).appendTo(drop_down.parent());
        });
    });
}

document.observe('dom:loaded', function () {
    replaceSelectOption();


    jQuery(".product-view .add-to-cart .button.btn-cart").attr('onclick', '');
    jQuery(".product-view .add-to-cart .button.btn-cart").on('click', function () {
        var chk = true;
        jQuery(".input-box .product_attribute_option_link").each(function () {
            if (jQuery(this).hasClass("product_attribute_option_link_selected")) {
                chk = false;
                return false;
            }
        });
        if (chk) {
            jQuery("#product-options-wrapper .input-box").addClass('validation-failed');
            jQuery("#product-options-wrapper > p.required").css({
                display: 'block',
                position: 'absolute',
                right: '0',
                top: '30px',
                color: 'red'
            });
            jQuery("#product-options-wrapper > p.required").fadeOut(3000, function () {
                jQuery("#product-options-wrapper .input-box").removeClass('validation-failed');
            });
        }
        else {
           productAddToCartForm.submit(this);
        }
    });

    


});
    </script>
<?php endif;?>