Jump to content
Sign in to follow this  
boxtel

Order Re-Order Contribution Support

Recommended Posts

Contribution :

http://www.oscommerce.com/community/contributions,3407

 

 

change:

to reduce the attributes query from 3 to 1 per product use this function.

It is a join of the 3 separate queries to determine the attribute id's based on the attribute names stored in the order information.

 

function tep_reorder ($orders_id) {

 

global $cart, $languages_id;

 

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

op.orders_products_id,

op.products_quantity,

p.products_status,

p.products_model,

p.products_quantity as stock,

pd.products_name

from " . TABLE_ORDERS_PRODUCTS . " op, " .

TABLE_PRODUCTS . " p, " .

TABLE_PRODUCTS_DESCRIPTION . " pd

where op.orders_id = '" . $orders_id . "' and

op.products_id = p.products_id and

p.products_id = pd.products_id and

pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

if ($ordered_product['products_status'] == '1') {

if (!tep_has_product_attributes($ordered_product['products_id'])) {

if ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity'])) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

}

} else {

$attributes = array();

$attributes_count = 0;

$attributes_query = tep_db_query("select po.products_options_id ,

pov.products_options_values_id

from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

" . TABLE_PRODUCTS_OPTIONS . " po,

" . TABLE_PRODUCTS_OPTIONS_VALUES . " pov

where opa.orders_id = '" . $orders_id . "' and

opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

po.products_options_name = opa.products_options and

po.language_id = '" . $languages_id . "' and

pov.products_options_values_name = opa.products_options_values and

pov.language_id = '" . $languages_id . "'");

 

while ($attribute = tep_db_fetch_array($attributes_query)) {

$attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

$attributes_count++;

}

 

if ($attributes_count == 0) {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

}

 

if ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'])) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

}

}

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not Available<br>';

}

}

return $result;

}


Treasurer MFC

Share this post


Link to post
Share on other sites

thanks

everything works for me

i have been looking for this for a long time

now i have to figure out how to put it in the index page so the customer reorder his last order or maybe even see what the last order was maybe in an info box or a little section on top that say like

your last order was blah blah would you like to reorder that

this would make reordering very easy for regular customers.

Share this post


Link to post
Share on other sites
thanks

everything works for me

i have been looking for this for a long time

now i have to figure out how to put it in the index page so the customer  reorder his last order or maybe even see what the last order was maybe in an info box or a little section on top that say like

your last order was blah blah  would you like to reorder that

this would make reordering very easy for regular customers.

 

I believe there is a standard order history box with osc showing the last x orders.

So whereever you have the orders id, you can call the function.


Treasurer MFC

Share this post


Link to post
Share on other sites

order history box just adds a listing of ordered products i belive so i hacked the account.php and made a simple file

<table border="0" width="100%" cellspacing="0" cellpadding="0">


