Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Question about duplicating custom options
 
nekhbet
Jr. Member
 
Total Posts:  6
Joined:  2008-11-27
 

Hi all,
I’m new to this forum and to Magento. I’m trying to do a simple shop for eye lenses. I managed to add the custom options (please look at the attached image) and now I need to duplicate the same option bar (one for left eye and one for the right eye). Can you give me an idea on how I can duplicate (in the end the visitor should be able to add from the same page, for example, 3 lenses for the right eye and 2 lenses for the left eye without going to the same page twice) ?
Thanks
Sorin

Image Attachments
screen1.JPG
 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

You cannot do it except by code. Write a php file, e.g. cpo.php store it in root, run it with http://example.com/cpo.php, then delete it when you are done. Here is some example code. This works on configurable products within a given category id. You will need to modify all the code to suit your needs and browsing your tables in phpmyadmin will be helpful in that task:

<html>
<
head>
<
title>Custom Product Options shirt</title>
</
head>
<
body>
<?php {
// Database connection - hope you remembered your user, pass and db
  
$res mysql_pconnect('localhost''user''pass');
  
mysql_select_db('dbname');
// Product selector - here all skus with T-shirt are selected you may want to use one sku to test
  
$res mysql_query('select entity_id from catalog_product_entity where type_id = \'configurable\' and category_ids=\'289\'');
// Flag to test selection, set to 1 for cpo's to be added, set to 0 if the products to be modified just need to be shown with no harm done...
  
$go_for_it=0;

// Go through all the products that match the selection
  
while ($o mysql_fetch_array($res)) {
    $res_o 
mysql_query('select option_id from catalog_product_option where product_id='.$o['entity_id']);
    
$result mysql_query('select sku from catalog_product_entity where entity_id='.$o['entity_id']);
// Get the product images too - keep it visual
    
$image_o =  mysql_query('select value from catalog_product_entity_media_gallery where entity_id='.$o['entity_id']);
    
$image =  mysql_fetch_array($image_o);

    
$row mysql_fetch_assoc($result);
    if (
mysql_num_rows($res_o)) {
// if there are already custom product options then do nothing and move on
      
echo '<img src="/media/catalog/product'.$image['value'].'"> '.$row['sku'].' ('.$o['entity_id'].') has options already<br />';
      
$catalog_product_option =  mysql_query('select option_id, product_id, type, is_require, sku, max_characters, file_extension, sort_order from catalog_product_option where product_id='.$o['entity_id']);
      
$catalog_product_option_array mysql_fetch_array($catalog_product_option);
      echo 
'table catalog_product_option values='.$catalog_product_option_array['option_id'].' '.$catalog_product_option_array['product_id'].'<br />';
    
}
    
else {
// if there are no custom product options then do stuff if we are able to

      
if($go_for_it!=1{
        
echo '<img src="/media/catalog/product'.$image['value'].'"> '.$row['sku'].' ('.$o['entity_id'].') has yet to get custom product options<br />';
      
else {
        
echo '<img src="/media/catalog/product'.$image['value'].'"> '.$row['sku'].' ('.$o['entity_id'].') is getting new custom product options<br />';

//Add text box and checkbox list

        
mysql_query('insert into catalog_product_option (product_id, type, is_require, sort_order) values ('.$o['entity_id'].', "area", 0, "10")');
        
$area_id=mysql_insert_id();
        
mysql_query('insert into catalog_product_option (product_id, type, is_require, sort_order) values ('.$o['entity_id'].', "checkbox", 0, "0")');
        
$checkbox_id=mysql_insert_id();

//No price for the text box

        
mysql_query('insert into catalog_product_option_price (option_id, store_id, price, price_type) values ('.$area_id.', "0", "0.00", "fixed")');

//Text for the text box and check box list

        
mysql_query('insert into catalog_product_option_title (option_id, store_id, title) values ('.$area_id.', "0", "Size, location and other notes")');
        
mysql_query('insert into catalog_product_option_title (option_id, store_id, title) values ('.$checkbox_id.', "0", "Customise!")');

//Add check-box 1

        
mysql_query('insert into catalog_product_option_type_value (option_id, sort_order) values ('.$checkbox_id.', "0")');
        
$option_type_id=mysql_insert_id();
        
mysql_query('insert into catalog_product_option_type_title (option_type_id, store_id, title) values ('.$option_type_id.', "0", "Embroidered badge")');
        
mysql_query('insert into catalog_product_option_type_price (option_type_id, store_id, price, price_type) values ('.$option_type_id.', "0", "3.0000", "fixed")');

//Add check-box 2 - removed to fit form

    
}
    mysql_free_result
($result);
  
}
}
?>
</body>
</
html>
 
Magento Community Magento Community
Magento Community
Magento Community
 
nekhbet
Jr. Member
 
Total Posts:  6
Joined:  2008-11-27
 

Thanks for the quick reply smile

I will modify it as you said (all the products are simple with custom options) but I still don’t understand how will that script do it like this (please see the attached image).

Regards

Sorin

Image Attachments
screen1.JPG
 
Magento Community Magento Community
Magento Community
Magento Community
 
dweb
Jr. Member
 
Total Posts:  13
Joined:  2007-08-31
 

Hi,

I’m also interested if you have find a solution !
I have tried to create a new grouped product composed with 2 simple products having each custom options but magento seems to not accept this !

 
Magento Community Magento Community
Magento Community
Magento Community
 
tomislavbilic
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-17
Osijek, Croatia
 
dweb - 20 December 2008 11:30 AM

Hi,
I’m also interested if you have find a solution !
I have tried to create a new grouped product composed with 2 simple products having each custom options but magento seems to not accept this !

Hi dweb,

Did you try to set custom options as Not required?

Check out this article. It explains How to associate simple product with custom options in grouped product in Magento

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top