Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Exclude cod payment in some products/attributes


metaminas2015

Recommended Posts

I'm using the osCommerce 2.2rc2a I'm trying to exclude cod.php payment method from certain products_id and/or attributes.

 

I've found those topics:

- http://www.oscommerce.com/forums/topic/324732-specific-product-to-have-specific-payment-option/

http://www.oscommerce.com/forums/topic/395429-restricting-certain-products-from-paypal-payments/

 

But it didn't worked, I've trying for days using this way: if ( ($cart->in_cart(259)) || ($cart->in_cart(259)) ) $this->enabled = false; but without success.

 

Also trying to check which $products_options['products_options_values_name'] is the products to exclude the payment, could someone help me?

Link to comment
Share on other sites

Hello Andre @@metaminas2015,

 

If you do this check in checkout_payment.php you'll better done with the order class.

If its the product id, I think you can just check by:

!in_array('259', $order->products['id'])

supposing 259 is the product id

 

If it's for attribute, you 'll need to loop through all products in the order and check for the attribute id.

You can take the example of the product list in checkout_confirmation.php how to do it:

  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
     
    // here you could do a simple check for product id:
    if ($order->products[$i]['id'] == '259') {
      $this->enabled = false;
    }

    if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
      for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

        // do here your attribute check

      }
    }
  }

Hope this helps

rgds

Rainer

Link to comment
Share on other sites

Hello @@raiwa thanks for replying. I got this piece of code in checkout_payment.php:
 
 
 

<?php
    $selection = $payment_modules->selection();
 
    if (sizeof($selection) > 1) {
?>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="100%"><?php echo TEXT_SELECT_PAYMENT_METHOD; ?></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
<?php
    } else {
?>
              <tr>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td class="main" width="100%" colspan="2"><?php echo TEXT_ENTER_PAYMENT_INFORMATION; ?></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
<?php
    }
 
    $radio_buttons = 0;
    for ($i=0, $n=sizeof($selection); $i<$n; $i++) {
 
    $mostra = 1;
    if ($selection[$i]['id'] == "cod"){
        if ($order->info['total'] > 45){
            $mostra = 0;
        }
    };
 
    if ($mostra == 1){
?>

I was trying to add a OR statement that if 1 or 2 products_id where in cart to exclude the cod payment method.

In the end it removes the cod from the avaliable payments if order is bigger than 45€ I've been trying insert the code you gave but without success.

There's nothing on error_log so I can't figure out what's missing.

Link to comment
Share on other sites

Hello Andre @@metaminas2015,

 

The code I gave is not complete, it's just an example to give you a starting point in the right directions. It is thought to be used in the cod module, not in the checkout_payment page.

But, of course, it's supposed you have a minimum of coding knowledge. If you do not have the required coding skills, you should consider to post in the comercial support forum for (payed for) help.

 

rgds

Rainer

Link to comment
Share on other sites

I know and I appreciate your help. I think the problem can be the ID.. This is a ID that I'm trying in other pages after add it to cart it shows this way 591{20}165{18}145{17}126{19}151

 

Array
(
[qty] => 1
[name] => Geracao a Rasca
[model] =>
[image] => geracao-a-rasca-tshirts-portugal.png
[tax] => 20
[tax_description] => IVA 23%
[price] => 10.8333
[final_price] => 10.8333
[weight] => 0.00
[id] => 591{20}165{18}145{17}126{19}151
[attributes] => Array
(

 

EDIT:

It worked.. But then it failed in a new one due the ID changed to 591{20}165{18}145{17}126{19}152 (changed the last number)

I'm not sure how to prevent this now..

Link to comment
Share on other sites

@@raiwa the difficult part is now to check the attributes..

 

Array
(
    [qty] => 1
    [name] => .Mr Mickey T-shirt
    [model] => 
    [image] => blusa-mr-mrs-blusao-sweat-camisolas-portugal.png
    [tax] => 20
    [tax_description] => IVA 23%
    [price] => 10.8333
    [final_price] => 16.6666
    [weight] => 0.00
    [id] => 1342{18}135{17}132{19}147
    [attributes] => Array
        (
            [0] => Array
                (
                    [option] => s_cor_produto
                    [value] => branco
                    [option_id] => 18
                    [value_id] => 135
                    [prefix] => +
                    [price] => 0.0000
                )


            [1] => Array
                (
                    [option] => s_produto
                    [value] => sweatshirt_crianca
                    [option_id] => 17
                    [value_id] => 132
                    [prefix] => +
                    [price] => 5.8333
                )


            [2] => Array
                (
                    [option] => s_tamanho_produto
                    [value] => 6_anos
                    [option_id] => 19
                    [value_id] => 147
                    [prefix] => +
                    [price] => 0.0000
                )


        )


)

This is what I got, in can have 1 or 4 subarrays I tried to check in attributes if the key [option] has the value => s_produto and the [value] => sweatshirt_crianca but can't set it working, someone could help me?

Link to comment
Share on other sites

Hello Andre @@metaminas2015,

 

If you had a look in the products options loop in checkout_confirmation.php you'll find all what you need:

    if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
      for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
        echo '<br /><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
      }
    }

So if you do the check in the attribute loop I posted in my first reply you can just use this:

 

$order->products[$i]['attributes'][$j]['option'] for to check if the attribute option is equal to: 's_produto'

and

$order->products[$i]['attributes'][$j]['value'] for to check if the attribute value is equal to: 'sweatshirt_crianca'

 

hope this helps

 

rgds

Rainer

Link to comment
Share on other sites

Hello @@raiwa

I'm trying as you said but isn't working.. this is what I got

 

      for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
        if ($order->products[$i]['weight'] > '0.00') {
          $this->enabled = false;
          // This is a hack because [id] => 1342{18}135{17}132{19}147
          // And as products doesn't have weight when I need to exclude them from cod.php I set some weight..
        }


        if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
          for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
            if ($order->products[$i]['attributes'][$j]['option'] == 's_produto') {
              if ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirt_crianca') || ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirtc_crianca_capuz') {
                if ($order->products[$i]['attributes'][$j]['option'] == 's_tamanho_produto') && ($order->products[$i]['attributes'][$j]['value'] != '14_anos') {
                  // This is the worst part 14_anos belong to [option] => s_tamanho_produto but even without this if statement isn't working don't know what is going on
                  $this->enabled = false;
                }
              }
            }
          }
        }
      }