<?php
 if ($messageStack->size('account') > 0) {
?>
     <tr>
       <td><?php echo $messageStack->output('account'); ?></td>
     </tr>

<?php
 }

 if (tep_count_customer_orders() > 0) {
?>
     <tr>
       <td>


       <table border="0" cellspacing="0" cellpadding="2">
         <tr>

           <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL') . '"><u>' . OVERVIEW_SHOW_ALL_ORDERS . '</u></a>'; ?></td>
         </tr>
       </table>

       </td>
     </tr>
     <tr>
       <td>


       <table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td>



           <table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td class="main" align="center" valign="top" ><?php echo '<b>' . 'choose' . '</b><br>' . tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?></td>
               <td>


               <table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php

   $orders_query = tep_db_query("select o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id  . "' order by orders_id desc limit 3");
   while ($orders = tep_db_fetch_array($orders_query)) {
     if (tep_not_null($orders['delivery_name'])) {
       $order_name = $orders['delivery_name'];
       $order_country = $orders['delivery_country'];
     } else {
       $order_name = $orders['billing_name'];
       $order_country = $orders['billing_country'];
     }
?>
                 <tr class="moduleRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="document.location.href='<?php echo tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL'); ?>'">
                <td class="main" width="80"><?php echo tep_date_short($orders['date_purchased']); ?></td>

                   <td class="main"><?php echo 'order#' . $orders['orders_id']; ?></td>

                   <td class="main" align="right"><?php echo $orders['order_total']; ?></td>

                   <td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL') . '">' . tep_image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW) . '</a>'; ?></td>
                    <?php echo tep_draw_form('order_reorder', tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', 'SSL'));
echo '<td valign="middle" align="center">' . tep_image_submit('button_in_cart.gif', 'Re-Order','','update_button') . '</td>';
echo '</form>'; ?>
                 </tr>
<?php
   }
?>
            </table>  </td>   </tr> </table>   </td></tr> </table>


<?php
 }
?>
     </td></tr> </table>

i called it reorder.php and put it in modules directory this way i can call it any where i want ofcourse if you want to put it in a box you must edit it a bit so the widh be acceptable

thank you again for this great contribution

Share this post


Link to post
Share on other sites
I believe there is a standard order history box with osc showing the last x orders.

So whereever you have the orders id, you can call the function.

Hello,

 

I can't find where should I put in account_history_info

 

echo tep_draw_form('order_reorder', tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_GET['order_id'] . '&action=reorder'));

echo '<td valign="middle" align="center">' . tep_image_submit('button_in_cart.gif', 'Re-Order','','update_button') . '</td>';

echo '</form>';

 

What means Step 4) in instructions:

4) better also add some indexes to the fields in the where clauses of the queries above.

I'll appreciate your advices. Thanks,

Irina.

Share this post


Link to post
Share on other sites

Hi,

 

Please disregard my previous post. I've found it already.

I have a question: how can I add Reorder function to account.php, so when customer goes to 'My account' near View previous orders, he can have an option to reorder the exact same order.

 

Thanks in advance,

Irina.

Share this post


Link to post
Share on other sites

look in the code i posted above

this is a cut out of from acount.php

notice the change in order_id

Share this post


Link to post
Share on other sites
look in the code i posted above

this is a cut out of  from acount.php

notice the change in order_id

Thanks for your reply, nana. I added this code to acount.php, but when I click 'Add to Cart' from acount.php, the reorder function doesn't work, just lists the previous order. What have I done wrong?

 

Thanks,

Irina.

Share this post


Link to post
Share on other sites

i had the same problem for some reason i was not getting action=reorder in the url i had to add ssl to the code make sure you have ssl or maybe nonssl would work also

