Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Markup / Margin Update


CGhoST

Recommended Posts

Hi Everyone

 

I installed http://addons.oscommerce.com/info/9346

 

It an addon that shows the margin/markup for each product.

 

The problem with this addon is the percentage only updates after you save the product and edit the product again.

 

The following is the javascript for this:

/*
COST MARGIN MOD
START OF CODE ADDITION
*/
function updateMargin() {
  var grossValue = document.forms["new_product"].products_price.value;
  var costValue = document.forms["new_product"].products_cost.value;

 marginValue = parseInt(-100 + (grossValue/costValue)*100);

  document.getElementById('products_price_margins').innerHTML = marginValue + "%";
 }
/*
COST MARGIN MOD
END OF CODE ADDITION
*/

Can someone please assist in showing how:

  document.getElementById('products_price_margins').innerHTML = marginValue + "%";

can be changed so that it does a live update just the way gross and net value change if you change either.

Link to comment
Share on other sites

I agree with the last post, margin report addon 8147 works well with BS. 

 

Mike

osC CE live - developing osC Phoenix adding modules with no core changes(awesome and easy!)

Link to comment
Share on other sites

Hi

 

Looking at the install for your version:

%%%Replace With:

  <tr bgcolor="#ebebff">
    <td class="main"><?php echo TEXT_PRODUCTS_PRICE_COST; ?></td>
    <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_cost', $pInfo->products_cost, ''); ?></td>
  </tr>
  <tr bgcolor="#ebebff">
    <td class="main"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
    <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_price', $pInfo->products_price, 'onKeyUp="updateGross()"'); ?></td>
  </tr>

try swapping in this

%%%Replace With:

  <tr bgcolor="#ebebff">
    <td class="main"><?php echo TEXT_PRODUCTS_PRICE_COST; ?></td>
    <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_cost', $pInfo->products_cost, 'onKeyUp="updateMargin()"'); ?></td>
  </tr>
  <tr bgcolor="#ebebff">
    <td class="main"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td>
    <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_price', $pInfo->products_price, 'onKeyUp="updateGross()"'); ?></td>
  </tr>

i.e. add a call to the updateMargin() function - it looks like it is missing?

Link to comment
Share on other sites

Thank you Bob. That worked great.

 

 

I tried http://addons.oscommerce.com/info/8147 but it didn't show percentage in product edit. But i see that part can be added from the contribution i installed.

 

Is it possible it can be changed into a field so that if there is a cost and you set a certain markup the net price changes with it?

Link to comment
Share on other sites

Ok i tried to make a pull down menu to select margin or markup to see the percentage.

 

This is what i did.

          <tr bgcolor="#ebebff">
            <td class="main"><?php echo TEXT_PRODUCTS_COST_SELECTION; ?></td>
            <?php $margin_array[] = array('id' => '1', 'text' => 'Margin');
	          $margin_array[] = array('id' => '2', 'text' => 'Markup'); ?>
	    <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('margin_array', $margin_array);?></td>
          </tr>

The IF statement line is what i am not understanding. Following is the code i have:

if ($_GET['margin_array'] == '1'){
  function updateMargin() {
    var realValue = document.forms["new_product"].products_price.value;
    var costValue = document.forms["new_product"].products_cost.value;

    marginValue = parseInt(-100 + (realValue/costValue)*100);
 
    document.getElementById('products_price_margins').innerHTML = marginValue + "%";
  }
}

if ($_GET['margin_array'] == '2'){
  function updateMargin() {
    var grossValue = document.forms["new_product"].products_price.value;
    var costValue = document.forms["new_product"].products_cost.value;

    marginValue = parseInt(100 - (costValue/grossValue)*100);
 
    document.getElementById('products_price_margins').innerHTML = marginValue + "%";
  }
}

Please help

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...