News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Saving Related Product and Category in Product Detail

Started by seyi, November 20, 2013, 16:58:10 PM

Previous topic - Next topic

seyi

Hey Guys,

I found a problem when trying to save a product in admin product details (index.php?option=com_virtuemart&view=product&task=edit&virtuemart_product_id[]=4).

If I enter a related category and then enter a related product, only the related product is saved.  After some digging I found this code to be the problem in
www/administrator/components/com_virtuemart/views/product/tmpl/product_edit_custom.php:

nextCustom = <?php echo $i ?>;

jQuery('input#relatedproductsSearch').autocomplete({

source: '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom,
select: function(event, ui){
jQuery("#custom_products").append(ui.item.label);
nextCustom++;
jQuery(this).autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom )
jQuery('input#relatedproductsSearch').autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom )
},
minLength:1,
html: true
});
jQuery('input#relatedcategoriesSearch').autocomplete({

source: '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom,
select: function(event, ui){
jQuery("#custom_categories").append(ui.item.label);
nextCustom++;
jQuery(this).autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom )
jQuery('input#relatedcategoriesSearch').autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom )
},
minLength:1,
html: true
});


On initial load nextCustom is set to 0 and so both autocomplete boxes receive 0 to begin with.  So when saving a category, it chooses the 0 index, and then when saving a product it uses the 0 index, causing the category to be overwritten.  Found a solution by using the live method of jquery


// jQuery('input#relatedproductsSearch').autocomplete({
jQuery("input#relatedproductsSearch").live("focus", function (event) {
   jQuery(this).autocomplete({

source: '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom,
select: function(event, ui){
jQuery("#custom_products").append(ui.item.label);
nextCustom++;
jQuery(this).autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom )
jQuery('input#relatedproductsSearch').autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedproducts&row='+nextCustom )
},
minLength:1,
html: true
});
});

// jQuery('input#relatedcategoriesSearch').autocomplete({
jQuery("input#relatedcategoriesSearch").live("focus", function (event) {
   jQuery(this).autocomplete({

source: '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom,
select: function(event, ui){
jQuery("#custom_categories").append(ui.item.label);
nextCustom++;
jQuery(this).autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom )
jQuery('input#relatedcategoriesSearch').autocomplete( "option" , 'source' , '<?php echo JURI::root(false?>administrator/index.php?option=com_virtuemart&view=product&task=getData&format=json&type=relatedcategories&row='+nextCustom )
},
minLength:1,
html: true
});
});

Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate