|
Gab,
There are a few ways…
Either their names are standardized or not.
If standardized, on what? (Sku/Name)
If not, how defined? Attribute.
----------------------------------------
I started with a standardization, it happened to be that all the PDF’s match the Product Names and their Images but capitalized.
I check per product if the file exists in the set location, if it does, its displayed, and can be downloaded. If not… its not.
I started out with something like the following…
app/ ... / template/catalog/products/view.phtml
and viewgroup.phtml
<?php if ($this->helper('customer/data')->isLoggedIn()): ?> <h4><?php echo $this->__('Downloads') ?></h4> <?php //media pathing $path = $this->getUrl('').'media/catalog/product/'; //pdf uses .pdf ext and standard numbers $pdf = $_product->getImage(); $pdf = strtoupper($pdf); $pdf = str_replace(".JPG", ".pdf", $pdf); //dxf uses .dxf ext and order codes $dxf = $_product->getSku().'.dxf'; //iges uses .zip ext and order codes $iges = $_product->getSku().'.zip'; //final string $pdf = $path.$pdf; $dxf = $path.$dxf; $iges = $path.$iges; if(file_exists($pdf)) { ?> <button class="form-button"> <span> <a style="color: #ffffff ;" href="<?php echo $pdf ; ?>"><?php echo "PDF" ?> </a></span> </button> <?php } if(file_exists($dxf)){ ?> <button class="form-button"> <span> <a style="color: #ffffff ;" href="<?php echo $dxf ; ?>"><?php echo "DXF" ?></a></span> </button> <?php } if(file_exists($iges)){ ?> <button class="form-button"> <span> <a style="color: #ffffff ;" href="<?php echo $iges ; ?>"> <?php echo "IGES" ?></a></span> </button> <?php } ?> <?php endif; ?>
This would check to see if they were a customer, check to see if the expected files exist, and display if they do.
Another add on you can do is also to check to see if an attribute exists, what that string is, and see if that file exists on the server.
(http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-attributes-custom-fields)
create an attribute, (PDF)
add it to your attribute set, allow text entry..
the user in the admin can use “bob.pdf” or “bob” depending on your code.
Then you grab “bob.pdf” from the current object, see if bob.pdf exists in your specified path.
<div class="collateral-box attribute-specs"> <div class="head"> <h4><?php echo $this->__('Additional Information') ?></h4> </div> <table cellspacing="0" class="data-table" id="product-attribute-specs-table"> <?php if ($this->helper('customer/data')->isLoggedIn()){ ?> <tr> <td class="label"> Order Code </td> <td class="data"><?php echo $_product->getSku() ?></td> </tr> <?php if($_additional = $this->getAdditionalData()){ ?> <?php foreach ($_additional as $_data){ ?> <tr> <td class="label"><?php echo $_data['label'] ?></td> <td class="data"><?php echo $_data['value'] ?></td> </tr> <?php } ?> <?php } ?> <?php }else{ ?> <tr> <td class="label"> Order Code </td> <td class="data"><?php echo $_product->getSku() ?></td> </tr> <tr> <td class="label"> Downloads available for registered customers. Click <a href="https://www.eins1.us/index.php/customer/account/login">here</a> to register or login. </td> <td></td> </tr> <?php } //endelse ?> </table>
<?php //echo "<pre>".print_r($_product)."</pre>" ; ?> </div>
<?php echo $this->getChildHtml('upsell_products') ?> <?php echo $this->getChildHtml('product_additional_data') ?> </div> </div>
Uses the attributes in view.phtml
|