<?php echo tep_draw_form('order_reorder', tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', 'SSL'));
echo '<td valign="middle" align="center">' . tep_image_submit('button_in_cart.gif', 'Re-Order','','update_button') . '</td>';
echo '</form>'; ?>

Share this post


Link to post
Share on other sites

or maybe removing the ssl if you don;t have a certificate. that was my problem look in the url and see if you see axtion=reorder maybe amanda knows what is causing the problem and what the fix is

Edited by nana

Share this post


Link to post
Share on other sites
or maybe removing the ssl if you don;t have a certificate. that was my problem look in the url and see if you see axtion=reorder maybe amanda knows what is causing the problem and what the fix is

I don't have a certificate, however, I don't think this is a problem because I have SSL everywhere through acount.php.

Have you got it working?

 

Regards,

Irina.

Share this post


Link to post
Share on other sites
I don't have a certificate, however, I don't think this is a problem because I have SSL everywhere through acount.php.

Have you got it working?

 

Regards,

Irina.

 

it should work when after this in acount.php :

 

<td class="main"><?php echo tep_output_string_protected($order_name) . ', ' . $order_country; ?></td>

<td class="main"><?php echo $orders['orders_status_name']; ?></td>

<td class="main" align="right"><?php echo $orders['order_total']; ?></td>

<td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL') . '">' . tep_image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW) . '</a>'; ?></td>

 

you add this :

 

<td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', 'SSL') . '">' . tep_image_button('button_buy_now.gif', 'Reorder') . '</a>'; ?></td>


Treasurer MFC

Share this post


Link to post
Share on other sites
it should work when after this in acount.php :

 

                    <td class="main"><?php echo tep_output_string_protected($order_name) . ', ' . $order_country; ?></td>

                    <td class="main"><?php echo $orders['orders_status_name']; ?></td>

                    <td class="main" align="right"><?php echo $orders['order_total']; ?></td>

                    <td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'], 'SSL') . '">' . tep_image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW) . '</a>'; ?></td>

 

you add this :

 

                    <td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', 'SSL') . '">' . tep_image_button('button_buy_now.gif', 'Reorder') . '</a>'; ?></td>

I have added the above code to acount.php. Now, when I go to acount.php, I have 'Buy Now' button near 'View Previous Order'. When I press 'Buy Now', the Order Details shows up with the 'Add to Cart' button underneath the order. When I press 'Add to Cart', it just refreshes the page but no product has been added to cart.

 

Thanks,

Irina.

Share this post


Link to post
Share on other sites
I have added the above code to acount.php. Now, when I go to acount.php, I have 'Buy Now' button near 'View Previous Order'. When I press 'Buy Now', the Order Details shows up with the 'Add to Cart' button underneath the order. When I press 'Add to Cart', it just refreshes the page but no product has been added to cart.

 

Thanks,

Irina.

 

make sure you have this code in application_top.php

 

case 'reorder' : $reorder_result = tep_reorder($_GET['order_id']);

if ($reorder_result == '') {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

} else {

echo $reorder_result;

}

break;

 

it will print out the reasons why the products were not added to the card.


Treasurer MFC

Share this post


Link to post
Share on other sites
make sure you have this code in application_top.php

 

      case 'reorder' :        $reorder_result = tep_reorder($_GET['order_id']);

                              if ($reorder_result == '') {

                                tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

                              } else {

                                echo $reorder_result;

                              }

                              break;

 

it will print out the reasons why the products were not added to the card.

 

 

This version of the function in general.php will follow your "allow checkout if not enough stock" setting.

 

The current version does not add the product if there is not enough stock for it.

 

 

function tep_reorder ($orders_id) {

 

global $cart, $languages_id;

 

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

op.orders_products_id,

op.products_quantity,

p.products_status,

p.products_model,

p.products_quantity as stock,

pd.products_name

from " . TABLE_ORDERS_PRODUCTS . " op, " .

TABLE_PRODUCTS . " p, " .

TABLE_PRODUCTS_DESCRIPTION . " pd

where op.orders_id = '" . $orders_id . "' and

op.products_id = p.products_id and

p.products_id = pd.products_id and

pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

if ($ordered_product['products_status'] == '1') {

if (!tep_has_product_attributes($ordered_product['products_id'])) {

if ((STOCK_ALLOW_CHECKOUT) or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

}

} else {

$attributes = array();

$attributes_count = 0;

$attributes_query = tep_db_query("select po.products_options_id ,

pov.products_options_values_id

from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

" . TABLE_PRODUCTS_OPTIONS . " po,

" . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

" . TABLE_PRODUCTS_ATTRIBUTES . " pa

where opa.orders_id = '" . $orders_id . "' and

opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

po.products_options_name = opa.products_options and

po.language_id = '" . $languages_id . "' and

pa.options_id = po.products_options_id and

pa.options_values_id = pov.products_options_values_id and

pa.products_id = '" . $ordered_product['products_id'] . "' and

pov.products_options_values_name = opa.products_options_values and

pov.language_id = '" . $languages_id . "'");

 

while ($attribute = tep_db_fetch_array($attributes_query)) {

$attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

$attributes_count++;

}

 

if ($attributes_count < 1) {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

}

 

if ((STOCK_ALLOW_CHECKOUT) or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

}

}

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not Available<br>';

}

}

if ($result != '') {

$result = 'Reorder incomplete<br>' . $result;

}

return $result;

}


Treasurer MFC

Share this post


Link to post
Share on other sites
This version of the function in general.php will follow your "allow checkout if not enough stock" setting.

 

The current version does not add the product if there is not enough stock for it.

function tep_reorder ($orders_id) {

 

  global $cart, $languages_id;

 

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

                                              op.orders_products_id,

                                              op.products_quantity,

                                              p.products_status,

                                              p.products_model,

                                              p.products_quantity as stock,

                                              pd.products_name

                                        from " . TABLE_ORDERS_PRODUCTS . " op, " .

                                                TABLE_PRODUCTS . " p, " .

                                                TABLE_PRODUCTS_DESCRIPTION . " pd

                                        where op.orders_id = '" . $orders_id . "' and

                                              op.products_id = p.products_id and

                                              p.products_id = pd.products_id and

                                              pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

  if ($ordered_product['products_status'] == '1') {

      if (!tep_has_product_attributes($ordered_product['products_id'])) {

        if ((STOCK_ALLOW_CHECKOUT) or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

        } else {

            $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

        }

      } else {

          $attributes = array();

          $attributes_count = 0;

          $attributes_query = tep_db_query("select po.products_options_id ,

                                                    pov.products_options_values_id

                                            from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

                                                  " . TABLE_PRODUCTS_OPTIONS . " po,

                                                  " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

                                                  " . TABLE_PRODUCTS_ATTRIBUTES . " pa

                                            where opa.orders_id = '" . $orders_id . "' and

                                                  opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

                                                  po.products_options_name = opa.products_options and

                                                  po.language_id = '" . $languages_id . "' and

                                                  pa.options_id =  po.products_options_id and

                                                  pa.options_values_id = pov.products_options_values_id and

                                                  pa.products_id = '" . $ordered_product['products_id'] . "' and

                                                  pov.products_options_values_name = opa.products_options_values and

                                                  pov.language_id = '" . $languages_id . "'");

 

          while ($attribute = tep_db_fetch_array($attributes_query)) {

                $attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

                $attributes_count++;

          }

 

          if ($attributes_count < 1) {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

          }

 

          if ((STOCK_ALLOW_CHECKOUT) or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

          } else {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

          }

      }

  } else {

      $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not Available<br>';

  }

}

if ($result != '') {

  $result = 'Reorder incomplete<br>' . $result;

}

return $result;

}

 

 

 

Correction, this switch is of the string kind :

 

 

 

function tep_reorder ($orders_id) {

 

global $cart, $languages_id;

 

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

op.orders_products_id,

op.products_quantity,

p.products_status,

p.products_model,

p.products_quantity as stock,

pd.products_name

from " . TABLE_ORDERS_PRODUCTS . " op, " .

TABLE_PRODUCTS . " p, " .

TABLE_PRODUCTS_DESCRIPTION . " pd

where op.orders_id = '" . $orders_id . "' and

op.products_id = p.products_id and

p.products_id = pd.products_id and

pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

if ($ordered_product['products_status'] == '1') {

if (!tep_has_product_attributes($ordered_product['products_id'])) {

if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

}

} else {

$attributes = array();

$attributes_count = 0;

$attributes_query = tep_db_query("select po.products_options_id ,

pov.products_options_values_id

from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

" . TABLE_PRODUCTS_OPTIONS . " po,

" . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

" . TABLE_PRODUCTS_ATTRIBUTES . " pa

where opa.orders_id = '" . $orders_id . "' and

opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

po.products_options_name = opa.products_options and

po.language_id = '" . $languages_id . "' and

pa.options_id = po.products_options_id and

pa.options_values_id = pov.products_options_values_id and

pa.products_id = '" . $ordered_product['products_id'] . "' and

pov.products_options_values_name = opa.products_options_values and

pov.language_id = '" . $languages_id . "'");

 

while ($attribute = tep_db_fetch_array($attributes_query)) {

$attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

$attributes_count++;

}

 

if ($attributes_count < 1) {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

}

 

if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

}

}

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not Available<br>';

}

}

if ($result != '') {

$result = 'Reorder incomplete<br>' . $result;

}

return $result;

}


Treasurer MFC

Share this post


Link to post
Share on other sites
Correction, this switch is of the string kind :

function tep_reorder ($orders_id) {

 

  global $cart, $languages_id;

 

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

                                              op.orders_products_id,

                                              op.products_quantity,

                                              p.products_status,

                                              p.products_model,

                                              p.products_quantity as stock,

                                              pd.products_name

                                        from " . TABLE_ORDERS_PRODUCTS . " op, " .

                                                TABLE_PRODUCTS . " p, " .

                                                TABLE_PRODUCTS_DESCRIPTION . " pd

                                        where op.orders_id = '" . $orders_id . "' and

                                              op.products_id = p.products_id and

                                              p.products_id = pd.products_id and

                                              pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

  if ($ordered_product['products_status'] == '1') {

      if (!tep_has_product_attributes($ordered_product['products_id'])) {

        if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

        } else {

            $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

        }

      } else {

          $attributes = array();

          $attributes_count = 0;

          $attributes_query = tep_db_query("select po.products_options_id ,

                                                    pov.products_options_values_id

                                            from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

                                                  " . TABLE_PRODUCTS_OPTIONS . " po,

                                                  " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

                                                  " . TABLE_PRODUCTS_ATTRIBUTES . " pa

                                            where opa.orders_id = '" . $orders_id . "' and

                                                  opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

                                                  po.products_options_name = opa.products_options and

                                                  po.language_id = '" . $languages_id . "' and

                                                  pa.options_id =  po.products_options_id and

                                                  pa.options_values_id = pov.products_options_values_id and

                                                  pa.products_id = '" . $ordered_product['products_id'] . "' and

                                                  pov.products_options_values_name = opa.products_options_values and

                                                  pov.language_id = '" . $languages_id . "'");

 

          while ($attribute = tep_db_fetch_array($attributes_query)) {

                $attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

                $attributes_count++;

          }

 

          if ($attributes_count < 1) {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

          }

 

          if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

          } else {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

          }

      }

  } else {

      $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not Available<br>';

  }

}

