0

I need to add two custom fields in group price both in simple product and in bundle.

app/design/adminhtml/default/default/template/catalog/product/edit/price/group.phtml

Actually I want to calculate Profit and Profit percentage, for example

   Price:  144.00
   Profit: 20.00
   Profit Percentage: 13.89

I successfully add both in first row as wholesale... but when I add next field it's not working and repeating itself. Would anybody guide me in the right direction?

<?php foreach ($this->getValues() as $_item):

$getCost  = $_product->getCost();
$groupprofit = $_item['price'] / 1.2 - $getCost;
$grouppercentage = $groupprofit / sprintf('%.2f', $_item['price']) * 100; 
?>
<?php endforeach; ?>



var groupPriceRowTemplate = '<tr>'
+ '<td<?php if (!$_showWebsite): ?> style="display:none"<?php endif; ?>>'
+ '<select class="<?php echo $_htmlClass; ?> required-entry" name="<?php echo $_htmlName; ?>[{{index}}][website_id]" id="group_price_row_{{index}}_website">'
<?php foreach ($this->getWebsites() as $_websiteId => $_info) : ?>
+ '<option value="<?php echo $_websiteId; ?>"><?php echo $this->jsQuoteEscape($this->escapeHtml($_info['name'])); ?><?php if (!empty($_info['currency'])) : ?> [<?php echo $this->escapeHtml($_info['currency']); ?>]<?php endif; ?></option>'
<?php endforeach; ?>
+ '</select></td>'
+ '<td><select class="<?php echo $_htmlClass; ?> custgroup required-entry" name="<?php echo $_htmlName; ?>[{{index}}][cust_group]" id="group_price_row_{{index}}_cust_group">'
<?php foreach ($this->getCustomerGroups() as $_groupId => $_groupName): ?>
+ '<option value="<?php echo $_groupId; ?>"><?php echo $this->jsQuoteEscape($this->escapeHtml($_groupName)); ?></option>'
<?php endforeach; ?>
+ '</select></td>'
+ '<td><input class="<?php echo $_htmlClass; ?> required-entry <?php echo $_priceValueValidation; ?>" type="text" name="<?php echo $_htmlName; ?>[{{index}}][price]" value="{{price}}" id="group_price_row_{{index}}_price" /></td>'


+ '<td><?php echo  sprintf('%.2f', $groupprofit);  ?></td>'  
+ '<td><?php echo  sprintf('%.2f', $grouppercentage); ?> </td>'  


+ '<td class="last"><input type="hidden" name="<?php echo $_htmlName; ?>[{{index}}][delete]" class="delete" value="" id="group_price_row_{{index}}_delete" />'
+ '<button title="<?php echo Mage::helper('catalog')->__('Delete Group Price'); ?>" type="button" class="scalable delete icon-btn delete-product-option" id="group_price_row_{{index}}_delete_button" onclick="return groupPriceControl.deleteItem(event);">'
+ '<span><?php echo Mage::helper('catalog')->__('Delete'); ?></span></button></td>'
+ '</tr>';
0

All your code needs to be enclosed in the foreach loop. The following 2 lines we outside the foreach loop, hence it'll only display the last value from the loop.

+ '<td><?php echo  sprintf('%.2f', $groupprofit);  ?></td>'  
+ '<td><?php echo  sprintf('%.2f', $grouppercentage); ?> </td>' 
  • Thanks, Yes already try ...but its repeating first field.. if you have any idea how price in curly bracket --- {{price}} -- calculated or how this works... – lordman Jul 30 '15 at 12:49
  • Looking further down the template file, <?php foreach ($this->getValues() as $_item) : ?> groupPriceControl.addItem('<?php echo $_item['website_id']; ?>', '<?php echo $_item['cust_group']; ?>', '<?php echo sprintf('%.2f', $_item['price']); ?>', <?php echo (int)!empty($_item['readonly']); ?>); <?php endforeach; ?> – eetzen Jul 30 '15 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.