PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/wordpress/wp-content/plugins/thecartpress/widgets/ResumenShoppingCartWidget.class.php

http://ownerpress.googlecode.com/
PHP | 110 lines | 90 code | 4 blank | 16 comment | 8 complexity | 4f85d653a8928adee3da56059a6af4f4 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * This file is part of TheCartPress.
  4. *
  5. * TheCartPress is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * TheCartPress is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with TheCartPress. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. class ResumenShoppingCartWidget extends WP_Widget {
  19. function ResumenShoppingCartWidget() {
  20. $widget = array(
  21. 'classname' => 'resumenshoppingcart',
  22. 'description' => __( 'Use this widget to add a resume of the shopping cart', 'tcp' ),
  23. );
  24. $control = array(
  25. 'width' => 300,
  26. 'id_base' => 'resumenshoppingcart-widget',
  27. );
  28. $this->WP_Widget( 'resumenshoppingcart-widget', 'TCP Resume shopping cart', $widget, $control );
  29. }
  30. function widget( $args, $instance ) {
  31. extract( $args );
  32. $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '');
  33. echo $before_widget;
  34. if ( $title ) echo $before_title, $title, $after_title;
  35. $settings = get_option( 'tcp_settings' );
  36. $currency = isset( $settings['currency'] ) ? $settings['currency'] : 'EUR';
  37. $stock_management = isset( $settings['stock_management'] ) ? $settings['stock_management'] : false;
  38. $shoppingCart = TheCartPress::getShoppingCart();?>
  39. <ul class="tcp_shopping_cart_resume">
  40. <li><span class="tcp_resumen_subtotal"><?php _e( 'Total', 'tcp' );?>:</span>&nbsp;<?php echo number_format( $shoppingCart->getTotal(), 2 );?>&nbsp;<?php echo $currency;?></li>
  41. <li><span class="tcp_resumen_count"><?php _e( 'N?? products:', 'tcp' );?>:</span>&nbsp;<?php echo $shoppingCart->getCount();?></li>
  42. <?php if ( $stock_management && isset( $instance['see_stock_notice'] ) ? $instance['see_stock_notice'] : false ) :
  43. if ( ! $shoppingCart->isThereStock() ) :?>
  44. <li><span class="tcp_no_stock_enough"><?php printf( __( 'No enough stock for some products. Visit the <a href="%s">Shopping Cart</a> to see more details.', 'tcp' ), get_permalink( get_option( 'tcp_shopping_cart_page_id' ) ) );?></span></li>
  45. <?php endif;
  46. endif;?>
  47. <?php if ( isset( $instance['see_weight'] ) ? $instance['see_weight'] : false ) :?>
  48. <li><span class="tcp_resumen_weight"><?php _e( 'Weigth', 'tcp' );?>:</span>&nbsp;<?php echo $shoppingCart->getWeight();?>&nbsp;<?php echo $currency;?></li>
  49. <?php endif;?>
  50. <?php if ( isset( $instance['see_shopping_cart'] ) ? $instance['see_shopping_cart'] : true ) :?>
  51. <li><a href="<?echo get_permalink( get_option( 'tcp_shopping_cart_page_id' ) );?>"><?php _e( 'Shopping cart', 'tcp' );?></a></li>
  52. <?php endif;?>
  53. <?php if ( isset( $instance['see_checkout'] ) ? $instance['see_checkout'] : true ) :?>
  54. <li><a href="<?echo get_permalink( get_option( 'tcp_checkout_page_id' ) );?>"><?php _e( 'Checkout', 'tcp' );?></a></li>
  55. <?php endif;?>
  56. </ul>
  57. <?php if ( isset( $instance['see_delete_all'] ) ? $instance['see_delete_all'] : false ) :?>
  58. <form method="post"><input type="submit" name="tcp_delete_shopping_cart" value="<?php _e( 'Delete shopping cart', 'tcp' );?>"/></form>
  59. <?php endif;?>
  60. <?php echo $after_widget;
  61. }
  62. function update( $new_instance, $old_instance ) {
  63. $instance = $old_instance;
  64. $instance['title'] = strip_tags( $new_instance['title'] );
  65. $instance['see_stock_notice'] = isset( $new_instance['see_stock_notice'] ) ? true : false;
  66. $instance['see_weight'] = isset( $new_instance['see_weight'] ) ? true : false;
  67. $instance['see_delete_all'] = isset( $new_instance['see_delete_all'] ) ? true : false;
  68. $instance['see_shopping_cart'] = isset( $new_instance['see_shopping_cart'] ) ? true : false;
  69. $instance['see_checkout'] = isset( $new_instance['see_checkout'] ) ? true : false;
  70. return $instance;
  71. }
  72. function form( $instance ) {
  73. $defaults = array(
  74. 'title' => __( 'Resume', 'tcp' ),
  75. 'see_weight' => true,
  76. 'see_delete_all' => true,
  77. );
  78. $see_stock_notice = isset( $instance['see_stock_notice'] ) ? (bool)$instance['see_stock_notice'] : false;
  79. $see_weight = isset( $instance['see_weight'] ) ? (bool)$instance['see_weight'] : false;
  80. $see_delete_all = isset( $instance['see_delete_all'] ) ? (bool)$instance['see_delete_all'] : false;
  81. $see_shopping_cart = isset( $instance['see_shopping_cart'] ) ? (bool)$instance['see_shopping_cart'] : false;
  82. $see_checkout = isset( $instance['see_checkout'] ) ? (bool)$instance['see_checkout'] : false;
  83. $instance = wp_parse_args( ( array ) $instance, $defaults );?>
  84. <p>
  85. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'tcp' )?>:</label>
  86. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
  87. </p><p>
  88. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('see_stock_notice'); ?>" name="<?php echo $this->get_field_name( 'see_stock_notice' ); ?>"<?php checked( $see_stock_notice ); ?> />
  89. <label for="<?php echo $this->get_field_id( 'see_stock_notice' ); ?>"><?php _e('See stock notice', 'tcp'); ?></label>
  90. <br />
  91. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('see_weight'); ?>" name="<?php echo $this->get_field_name( 'see_weight' ); ?>"<?php checked( $see_weight ); ?> />
  92. <label for="<?php echo $this->get_field_id( 'see_weight' ); ?>"><?php _e('See weigth', 'tcp'); ?></label>
  93. <br />
  94. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('see_delete_all'); ?>" name="<?php echo $this->get_field_name( 'see_delete_all' ); ?>"<?php checked( $see_delete_all ); ?> />
  95. <label for="<?php echo $this->get_field_id( 'see_delete_all' ); ?>"><?php _e('See delete button', 'tcp'); ?></label>
  96. <br />
  97. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('see_shopping_cart'); ?>" name="<?php echo $this->get_field_name( 'see_shopping_cart' ); ?>"<?php checked( $see_shopping_cart ); ?> />
  98. <label for="<?php echo $this->get_field_id( 'see_shopping_cart' ); ?>"><?php _e('See shopping cart link', 'tcp'); ?></label>
  99. <br />
  100. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('see_checkout'); ?>" name="<?php echo $this->get_field_name( 'see_checkout' ); ?>"<?php checked( $see_checkout ); ?> />
  101. <label for="<?php echo $this->get_field_id( 'see_checkout' ); ?>"><?php _e('See checkout link', 'tcp'); ?></label>
  102. </p>
  103. <?php
  104. }
  105. }
  106. ?>