Link to comment
Share on other sites

Hello @@metaminas2015,

 

you have to do this different, you can't wrap a second option condition  inside a option condition, the loop checks one by one. I think you have to do it using a kind of flag system.

 

rgds

Rainer

Link to comment
Share on other sites

Here's is my cod.php.. The weigth stuff works fine but the attributes isn't working correctly.

Thanks for you help @@raiwa hope you or somebody could help me fixing this to exclude the respetive products that contains this attributes to disable this payment method.

<?php
/*
  $Id: cod.php 1739 2007-12-20 00:52:16Z hpdl $


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


  Copyright (c) 2003 osCommerce


  Released under the GNU General Public License
*/


  class cod {
    var $code, $title, $description, $enabled;


// class constructor
    function cod() {
      global $order;


      $this->code = 'cod';
      $this->title = MODULE_PAYMENT_COD_TEXT_TITLE;
      $this->description = MODULE_PAYMENT_COD_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_PAYMENT_COD_SORT_ORDER;
      $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);


      if ((int)MODULE_PAYMENT_COD_ORDER_STATUS_ID > 0) {
        $this->order_status = MODULE_PAYMENT_COD_ORDER_STATUS_ID;
      }


      if (is_object($order)) $this->update_status();
    }


// class methods
    function update_status() {
      global $order;


      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_COD_ZONE > 0) ) {
        $check_flag = false;
        $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_COD_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while ($check = tep_db_fetch_array($check_query)) {
          if ($check['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
        }


        if ($check_flag == false) {
          $this->enabled = false;
        }
      }


      // Products with > 0.00 height are excluded
      for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
        if ($order->products[$i]['weight'] > '0.00') {
          $this->enabled = false;
        }
        // Specific attributes are also excluded
        if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
          for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
            // Attribute check
            if ($order->products[$i]['attributes'][$j]['option'] == 's_produto') {
              if ( ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirt_crianca') || ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirtc_crianca_capuz') ) {
                if ( ($order->products[$i]['attributes'][$j]['option'] == 's_tamanho_produto') && ($order->products[$i]['attributes'][$j]['value'] != '14_anos') ) {
                  $this->enabled = false;
                }
              }
            }
          }
      }


      // disable the module if the order only contains virtual products
      if ($this->enabled == true) {
        if ($order->content_type == 'virtual') {
          $this->enabled = false;
        }
      }
    }


    function javascript_validation() {
      return false;
    }


    function selection() {
      return array('id' => $this->code,
                   'module' => $this->title);
    }


    function pre_confirmation_check() {
      return false;
    }


    function confirmation() {
      //return false;
      return array('title' => MODULE_PAYMENT_COD_TEXT_DESCRIPTION);
    }


    function process_button() {
      return false;
    }


    function before_process() {
      return false;
    }


    function after_process() {
      return false;
    }


    function get_error() {
      return false;
    }


    function check() {
      if (!isset($this->_check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_COD_STATUS'");
        $this->_check = tep_db_num_rows($check_query);
      }
      return $this->_check;
    }


    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Cash On Delivery Module', 'MODULE_PAYMENT_COD_STATUS', 'True', 'Do you want to accept Cash On Delevery payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_COD_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_COD_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_COD_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
   }


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


    function keys() {
      return array('MODULE_PAYMENT_COD_STATUS', 'MODULE_PAYMENT_COD_ZONE', 'MODULE_PAYMENT_COD_ORDER_STATUS_ID', 'MODULE_PAYMENT_COD_SORT_ORDER');
    }
  }
?>
Link to comment
Share on other sites

EDIT:

 

Well, I could set it check something but if I try to check if != doesn't work..

 

      // Products with > 0.00 height are excluded
      for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
        if ($order->products[$i]['weight'] > '0.00') {
          $this->enabled = false;
        }
        // Specific attributes are also excluded
        if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
          for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
            // Attribute check
            if ( ($order->products[$i]['attributes'][$j]['option'] == 's_produto') && ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirt_crianca') ) {
              // DONT WORK IF I TRY TO PERFORM THIS CHECK
              //if ( ($order->products[$i]['attributes'][$j]['option'] == 's_tamanho_produto') && ($order->products[$i]['attributes'][$j]['value'] != '14_anos') ) {
                $this->enabled = false;
              //}
            }
            else if ( ($order->products[$i]['attributes'][$j]['option'] == 's_produto') && ($order->products[$i]['attributes'][$j]['value'] == 'sweatshirtc_crianca_capuz') ) {
              // DONT WORK IF I TRY TO PERFORM THIS CHECK
              //if ( ($order->products[$i]['attributes'][$j]['option'] == 's_tamanho_produto') && ($order->products[$i]['attributes'][$j]['value'] != '14_anos') ) {
                $this->enabled = false;
              }
            }
          }
        }
      }
Link to comment
Share on other sites

  • 3 weeks later...

Archived

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

×
×
  • Create New...