Hello guys,
I am currently doing a project that requires simple products with custom options. Easy to do, then suddenly my client ask if he can monitor the inventory of that custom option.
I\’ve search for hours and reach some dead end.
So far the closest I did was with this forum:
http://www.magentocommerce.com/boards/viewthread/73036/P0/
I followed the instructions there and which are:
1. add new field to the database:
log into phpmyadmin
select the table: catalog_product_option_type_value
click \’SQL\’ and insert
ALTER TABLE ` catalog_product_option_type_value ` ADD ` qty ` DECIMAL ( 12 , 2 ) DEFAULT \ '0\' AFTER ` option_id ` ;
click \’go\’
2. add new column in the admin area
app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml
after this line:
\ '<th class=\"type-type\"><?php echo Mage::helper(\' catalog\ ')->__(\' Price Type\ ') ?></th>\' +
insert:
\ '<th class=\"type-weight\"><?php echo Mage::helper(\' catalog\ ')->__(\' Qty\ ') ?></th>\' +
after this line:
< td > <?php echo $this -> getPriceTypeSelectHtml () ?>{{checkboxScopePrice}} </ td > \ +
insert:
\ '<td><input type=\"text\" class=\"input-text validate-number product-option-weight\" id=\"product_option_{{id}}_select_{{select_id}}_qty\" name=\"product[options][{{id}}][values][{{select_id}}][qty]\" value=\"{{qty}}\"></td>\' +
3. add the qty to the array
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php
after this line:
\ 'price_type\' => $_value -> getPriceType (),
insert:
\ 'qty\' => $_value -> getQty (),
4. add custom qty to the main product when added to the cart
app/code/core/Mage/Sales/Model/Quote/Item.php
BEFORE this line:
$this -> setData ( \ 'product\' , $product )
insert
$options = $this -> getOptions (); if ( is_array ( $options )) { unset( $options[0] );unset( $options[1] ); $read = Mage :: getSingleton ( \ 'core/resource\' )-> getConnection ( \ 'core_read\' ); foreach ( $options as $option ) { $temp = $read -> fetchRow ( \ 'SELECT * FROM `catalog_product_option_type_value` WHERE `option_type_id` = \' . $option -> getValue (). \ ' LIMIT 0, 1\' ); $tempQty = ( $temp[\ 'qty\' ] > 0 )? $temp[\ 'qty\' ] - 1 : 0 ; $write = Mage :: getSingleton ( \ 'core/resource\' )-> getConnection ( \ 'core_write\' ); $updateQuery = \ 'UPDATE `catalog_product_option_type_value` SET qty = \' . $tempQty . \ ' WHERE `option_type_id` = \' . $option -> getValue (); $write -> query ( $updateQuery ); } }
It is close But.. when I try add the product to the cart with qty greater than 1, the option qty is still subtracted by 1 and I know that the code is still not complete because there is no update when I delete products in the cart.
Can somebody point me to the right direction here?
What are the things needed to be done?
Signature
"If you cannot do great things, do small things in a great way.”
while( !succeed ) try();