if ($result != '') {

  $result = 'Reorder incomplete<br>' . $result;

}

return $result;

}

Nope, doesn't work either. I have the same code as above, checked all: application_top.php, general.php, acount.php. Everything seems to be ok, but reorder function doesn't work.

 

What else should I check?

Thanks,

Irina.

Share this post


Link to post
Share on other sites
Nope, doesn't work either. I have the same code as above, checked all: application_top.php, general.php, acount.php. Everything seems to be ok, but reorder function doesn't work.

 

What else should I check?

Thanks,

Irina.

 

ok, use this version of the function and tell me if you get any text at the top of the screen after you pressed reorder.

 

 

function tep_reorder ($orders_id) {

 

global $cart, $languages_id;

 

$num_prod = 0;

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

op.orders_products_id,

op.products_quantity,

p.products_status,

p.products_model,

p.products_quantity as stock,

pd.products_name

from " . TABLE_ORDERS_PRODUCTS . " op, " .

TABLE_PRODUCTS . " p, " .

TABLE_PRODUCTS_DESCRIPTION . " pd

where op.orders_id = '" . $orders_id . "' and

op.products_id = p.products_id and

p.products_id = pd.products_id and

pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

$num_prod++;

if ($ordered_product['products_status'] == '1') {

if (!tep_has_product_attributes($ordered_product['products_id'])) {

if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

}

} else {

$attributes = array();

$attributes_count = 0;

$attributes_query = tep_db_query("select po.products_options_id ,

pov.products_options_values_id

from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

" . TABLE_PRODUCTS_OPTIONS . " po,

" . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

" . TABLE_PRODUCTS_ATTRIBUTES . " pa

where opa.orders_id = '" . $orders_id . "' and

opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

po.products_options_name = opa.products_options and

po.language_id = '" . $languages_id . "' and

pa.options_id = po.products_options_id and

pa.options_values_id = pov.products_options_values_id and

pa.products_id = '" . $ordered_product['products_id'] . "' and

pov.products_options_values_name = opa.products_options_values and

pov.language_id = '" . $languages_id . "'");

 

while ($attribute = tep_db_fetch_array($attributes_query)) {

$attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

$attributes_count++;

}

 

if ($attributes_count < 1) {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

}

 

if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

$cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

}

}

} else {

$result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': No longer Available<br>';

}

}

