1

I am working on magento 1.9, I have created a multiple selection attribute from back-end and deploy it on attribute sets, I want users to choose a time slots between 4 or 5 slots, like, there will be options 08:00 Am, 10:00 AM, 12:00PM, And so on, and user will choose appropriate time slot from all these.

The problem is i am working with virtual products as like services. so i don't want to go to the configurable or bundle way, i want a drop-down with these slots on my product page. i tried getting attribute value on select option but every time i do so i get only a drop-down not options and nor values

enter image description here enter image description here

Any Suggestions will be appreciated

Lalit

  • you can use custom options for this – Gopal Patel Mar 30 '17 at 12:13
  • @GopalPatel can you please assist me how to do that? – Lalit838 Mar 30 '17 at 12:29
  • @GopalPatel thank You so much,As i understand, it seems like i have to put it on every product individually? – Lalit838 Mar 30 '17 at 12:39
  • Yes , But if you have large number of product then you can set it programmatically – Gopal Patel Mar 30 '17 at 12:43
1

Create custom.php in root folder and place below code. Run custom.php through command line because it will take time to run.

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ini_set('max_execution_time', 0);
ini_set("memory_limit","-1");
require_once('app/Mage.php');
umask(0);

Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

$products=Mage::getModel('catalog/product')->getCollection();

function getOptions($product){

    $slotes=$product->getAttributeText('time_slot'); //your attribute code ex. time_slot
    $slotes=explode(" ",$slotes);
    $options=array();
    foreach ($slotes as $key => $value) {
        $options[]=array(
            'title' => $value,
            'price' =>$product->getPrice,
            'price_type' => 'fixed',
            'sort_order' => '1'
        )
    }
    return $options;
} 

foreach ($products as $product) {
    //echo $product->getId(); //print product id
    $option = array(
        'title' => 'custom option title',
        'type' => 'drop_down', // could be drop_down ,checkbox , multiple
        'is_require' => 1,
        'sort_order' => 0,
        'values' => getOptions($product)
    );
    $optionInstance = $product->getOptionInstance()->unsetOptions();
    $product->setHasOptions(1);
    $optionInstance->addOption($option);
    $optionInstance->setProduct($product);
    $product->save();
    //break; //try on one product
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.