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;?>

Magento update product sku programmatically using csv

Put a skucsv.csv file which containt 2 columns.
1st column containt OLD sku list and 2nd column containt New sku list.
Create a updateProductSku.php file in root and paste below script on this file.





error_reporting(E_ALL);
ini_set('display_errors', 1);
define('MAGENTO_ROOT', getcwd());
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::init();
$row = 1;

if (($handle = fopen("skucsv.csv", "r")) !== FALSE) {

    while (($sku = fgetcsv($handle, 1000, ",")) !== FALSE) {
 // $sku[0] OLD sku list
 // $sku[1] New sku list
        $product = Mage::getModel('catalog/product')->loadByAttribute('sku',
                $sku[0]);
       
        if ($product && $product->getTypeId() == 'simple') {
            $product->setSku($sku[1]);
            $product->save(); 
        }else{            
            echo $sku[0].' Does not found SKU <br />';
        }

        unset($product);       
        $row++;
    }

    fclose($handle);
}

Magento remove product from category programatically

Create a file in root directory of project and paste below code on that file and run this file on browser.
Please take a DB backup before use it.




In below script we are checking New category product From Date and To Date. if any product does not meet the date range than product automatically removed from that category


error_reporting(E_ALL);
ini_set('display_errors', 1);
define('MAGENTO_ROOT', getcwd());
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::init();
$newCatId = 147; //category Id those you want to check it.


$cat = Mage::getModel('catalog/product')->setId($newCatId);
$collection = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($cat)
->addAttributeToSelect('*');
$collection->addAttributeToFilter('status', 1);
$collection->addFieldToFilter(array(array('attribute' => 'visibility', 'neq' => "1")));
$collection->addUrlRewrite($cat);
//$collection->getSelect()->order('rand()');
//$collection->getSelect()->limit(4);



//Subtract 1 Day from current date
$date = strtotime(date('Y-m-d'));
$newDateDay = date('Y-m-d', strtotime('-1 day', $date)) . ' ' . date('H:i:s'); 


if (count($collection) > 0):
    foreach ($collection as $item):
        if (($item->getNewsFromDate() != '' && $item->getNewsFromDate() < date('Y-m-d H:i:s'))
                && ($item->getNewsToDate() == '' or $item->getNewsToDate() >= $newDateDay)) {
		// put the code that you want to meet the requirement
            
        } else {
            //Remove product from that category	    
            Mage::getSingleton('catalog/category_api')
		->removeProduct($newCatId,$item->getId());  // First Parameter is Category Id and Second is Product Id
        }

    endforeach;
endif;

// Indexing of the category
$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_category_product');
$process->reindexAll();

magento change choose an option text in product detail page

It’s very simple to change the text of default Magento choose an option to size or whatever we want.

Go to your theme file location

app/design/frontend/YOUR-THEME_NAME(default)/default/template/catalog/product/view/type/options/configurable.phtml


Rplace this code 
 <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
 </script>

to this one

<script type="text/javascript">
    <?php
        $jsonConfig = $this->getJsonConfig();
        $jsonConfig = str_replace("Choose an Option...", "Size", $jsonConfig);
    ?>
    var spConfig = new Product.Config(<?php echo $jsonConfig; ?>);
</script>