if ($num_prod == 0) {

$result .= 'No products found to add';

}

if ($result != '') {

$result = 'Reorder incomplete<br>' . $result;

}

return $result;

}


Treasurer MFC

Share this post


Link to post
Share on other sites
ok, use this version of the function and tell me if you get any text at the top of the screen after you pressed reorder.

function tep_reorder ($orders_id) {

 

  global $cart, $languages_id;

 

$num_prod = 0;

$result = '';

$ordered_products_query = tep_db_query("select op.products_id,

                                              op.orders_products_id,

                                              op.products_quantity,

                                              p.products_status,

                                              p.products_model,

                                              p.products_quantity as stock,

                                              pd.products_name

                                        from " . TABLE_ORDERS_PRODUCTS . " op, " .

                                                TABLE_PRODUCTS . " p, " .

                                                TABLE_PRODUCTS_DESCRIPTION . " pd

                                        where op.orders_id = '" . $orders_id . "' and

                                              op.products_id = p.products_id and

                                              p.products_id = pd.products_id and

                                              pd.language_id = '" . $languages_id . "'");

 

while ($ordered_product = tep_db_fetch_array($ordered_products_query)) {

  $num_prod++;

  if ($ordered_product['products_status'] == '1') {

      if (!tep_has_product_attributes($ordered_product['products_id'])) {

        if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity($ordered_product['products_id'])+$ordered_product['products_quantity']);

        } else {

            $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock<br>';

        }

      } else {

          $attributes = array();

          $attributes_count = 0;

          $attributes_query = tep_db_query("select po.products_options_id ,

                                                    pov.products_options_values_id

                                            from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa,

                                                  " . TABLE_PRODUCTS_OPTIONS . " po,

                                                  " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov,

                                                  " . TABLE_PRODUCTS_ATTRIBUTES . " pa

                                            where opa.orders_id = '" . $orders_id . "' and

                                                  opa.orders_products_id = '" . $ordered_product['orders_products_id'] . "' and

                                                  po.products_options_name = opa.products_options and

                                                  po.language_id = '" . $languages_id . "' and

                                                  pa.options_id =  po.products_options_id and

                                                  pa.options_values_id = pov.products_options_values_id and

                                                  pa.products_id = '" . $ordered_product['products_id'] . "' and

                                                  pov.products_options_values_name = opa.products_options_values and

                                                  pov.language_id = '" . $languages_id . "'");

 

          while ($attribute = tep_db_fetch_array($attributes_query)) {

                $attributes[$attribute['products_options_id']] = $attribute['products_options_values_id'];

                $attributes_count++;

          }

 

          if ($attributes_count < 1) {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Attributes changed<br>';

          }

 

          if ((STOCK_ALLOW_CHECKOUT == 'true') or ($ordered_product['stock'] >= ($cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity']))) {

          $cart->add_cart($ordered_product['products_id'], $cart->get_quantity(tep_get_uprid($ordered_product['products_id'], $attributes))+$ordered_product['products_quantity'], $attributes);

          } else {

              $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': Not enough stock (attr)<br>';

          }

      }

  } else {

      $result .= 'product: ' . $ordered_product['products_id'] . ' [' . $ordered_product['products_model'] . '] > ' . $ordered_product['products_name'] . ': No longer Available<br>';

  }

}

if ($num_prod == 0) {

  $result .= 'No products found to add';

}

if ($result != '') {

  $result = 'Reorder incomplete<br>' . $result;

}

return $result;

}

I changed the code but I don't get any text at the top of the screen after I press reorder. Does it mean anything to you?

 

Regards,

Irina.

Share this post


Link to post
Share on other sites
I changed the code but I don't get any text at the top of the screen after I press reorder. Does it mean anything to you?

 

Regards,

Irina.

 

normally, if the result has text, it should be shown at the top of the screen and you remain in history info. if the result is empty, you should end up in checkout shipping.

 

The result only has text if not all products were added for some reason.

 

so, please post the code you added in application top and in history info


Treasurer MFC

Share this post


Link to post
Share on other sites

i had a problem like this . it was not passing "action=reorder" in the url

i suggest you also post your url after you click the bottom

Share this post


Link to post
Share on other sites
or maybe removing the ssl if you don;t have a certificate. that was my problem look in the url and see if you see axtion=reorder maybe amanda knows what is causing the problem and what the fix is

 

or try :

 

<td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', $request_type) . '">' . tep_image_button('button_buy_now.gif', 'Reorder') . '</a>'; ?></td>

 

$request_type holds your current SSL/NONSSL status


Treasurer MFC

Share this post


Link to post
Share on other sites
or try :

 

<td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', $request_type) . '">' . tep_image_button('button_buy_now.gif', 'Reorder') . '</a>'; ?></td>

 

$request_type holds your current SSL/NONSSL status

Here is a part with reorder function of my cataolg/includes/application_top.php:

 

// Customer wants to update the product quantity in their shopping cart

      case 'add_wishlist' :  if (ereg('^[0-9]+$', $HTTP_POST_VARS['products_id'])) {

                                if ($HTTP_POST_VARS['products_id']) {

                                  if ($customer_id > 0) {

            // Queries below replace old product instead of adding to queatity.

                                    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . $HTTP_POST_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");

                                    tep_db_query("insert into " . TABLE_WISHLIST . " (customers_id, products_id, products_model, products_name, products_price) values ('" . $customer_id . "', '" . $products_id . "', '" . $products_model . "', '" . $products_name . "', '" . $products_price . "' )");

                                    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . $HTTP_POST_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");

                                    // Read array of options and values for attributes in id[]

                                    if (isset ($id)) {

                                      foreach($id as $att_option=>$att_value) {

                                        // Add to customers_wishlist_attributes table

                                        tep_db_query("insert into " . TABLE_WISHLIST_ATTRIBUTES . " (customers_id, products_id, products_options_id , products_options_value_id) values ('" . $customer_id . "', '" . $products_id . "', '" . $att_option . "', '" . $att_value . "' )");

                                      }

                                    }

                                  }

                                }

                              }

                              break;

 

      case 'wishlist_add_cart' :if (ereg('^[0-9]+$', $HTTP_POST_VARS['products_id'])) {

                                  if ($HTTP_POST_VARS['products_id']) {

                                  if ($customer_id > 0) {

                                    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . $HTTP_POST_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");

                                    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . $HTTP_POST_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");

                                    // Read array of options and values for attributes in id[]

                                    if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

                                      $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);

                                    }

                                    tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

                                    break;

                                  }

                                }

                              }

                              break;

 

      // Wishlist Checkboxes

      case 'add_delete_products_wishlist':

                                      if (isset($HTTP_POST_VARS['add_wishprod'])) {

                                        if ($HTTP_POST_VARS['borrar'] == 0) {

                // 'borrar' form variable refers to deleting products in array $add_wishprod[] from wishlist

                                              foreach ($HTTP_POST_VARS['add_wishprod'] as $value) {

                                                    if (ereg('^[0-9]+$', $value)) {

                                                    $cart->add_cart($value, $cart->get_quantity(tep_get_uprid($value, $HTTP_POST_VARS['id'][$value]))+1, $HTTP_POST_VARS['id'][$value]);

                                                    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = $value and customers_id = '" . $customer_id . "'");

                                                    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '$value' and customers_id = '" . $customer_id . "'");

                                                    }

                                              }

                                            tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

                                        }

                                        if ($HTTP_POST_VARS['borrar'] == 1) {

                                              foreach ($HTTP_POST_VARS['add_wishprod'] as $value) {

                                                    if (ereg('^[0-9]+$', $value)) {

                                                    tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = $value and customers_id = '" . $customer_id . "'");

                                                    tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '$value' and customers_id = '" . $customer_id . "'");

                                                  }

                                              }

                                            tep_redirect(tep_href_link(FILENAME_WISHLIST));

                                        }

                                      }

                                      break;

                                      case 'reorder' : $reorder_result = tep_reorder($_GET['order_id']);

