Skip to content

Instantly share code, notes, and snippets.

@traviswaelbro
Last active June 1, 2016 21:02
Show Gist options
  • Save traviswaelbro/e867812351918b0c0dd4b828224528a1 to your computer and use it in GitHub Desktop.
Save traviswaelbro/e867812351918b0c0dd4b828224528a1 to your computer and use it in GitHub Desktop.
Standalone page designed to generate Excel-compatible table with all grouped products' cost and price (per components and total grouped product).
<?php
include_once "app/Mage.php";
umask(0);
Mage::app();
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');
echo $headBlock->toHtml() . $headerBlock->toHtml();// . $footerBlock->toHtml();
?>
<div class="page-header">
<?php
$groupedProducts = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('*')
->addFieldToFilter('type_id', array('eq' => 'grouped')); ?>
<table style="width:75%;">
<thead>
<th>Parent SKU</th>
<th>Child SKU</th>
<th>Cost</th>
<th>Price</th>
<th>Qty</th>
<th>Total SKU Cost</th>
<th>Total SKU Price</th>
<th>Total Cost</th>
<th>Total Price</th>
</thead>
<tbody>
<?php foreach($groupedProducts as $product) { ?>
<?php $sumCost = $sumPrice = 0; ?>
<tr>
<td><?php echo $product->getSku() ?></td>
<?php $associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product); ?>
<td>
<?php foreach ($associatedProducts as $item) { ?>
<?php $sumCost += ($item->getCost() * $item->getQty()); ?>
<?php $sumPrice += ($item->getPrice() * $item->getQty()); ?>
<tr>
<td></td>
<td><?php echo $item->getSku() ?></td>
<td><?php echo number_format($item->getCost(),2) ?></td>
<td><?php echo number_format($item->getPrice(),2) ?></td>
<td><?php echo $item->getQty() ?></td>
<td><?php echo number_format($item->getCost(),2) * $item->getQty() ?></td>
<td><?php echo number_format($item->getPrice(),2) * $item->getQty() ?></td>
<!--<td><?php echo $sumCost ?></td>
<td><?php echo $sumPrice ?></td>-->
</tr>
<?php } ?>
</td>
<td><?php echo $product->getSku() ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $sumCost ?></td>
<td><?php echo $sumPrice ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment