Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Pretty'ing up Shopping Cart in navbar_modules


Recommended Posts

Hey all, I'm trying to pretty up the navbar shopping cart for the modular navbar in EDGE and I'm having one small issue.

 

I'm trying to include the Checkout with PayPal button.... All works well UNLESS I'm on the shopping_cart.php or checkout_payment.php pages where, I presume, the payment class (and or the button) is already included.

 

Below is my template code - anyone willing to take a look at it... I would  greatly appreciate it.

 

It's not the end of the world if the Checkout with PayPal button is not included on either of these 2 pages - however I'm also sure there must be a way (with a well crafted if statement) to get it to work.... It just seems to be eluding me.

<?php
   if ($cart->count_contents() > 0) {
  ?>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo sprintf(MODULE_NAVBAR_SHOPPING_CART_CONTENTS, $cart->count_contents()); ?></a>
    <ul class="dropdown-menu">
      <li><?php echo '<a href="' . tep_href_link('shopping_cart.php') . '">' . sprintf(MODULE_NAVBAR_SHOPPING_CART_HAS_CONTENTS, $cart->count_contents(), $currencies->format($cart->show_total())) . '</a>'; ?></li>
      <li role="separator" class="divider"></li>
      <?php      
      $products = $cart->get_products();
      foreach ($products as $k => $v) {
        echo '<li>' . sprintf(MODULE_NAVBAR_SHOPPING_CART_PRODUCT, $v['id'], $v['quantity'], $v['name']) . '</li>';
      }        
      ?>
      <li role="separator" class="divider"></li>

    <div class="buttonSet">
    <div class="text-center"><?php echo tep_draw_button(IMAGE_BUTTON_CHECKOUT, 'fa fa-truck', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'primary', NULL, 'btn-success'); ?></div>
    </div>
<?php

   if(!class_exists('payment')) {
    include_once(DIR_WS_CLASSES . 'payment.php');
    $payment_modules = new payment;
   
    $initialize_checkout_methods = $payment_modules->checkout_initialization_method();

    if (!empty($initialize_checkout_methods)) {
		
?>
  <div class="clearfix"></div>
  <p class="text-center"><?php echo " -OR- " ?></p>

<?php

      while (list(, $value) = each($initialize_checkout_methods)) {
?>

  <p class="text-center"><?php echo $value; ?></p>

<?php
      }
    }
  }	
?>
  
    </ul>
  </li>
  <?php

}
else {
  echo '<li> <a class="dropdown-toggle">' . MODULE_NAVBAR_SHOPPING_CART_NO_CONTENTS . '</a></li>';
}
?>
Link to comment
Share on other sites

Ok it would  seem this is more complicated than I first thought... OR, and more likely, I'm probably over thinking this....

 

In the process of cleaning up the shopping cart navbar module I created a new "button" module for the navbar only visable on xs.... And it would seem I'm having the same issue with the checkout with Paypal button.

 

Because I've already called for payment classes and modules in the navbar shopping_cart template file.... I cannot call it again in the new navbar shopping_cart_button template file I've just created.

 

@Harald Ponce de Leon

 

How does one make a duplicate instance of the checkout with PayPal button?

 

Here is what I have now....

   if(!class_exists('payment')) {
    include_once(DIR_WS_CLASSES . 'payment.php');
    $payment_modules = new payment;
   
    $initialize_checkout_methods = $payment_modules->checkout_initialization_method();

    if (!empty($initialize_checkout_methods)) {
		
?>
  <div class="clearfix"></div>
  <p class="text-center"><?php echo " -OR- " ?></p>

<?php

      while (list(, $value) = each($initialize_checkout_methods)) {
?>

  <p class="text-center"><?php echo $value; ?></p>

<?php
      }
    }
  }	
?>

And it works on all but shopping_cart.php and checkout_payment.php

Link to comment
Share on other sites

Ok, what if I just hard code it???? That would be simple right?

<p class="text-center"><a href="https://www.**********.com/sandbox/ext/modules/payment/paypal/express.php" data-paypal-button="true"><img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png" border="0" alt="" title="Check out with PayPal (paypal_express; Sandbox)" /></a></p>

Then I just have to figure out the tep_href_link to the path....

Link to comment
Share on other sites

Ok I got this all figured out... and seems to work and look good.

 

I have 2 new navbar modules, once to replace the EDGE included nb_shopping_cart and a "new" nb_shopping_cart_button. I'll post some code here for someone to test before I upload to the addon area.

 

Maybe someone could advise. I have currently "not" renamed the nb_shopping_cart - it would overwrite the included module... is this advisable? Or should I rename....

Link to comment
Share on other sites

Maybe someone could advise. I have currently "not" renamed the nb_shopping_cart - it would overwrite the included module... is this advisable? Or should I rename....

 

@@greasemonkey  Scott I would rename it too....if someone just wants to have a look and then revert back, the original would be toast.  With a different name it might avoid some confusion too.

 

Dan

Link to comment
Share on other sites

It would seem I cannot attach a zip.... so here is the code for the navbar button shopping cart

 

For \includes\modules\navbar_modules\nb_fancy_shopping_cart_button.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  class nb_fancy_shopping_cart_button {
    var $code = 'nb_fancy_shopping_cart_button';
    var $group = 'navbar_modules_home';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;    
    
    function nb_fancy_shopping_cart_button() {
      $this->title = MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_TITLE;
      $this->description = MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_DESCRIPTION;

      if ( defined('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_STATUS') ) {
        $this->sort_order = MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_SORT_ORDER;
        $this->enabled = (MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_STATUS == 'True');
        
        switch (MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CONTENT_PLACEMENT) {
          case 'Home':
          $this->group = 'navbar_modules_home';
          break;
          case 'Left':
          $this->group = 'navbar_modules_left';
          break;
          case 'Right':
          $this->group = 'navbar_modules_right';
          break;
        } 
      }
    }

    function getOutput() {
      global $oscTemplate, $cart;

      $cart_contents_string = '';

      if ($cart->count_contents() > 0) {
        $cart_contents_string = NULL;
        $products = $cart->get_products();
        for ($i=0, $n=sizeof($products); $i<$n; $i++) {
          $cart_contents_string .= '<a href="' . tep_href_link('product_info.php', 'products_id=' . $products[$i]['id']) . '">';
          $cart_contents_string .= $products[$i]['quantity'] . ' x ' . $products[$i]['name'];
		  $cart_contents_string .= '</a>';
        }
	  }
 
      ob_start();
      require('includes/modules/navbar_modules/templates/fancy_shopping_cart_button.php');
      $data = ob_get_clean();

      $oscTemplate->addBlock($data, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_STATUS');
    }

    function install() {
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Shopping Cart Button Module', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_STATUS', 'True', 'Do you want to add the module to your Navbar?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CONTENT_PLACEMENT', 'Home', 'This module must be placed in the Home area of the Navbar.', '6', '1', 'tep_cfg_select_option(array(\'Home\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_SORT_ORDER', '500', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_STATUS', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CONTENT_PLACEMENT', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_SORT_ORDER');
    }
  }

For \includes\modules\navbar_modules\templates\fancy_shopping_cart_button.php

<?php
   if ($cart->count_contents() > 0) {
  ?>
  <div class="dropdown pull-right">
  
    <button class="navbar-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<?php echo sprintf(MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CONTENTS, $cart->count_contents()); ?>
  </button>

    <ul class="dropdown-menu">
      <li><?php echo '<a href="' . tep_href_link('shopping_cart.php') . '">' . sprintf(MODULE_NAVBAR_FANCY_SHOPPING_CART_HAS_CONTENTS, $cart->count_contents(), $currencies->format($cart->show_total())) . '</a>'; ?></li>
      
	  <li role="separator" class="divider"></li>
      <li class="small"><?php echo $cart_contents_string; ?></li>
      <li role="separator" class="divider"></li>

    <div class="buttonSet">
    <div class="text-center"><?php echo tep_draw_button(IMAGE_BUTTON_CHECKOUT, 'fa fa-truck', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'primary', NULL, 'btn-success'); ?></div>
    </div>
	
	<?php
      if ( !defined('MODULE_PAYMENT_INSTALLED') || !tep_not_null(MODULE_PAYMENT_INSTALLED) || !in_array('paypal_express.php', explode(';', MODULE_PAYMENT_INSTALLED)) || !defined('OSCOM_APP_PAYPAL_EC_STATUS') || !in_array(OSCOM_APP_PAYPAL_EC_STATUS, array('1', '0')) ) {

        $this->enabled = false;

      }else{
		  
	  ?>
  <div class="clearfix"></div>
  <p class="text-center"><?php echo " -OR- " ?></p>
<p class="text-center"><?php echo '<a href="' . tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL') . '">' . '<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png" border="0" alt="" title="Check out with PayPal (paypal_express; Sandbox)" />' . '</a>' ?> </p>

 <?php
	  }
	  ?>
    </ul>
  </div>
<?php

}
else {
?>    
 <div class="dropdown pull-right">
 <button class="navbar-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  <?php 
  echo '<a class="dropdown-toggle">' . MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_NO_CONTENTS . '</a>';
  }
?>
</button></div>

<style>
/*shopping cart dropdown-menu maz width on sm*/
@[member='media'] (max-width: 767px) {
	.dropdown-menu {
		width: 280px !important;}
	.dropdown-menu > li > a {
		white-space: normal !important;}
	}
</style>

And for \includes\languages\english\modules\navbar_modules\nb_fancy_shopping_cart_button.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_TITLE', 'Fancy Shopping Cart Button');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_DESCRIPTION', 'Show Fancy Shopping Cart Button in Navbar.  <div class="secWarning">This is a special button that shows when the viewport is small.</div>');
  
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_PUBLIC_SCREENREADER_TEXT', '<span class="sr-only">Toggle Navigation</span>');  
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_PUBLIC_BUTTON_TEXT', '<i class="fa fa-shopping-cart"></i><span class="badge"> %s</span> <span class="caret"></span>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CONTENTS', '<i class="fa fa-shopping-cart"></i><span class="badge"> %s</span> <span class="caret"></span>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_NO_CONTENTS', '<i class="fa fa-shopping-cart"></i><span class="badge"> 0</span>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_HAS_CONTENTS', '<i class="small"> %s item(s) in your cart <p>Total: %s</p></i>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_VIEW_CART', 'View Cart');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_BUTTON_CHECKOUT', '<i class="fa fa-angle-right"></i> Checkout');
Link to comment
Share on other sites

and here is the complimenting navbar shopping cart to go with the button.....

 

For \includes\modules\navbar_modules\nb_fancy_shopping_cart.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  class nb_fancy_shopping_cart {
    var $code = 'nb_fancy_shopping_cart';
    var $group = 'navbar_modules_right';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;    
    
    function nb_fancy_shopping_cart() {
      $this->title = MODULE_NAVBAR_FANCY_SHOPPING_CART_TITLE;
      $this->description = MODULE_NAVBAR_FANCY_SHOPPING_CART_DESCRIPTION;

      if ( defined('MODULE_NAVBAR_FANCY_SHOPPING_CART_STATUS') ) {
        $this->sort_order = MODULE_NAVBAR_FANCY_SHOPPING_CART_SORT_ORDER;
        $this->enabled = (MODULE_NAVBAR_FANCY_SHOPPING_CART_STATUS == 'True');
        
        switch (MODULE_NAVBAR_FANCY_SHOPPING_CART_CONTENT_PLACEMENT) {
          case 'Home':
          $this->group = 'navbar_modules_home';
          break;
          case 'Left':
          $this->group = 'navbar_modules_left';
          break;
          case 'Right':
          $this->group = 'navbar_modules_right';
          break;
        } 
      }
    }

    function getOutput() {
      global $oscTemplate, $cart, $currencies;

      $cart_contents_string = '';

      if ($cart->count_contents() > 0) {
        $cart_contents_string = NULL;
        $products = $cart->get_products();
        for ($i=0, $n=sizeof($products); $i<$n; $i++) {
          $cart_contents_string .= '<a href="' . tep_href_link('product_info.php', 'products_id=' . $products[$i]['id']) . '">';
          $cart_contents_string .= $products[$i]['quantity'] . ' x ' . $products[$i]['name'];
		  $cart_contents_string .= '</a>';
        }
	  }
      
      ob_start();
      require('includes/modules/navbar_modules/templates/fancy_shopping_cart.php');
      $data = ob_get_clean();

      $oscTemplate->addBlock($data, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_NAVBAR_FANCY_SHOPPING_CART_STATUS');
    }

    function install() {
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Shopping Cart Module', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_STATUS', 'True', 'Do you want to add the module to your Navbar?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_CONTENT_PLACEMENT', 'Right', 'Should the module be loaded in the Left or Right or the Home area of the Navbar?', '6', '1', 'tep_cfg_select_option(array(\'Left\', \'Right\', \'Home\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_SORT_ORDER', '550', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_NAVBAR_FANCY_SHOPPING_CART_STATUS', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_CONTENT_PLACEMENT', 'MODULE_NAVBAR_FANCY_SHOPPING_CART_SORT_ORDER');
    }
  }

For \includes\modules\navbar_modules\templates\fancy_shopping_cart.php

<?php
   if ($cart->count_contents() > 0) {
  ?>
  <li class="dropdown hidden-xs">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo sprintf(MODULE_NAVBAR_FANCY_SHOPPING_CART_CONTENTS, $cart->count_contents()); ?></a>
    <ul class="dropdown-menu ">
      <li><?php echo '<a href="' . tep_href_link('shopping_cart.php') . '">' . sprintf(MODULE_NAVBAR_FANCY_SHOPPING_CART_HAS_CONTENTS, $cart->count_contents(), $currencies->format($cart->show_total())) . '</a>'; ?></li>
      <li role="separator" class="divider"></li>
      <li><?php echo  $cart_contents_string ; ?></li>
      <li role="separator" class="divider"></li>

    <div class="buttonSet">
    <div class="text-center"><?php echo tep_draw_button(IMAGE_BUTTON_CHECKOUT, 'fa fa-truck', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'primary', NULL, 'btn-success'); ?></div>
    </div>
	
	<?php
      if ( !defined('MODULE_PAYMENT_INSTALLED') || !tep_not_null(MODULE_PAYMENT_INSTALLED) || !in_array('paypal_express.php', explode(';', MODULE_PAYMENT_INSTALLED)) || !defined('OSCOM_APP_PAYPAL_EC_STATUS') || !in_array(OSCOM_APP_PAYPAL_EC_STATUS, array('1', '0')) ) {

        $this->enabled = false;

      }else{
		  
	  ?>
  <div class="clearfix"></div>
  <p class="text-center"><?php echo " -OR- " ?></p>
<p class="text-center"><?php echo '<a href="' . tep_href_link('ext/modules/payment/paypal/express.php', '', 'SSL') . '">' . '<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png" border="0" alt="" title="Check out with PayPal (paypal_express; Sandbox)" />' . '</a>' ?> </p>

  <?php
	  }
	  ?>
    </ul>
  </li>
<?php
}
else {
  echo '<li class="hidden-xs"> <a class="dropdown-toggle">' . MODULE_NAVBAR_FANCY_SHOPPING_CART_NO_CONTENTS . '</a></li>';
}
?>

And for \includes\languages\english\modules\navbar_modules\nb_fancy_shopping_cart.php

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com 

  Copyright (c) 2016 osCommerce

  Released under the GNU General Public License
*/

  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_TITLE', 'Fancy Shopping Cart');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_DESCRIPTION', 'Show Fancy Shopping Cart in Navbar');
  
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_CONTENTS', '<i class="fa fa-shopping-cart"></i><span class="badge"> %s</span> <span class="caret"></span>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_NO_CONTENTS', '<i class="fa fa-shopping-cart"></i><span class="badge"> 0 </span>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_HAS_CONTENTS', '<i class="small"> %s item(s) in your cart <p>Total: %s</p></i>');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_VIEW_CART', 'View Cart');
  define('MODULE_NAVBAR_FANCY_SHOPPING_CART_CHECKOUT', '<i class="fa fa-angle-right"></i> Checkout');
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...