if ($reorder_result == '') {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

} else {

echo $reorder_result;

}

break;

    } // end switch ($HTTP_POST_VARS['wishlist_action'])

  } // end isset($HTTP_POST_VARS)

// *****************************************

// Wish List 2.3 End

 

catalog/account_history_info.php:

 

<tr>

        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '25'); ?></td>

      </tr>

      <tr>

        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

          <tr class="infoBoxContents">

            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

              <tr>

                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

<?php //begin add receipt// ?>

              <td><div style="float:left"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY, tep_get_all_get_params(array('order_id')), 'SSL') . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a></div><div style=float:right>'; ?><a href="java script:popupPrintReceipt('<?php echo tep_href_link(FILENAME_ORDERS_PRINTABLE, tep_get_all_get_params(array('order_id')) . 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'); ?>')"><?php echo tep_image_button('button_print_order.gif', IMAGE_BUTTON_PRINT_ORDER) . '</a>'; ?></div>

<?php //end add receipt// ?>

 

<?php echo tep_draw_form('order_reorder', tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_GET['order_id'] . '&action=reorder'));

echo '<td valign="middle" align="center">' . tep_image_submit('button_in_cart.gif', 'Re-Order','','update_button') . '</td>';

echo '</form>'; ?></td>

                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

              </tr>

            </table></td>

          </tr>

        </table></td>

      </tr>

    </table></td>

</td>

  </tr>

</table><!-- body_text_eof //-->

    <td width="<?php echo BOX_WIDTH; ?>

The url I get after I press 'Buy Now' button on account.php: http://mystore/osCommerce/account_history_...&action=reorder.

 

Changing code from account_history_info.php into:

 

<td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'] . '&action=reorder', $request_type) . '">' . tep_image_button('button_buy_now.gif', 'Reorder') . '</a>'; ?></td>

doesn't add product to cart either.

 

What else can I try?

Thanks a lot,

Irina.

Share this post


Link to post
Share on other sites
Here is a part with reorder function of my cataolg/includes/application_top.php:

catalog/account_history_info.php:

The url I get after I press 'Buy Now' button on account.php: http://mystore/osCommerce/account_history_...&action=reorder.

 

Changing code from account_history_info.php into:

doesn't add product to cart either.

 

What else can I try?

Thanks a lot,

Irina.

 

take this :

 

case 'reorder' : $reorder_result = tep_reorder($_GET['order_id']);

if ($reorder_result == '') {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

} else {

echo $reorder_result;

}

break;

 

out of your "wishlist" switch and put it in your normal "action" switch.


Treasurer MFC

Share this post


Link to post
Share on other sites
take this :

 

case 'reorder' : $reorder_result = tep_reorder($_GET['order_id']);

if ($reorder_result == '') {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));

} else {

echo $reorder_result;

}

break;

 

out of your "wishlist" switch and put it in your normal  "action" switch.

Wow!!! :D

Finally I got it working.

Thanks a lot for all your support and great contribution.

:thumbsup: :thumbsup:

 

Regards,

Irina.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×