TomatoCart

68685 Downloads
304 users online
TomatoCart Community
Welcome, Guest
Please Login or Register.    Lost Password?
Bookmark and Share

"Add to Cart" from Accessories
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: "Add to Cart" from Accessories
#14897
"Add to Cart" from Accessories 9 Months, 1 Week ago Karma: 2
Hi All,

Wanted to share a little change I made to the "Accessories" UI to allow customers to "Add to Cart" directly instead of going to the associated product info page.

In: templates/<template name>/content/products/info.php

Find the where your accessories are displayed. In the default template this is in a div with and ID of "tabAccessories".

Add an extra parameter to the osc_link_object call (the call already expects this, but its not passed):

Original:
Code:


echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), 
$osC_Image->show($product->getImage(), $product->getTitle()));



Change to:
Code:


echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), 
$osC_Image->show($product->getImage(), $product->getTitle()), 
' id="productImage'.osc_get_product_id($product->getID()).'" '); 



You are adding:
Code:

, ' id="productImage'.osc_get_product_id($product->getID()).'" '


As the last param of the call.

You then need to edit the Shopping Cart JS file to re-order an "if" statement to show the cool image animation when an item is added to the cart. If you fail to change this the image will be the main product image of the page not the accessory image!

In: includes/javascript/ajax_shopping_cart.js

Look for the comment "//move image":

Original:
Code:


              if ( $defined($('defaultProductImage')) ) {
                //in the product info page, copy the product image and move it
                var productLink = $('productImages').getElement('#defaultProductImage');
                var productImg = $('defaultProductImage').getElement('img.productImage');
                var cloneProductImg = productImg.clone();
                var srcPos = productLink.getCoordinates();
                
                cloneProductImg.injectAfter(productLink).setStyles({
                  'position': 'absolute',
                  'left': productImg.getCoordinates().left,
                  'top': productImg.getCoordinates().top-5
                });
                
                var srcImage = cloneProductImg;
              }else if ( $defined($('productImage' + pID)) ) {
                var srcImage = $('productImage' + pID).getElement('img.productImage');
                 var srcPos = srcImage.getCoordinates();
              }



Swap the if/else:

Code:


     if ( $defined($('productImage' + pID)) ) {
                var srcImage = $('productImage' + pID).getElement('img.productImage');
                 var srcPos = srcImage.getCoordinates();
              } else if ( $defined($('defaultProductImage')) ) {
                //in the product info page, copy the product image and move it
                var productLink = $('productImages').getElement('#defaultProductImage');
                var productImg = $('defaultProductImage').getElement('img.productImage');
                var cloneProductImg = productImg.clone();
                var srcPos = productLink.getCoordinates();
                
                cloneProductImg.injectAfter(productLink).setStyles({
                  'position': 'absolute',
                  'left': productImg.getCoordinates().left,
                  'top': productImg.getCoordinates().top-5
                });
                
                var srcImage = cloneProductImg;
//alert(productImg);
              }



You are done! This will display the "Add to Cart" button, and allow your customers to buy accessories quicker

HTH
qU57MRteBvFl0Zc
Fresh Boarder
Posts: 9
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2011/08/12 08:52 By qU57MRteBvFl0Zc.
The administrator has disabled public write access.
 
#16698
Re: "Add to Cart" from Accessories 5 Months ago Karma: 4
i did this and nothing happens no add to cart at all.
annetteb
Senior Boarder
Posts: 70
graphgraph
User Online Now Click here to see the profile of this user
Gender: Female Location: Sydney, Australia
The administrator has disabled public write access.
 
#16709
Re: "Add to Cart" from Accessories 5 Months ago Karma: 4
problem solved ad this after the code in template/templatename//products/info.php



<div class="image"><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory),
$osC_Image->show($product->getImage(), $product->getTitle()),
' id="productImage'.osc_get_product_id($product->getID()).'" '); ?></div>
<div class="desc">
<h6><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $product->getTitle()); ?></h6>
<p><?php echo $product->getShortDescription(); ?></p>


add at the bottm on this code

<?php
echo '<b>' . osc_draw_image_submit_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'), 'style="vertical-align:middle;" class="ajaxAddToCart" id="ac_productsinfo_' . osc_get_product_id($product->getID()) . '"');
?>

worked for me. thanks all
annetteb
Senior Boarder
Posts: 70
graphgraph
User Online Now Click here to see the profile of this user
Gender: Female Location: Sydney, Australia
The administrator has disabled public write access.
 
#16710
Re:"Add to Cart" from Accessories 5 Months ago Karma: 4
i have added price as well as some formatting.

the code is below:


<div id="tabAccessories">
<div class="moduleBox">
<div class="content">
<?php
foreach ($accessories as $accessory) {
$product = new osC_Product($accessory);
?>
<div class="accessories">
<div align="center" class="image"><p></p><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $osC_Image->show($product->getImage(), $product->getTitle()),' id="productImage'.osc_get_product_id($product->getID()).'" '); ?> <p></p>&nbsp;<?php echo $product->getPriceFormated(true) . '&nbsp;' . ( (DISPLAY_PRICE_WITH_TAX == '1') ? $osC_Language->get('including_tax') : '' ); ?><?php echo '<b>' . osc_draw_image_submit_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'), 'style="vertical-align:middle;" class="ajaxAddToCart" id="ac_productsinfo_' . osc_get_product_id($product->getID()) . '"');
?><p></p></div>
<div class="desc">
<h4><p></p><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $product->getTitle()); ?></h4>
<font size="0"><p></p><?php echo $product->getShortDescription(); ?></font><p></p>




</div>
</div>
<div style="clear: both"></div>
<?php } ?>
</div>
</div>
</div>

replace your code with this code and presto adto cart and price in the accessories tab. with image fly out to cart.
annetteb
Senior Boarder
Posts: 70
graphgraph
User Online Now Click here to see the profile of this user
Gender: Female Location: Sydney, Australia
The administrator has disabled public write access.
 
#16784
Re:"Add to Cart" from Accessories 4 Months, 3 Weeks ago Karma: 24
This is a great idea.

Here*s the change to display prices and add to cart buttons as shown on image below.

In: templates/<template name>/content/products/info.php

replace this code:
-------------------------------------
<div class="accessories">
<div class="image"><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $osC_Image->show($product->getImage(), $product->getTitle())); ?></div>
<div class="desc">
<h6><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $product->getTitle()); ?></h6>
<p><?php echo $product->getShortDescription(); ?></p>
</div>
</div>
<div style="clear: both"></div>
-------------------------------------

with this code:
-------------------------------------
<div class="accessories">
<div class="image"><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $osC_Image->show($product->getImage(), $product->getTitle()), ' id="productImage'.osc_get_product_id($product->getID()).'"');?></div>
<div class="desc">
<h6><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $accessory), $product->getTitle()); ?></h6>
<?php echo $product->getShortDescription(); ?>
<div class="price"><b><?php echo $osC_Language->get('price') . '</b>&nbsp;' . $product->getPriceFormated(true); ?></div>
</div>
<div class="buy"><?php echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, osc_get_product_id($product->getID()) . '&action=cart_add'), osc_draw_image_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_productsnew_' . osc_get_product_id($product->getID()) . '"')); ?></div>
</div>
<div style="clear: both"></div>
-------------------------------------
In your template stylesheet.css replace:
-------------------------------------
.accessories {height: 100px}
.accessories .image {float: left; width: 100px}
.accessories .desc {float: right; width: 400px}
.accessories .desc h6 a{color: #616060}
-------------------------------------
with:
-------------------------------------
.accessories {height: 100px; padding-bottom:18px;}
.accessories .image {float: left; width: 120px}
.accessories .desc {float: left; width: 285px}
.accessories .price {float: left; width: 285px; padding-bottom:18px;}
.accessories .buy {float: right; width: 100px; padding-top:24px}
.accessories .desc h6 a{color: #616060}
-------------------------------------

It works fine. Thanks for sharing it.
Antun
Post your PM to my email r3xams@gmail.com
Platinum Boarder
Posts: 471
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Croatia, Europe
The administrator has disabled public write access.
 
#16801
Re:"Add to Cart" from Accessories 4 Months, 3 Weeks ago Karma: 4
i get this error using your code

Fatal error: Call to a member function getImage() on a non-object in /home/tabstore/public_html/templates/glass_gray/content/products/info.php on line 543
annetteb
Senior Boarder
Posts: 70
graphgraph
User Online Now Click here to see the profile of this user
Gender: Female Location: Sydney, Australia
The administrator has disabled public write access.
 
Go to top Page: 12

Latest Blog Post

How to install the Authorizenet AIM payment module

Authorize.Net enables merchants to authorize, settle and manage credit card and electronic check transactions via Web sites, retail stores, mail ...

Blog | jack.yin(weijian) | Wednesday, 2 May 2012

More in: About Us

-
+
3

contact_us

info@tomatocart.com
partner@tomatocart.com
support@tomatocart.com
Gtalk: jack.yin@tomatocart.com
Facebook Google+ Linkedin Twitter

Newsletter Subscription