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

Help with Custom Scroller and Adding products To cart

Started by mwillems, February 28, 2012, 22:18:30 PM

Previous topic - Next topic

mwillems

Hi
I have created a scroller in Joomla 2.5 VM 2.0.2  The site isn't live so I can't send a link.  It works perfectly aside from one aspect.  I have copied the code to add a product to the cart from the product_details component.  if I remove the <Noscript> option around the task - add POST then it adds just fine, but with the blue message bars at the top informing me that the product has been added.  I was hoping I could get it to use the JSON method instead.  This method appears to become activated whem you call vmJsApi::jPrice();, which in turns calls jprices() in jmprices.js which will put a watch on the input.addtocart-button element.  When it is clicked, seems to use JSON to process the addition.

the reason for doing this is because I want to customise a JSON form that is displayed when a product is added.  I also want to change the behaviour of VM after the product has been added, such as the redirect.

However, simply calling vmJsApi::jPrice(); in the php for the scroller doesn't seem to work, despite my form data appearing to be correct as the click event is not being captured.
The scroller was written for 1.7/vm1.1 and didn't work for 2.5/vm2 so I had to modify it.  Is there anything obviously wrong with this?

Also, I only just began to learn PHP/javascript/HTML in the past few weeks.  So some things I have learnt to do well and some things I just haven't come across yet.

function product_snapshot_new( $product_id, $show_product_name = true, $show_price=true, $show_detail=true, $show_addtocart=true, $cart_text2="More Information" ) {
         global $sess, $mm_action_url;
                  
                  
                  

                        $product_manager = new VirtueMartModelProduct;
                        $pr = $product_manager->getProduct($product_id);
                     


                        if ($pr) {
                           
                               
                               $db = JFactory::getDBO();
                     $query="SELECT * FROM #__virtuemart_medias where virtuemart_media_id = '".$pr->virtuemart_media_id[0]."'";
                     $db->setQuery( $query );
                     $image = $db->loadObject();
                         
                               
                         
                         
                            $html='';
            //$cid = $ps_product_category->get_cid( $product_id );
                                $cid = $pr->virtuemart_category_id;
                                   
            if ($pr->product_parent_id) {
               $url = "?page=shop.product_details&category_id=$cid";
               $url .= "&product_id=" . $pr->product_parent_id;
            } else {
               $url = "?page=shop.product_details&category_id=$cid";
               $url .= "&product_id=" . $pr->virtuemart_product_id;
                                     
            }

            $product_link = $pr->link;

                                if ($show_product_name) {
               $html .= '<span class="VMTitle'.$this->slideid.'" style="color: '.$this->titlecolor.'; text-align: '.$this->titlealign.';">'.'<a href="'. $product_link .'" title="'.$pr->product_name.'"><img src="'.JURI::base(true).'/'.$image->file_url_thumb.'" class="VMImg'.$this->slideid.'" style="height: '.$this->imageSize.';" alt="'.$pr->product_name.'" /><br/>'.$pr->product_name.'</a></span>';
            } else {
               $html .= '<span class="VMTitle'.$this->slideid.'">'.'<a href="'. $product_link .'" title=""><img src="'.JURI::base(true).'/'.$image->file_url_thumb.'" class="VMImg'.$this->slideid.'" style="width: '.$this->imageSize.';" alt="'.$pr->product_name.'" /></a></span>';
            }

            if ($show_price) {         
               $db->setQuery("SELECT REPLACE(REPLACE(C.currency_positive_style,'{symbol}',                                C.currency_symbol ),'{number}',cast(P.".$this->whichprice." as decimal(19,2))) As pricetext
                                             FROM 
                                             #__virtuemart_product_prices as P
                                             LEFT JOIN
                                             #__virtuemart_currencies as C on C.virtuemart_currency_id = P.product_currency
                                             WHERE P.virtuemart_product_id = '" . $product_id . "'  LIMIT 1 ");


                                        $price_object = $db->loadObject();
               
               
               //$price = $pr->prices['salesPrice'];
         
                   if ($price_object->pricetext=="£0.00" && $this->whichprice<>"product_price")
               {
                     $db->setQuery("SELECT REPLACE(REPLACE(C.currency_positive_style,'{symbol}',                                C.currency_symbol ),'{number}',cast(P.product_price as decimal(19,2))) As pricetext
                                             FROM 
                                             #__virtuemart_product_prices as P
                                             LEFT JOIN
                                             #__virtuemart_currencies as C on C.virtuemart_currency_id = P.product_currency
                                             WHERE P.virtuemart_product_id = '" . $product_id . "'  LIMIT 1 ");


                                        $price_object = $db->loadObject();
               }
               

               $price = '<span class="productPrice">'.$price_object->pricetext.'</span>';
                     vmJsApi::jPrice();                   

            }
            else $price='';

            if ($show_detail) {
               $html .= '<span class="VMDetail" style="color: '.$this->detailcolor.'; text-align: '.$this->detailalign.'" />'.$pr->product_s_desc.'</span>';
            }
            if ($show_price) {
               $html .= '<div style="border-bottom:solid '.$this->borderthick.' '.$this->bordercolor.'; line-height:36px;">'.$price;   
            }

            if(   $show_addtocart == 1){
               $html .= '<form action="index.php" method="post" name="addtocart" >
               <input type="hidden" class="pname" value="'.$pr->product_name.'" />
            <input type="hidden" name="option" value="com_virtuemart" />
            <input type="hidden" name="view" value="cart" />
            <noscript><input type="hidden" name="task" value="add" /></noscript>
            <input type="hidden" name="virtuemart_product_id" value="'.$pr->virtuemart_product_id.'" />
            <input type="hidden" name="virtuemart_manufacturer_id" value="'.$pr->virtuemart_manufacturer_id.'" />
            <input type="hidden" name="virtuemart_category_id[]" value="'.$pr->virtuemart_category_id.'" />
            
            <input type="hidden" class="quantity-input js-recalculate" name="quantity[]" value="1" />
            
            
            
            <div class="addtocart-button" align="center"><input type="submit" class="addtocart-button" value="'.$cart_text2.'" title="Add to cart" name="addtocart" style="border-radius:9px; border-color: #009900;  background:#009900; width:50px; color:#fff;box-shadow: 0px 0px 3px 3px rgba(80,140,80,.9); font-size:14px; font-weight:450;"/></div>
            </form>';}
            else $html .= '</div>';
            $html .= '</div>';

            return $html;
         }

         return '';
      }   

rupesh

Hello

Vmscroller is very nice module!

i'm using it on my website see this!

http://www.elifeshopping.com/


CAN YOU PLE TELL ME BELOW POINTS?

how you fetched product thumbnails images for main image becoz i'm also trying to develop a module which uses sql like

SELECT DISTINCT P.virtuemart_product_id,Pen.product_name ,vpm.virtuemart_media_id ,vm.file_url_thumb ,vpp.product_price FROM virtuemart_products as P
LEFT JOIN virtuemart_products_en_gb as Pen on Pen.virtuemart_product_id = P.virtuemart_product_id
LEFT JOIN virtuemart_product_medias as vpm on vpm.virtuemart_product_id = P.virtuemart_product_id
LEFT JOIN virtuemart_medias as vm on vm.virtuemart_media_id=vpm.virtuemart_media_id
LEFT JOIN virtuemart_product_prices as vpp on vpp.virtuemart_product_id = P.virtuemart_product_id
LEFT JOIN virtuemart_product_categories as PC on PC.virtuemart_product_id = P.virtuemart_product_id WHERE P.published = 1 AND PC.virtuemart_category_id =14 ORDER BY `P`.`created_on`  ASC LIMIT 10

But it will return vm.file_url_thumb for all images as we have multiple images for product!

But i want to fetch only main image thumbnail like your scroller!

Can you tell me how to fetch main thumbnail  image only

Thanks