Product PDF attachment - Attribute with Multiple Files - php

I have created a product attribute called product_downloads, I can put a file name there and it appears in the product view page in the tab "Additional Information" with a link to the file name. I have successfully implemented this idea for one download, but for some products I will have multiple downloads...
Like I said, I have the code working with one download per product, all that took was a small amount of code inside of app/design/frontend/base/default/template/catalog/product/view/attributes.phtml
Where the original code was:
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
this is the code I have replaced that with:
<?php foreach ($_additional as $_data): ?>
<?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?> <!-- IF NOTHING DO NOTHING-->
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<?php if ($_data['code'] == 'product_download'): ?>
<td>
Product PDF
</td>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>
</tr>
<?php endif; ?>
<?php endforeach; ?>
This works perfectly, however... What I need now is to look at the value of product_download, if it has a comma(or some other divider, if this would interfere with a csv format) make two separate links to two seperate files..
One major thing to note... I rely heavily on MAGMI, which is why I have taken this route as no extension allows me to massively import attachments to products.
This is for spec sheets and such... some products have multiple spec sheets. I want to use a single attribute to store multiple file names and have code that will differentiate between the two.

you can use logic with explode function And change your if condition with my custom code as below
<?php if ($_data['code'] == 'product_download'): ?>
<?php
$product_downloads = explode(",",$_product->getProductDownload());
foreach($product_downloads as $download):
?>
<td>
Product PDF
</td>
<?php endforeach; ?>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>
this is just logic you can use as per your thoughts as well.
hope this will sure help you.

Related

How can I make one column per foreach using bootstap?

For a web dev projet for my school, I've to program a Trello-like. I've to display board, with different columns but I really don't know how to generate one column per element in my foreach loop.
If someone could help me I'd be thanksfull!
Here's the foreach loop:
<?php foreach ($currentColumns as $currentColumn): ?>
(<?= $currentColumn['title']?> ) <?= $currentColumn['position'] ?>
<?php endforeach; ?>
here, you can do like this..
<table>
<tr>
<?php foreach ($currentColumns as $currentColumn): ?>
<td>
(<?= $currentColumn['title']?> ) <?= $currentColumn['position'] ?>
</td>
<?php endforeach; ?>
</tr>
</table>

changing attributes of product view in magento

I have a section of extra information for the product. In the config you can add a link. This is showing the text of the link, but we want to have a word as a link and not the url to be seen.
For the product additional information there is now 1 working link. (a word that is the link instead of showing the url)
Now for a second field (second link), I want to do the same. When this field is filled with an url, the word "second link" must be the link, but not showing the url. The word "second link" is the link
I tried to change the attributes.phtml but I get lost changing the php code.
<?php foreach ($_additional as $_data): ?>
<tr class="<?php if ($_data['value'] == "No" or $_data['value']== "Nee" or $_data['value'] == "N/A" or $_data['value'] == "Nvt" ){?>no-data-value<?php } ?>">
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data">
<?php if($_data['code'] == 'link'){?>
<?php echo $this->__('Product page manufacturer')?>
<?php }else{?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php }?>
</td>
</tr>
<?php endforeach; ?>
I am trying to do the same for the second field. How do I change this in the php? I tried several things but ends up in a loop showing it twice or i get an error in the syntax.
You may try the code below:
<?php
$links = array('link' => 'Product page manufacturer',
'YOUR_CODE_OF_SECOND_LINK' => 'TEXT_FOR_SECOND_LINK');
foreach ($_additional as $_data): ?>
<tr class="<?php if ($_data['value'] == "No" or $_data['value']== "Nee" or $_data['value'] == "N/A" or $_data['value'] == "Nvt" ){?>no-data-value<?php } ?>">
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data">
<?php if(array_key_exists($_data['code'], $links)){
$code = $_data['code']; ?>
<?php echo $this->__($links[$code])?>
<?php }else{?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php }?>
</td>
</tr>
<?php endforeach; ?>
You will be able to add links' codes and texts to the $links array. It's not very good to edit template files by this way, but it should work.

Email translation issue in Magento 1.9

I've got a problem with a translation. I don't understand why my content is well translated in the website but not in the email. The translation is done in csv files, but when I call the sentence, as usual, Magento got the english translation instead of the french one.
email/stock.phtml :
<?php if ($products = $this->getProducts()): ?>
<p><?php echo $this->__('You are receiving this notification because you subscribed to receive alerts when the following products are back in stock:') ?></p>
<table>
<?php foreach ($products as $product): ?>
<tr>
<td><img src="<?php echo $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75) ?>" border="0" align="left" height="75" width="75" alt="<?php echo $this->escapeHtml($product->getName()) ?>" /></td>
<td>
<p><strong><?php echo $this->escapeHtml($product->getName()) ?></strong></p>
<?php $shortDescription = $this->_getFilteredProductShortDescription($product) ?>
<?php if ($shortDescription): ?>
<p><small><?php echo $shortDescription ?></small></p>
<?php endif; ?>
<p><?php if ($product->getPrice() != $product->getFinalPrice()): ?>
<?php echo $this->__('Regular Price:') ?> <strong style="text-decoration:line-through;"><?php echo Mage::helper('core')->currency($product->getPrice()) ?></strong><br />
<strong><?php echo $this->__('Special price:') ?> <span style="color:#FF0000;"><?php echo Mage::helper('core')->currency($product->getFinalPrice()) ?></span></strong>
<?php else: ?>
<strong><?php echo $this->__('Price:') ?></strong> <?php echo Mage::helper('core')->currency($product->getPrice()) ?>
<?php endif; ?></p>
<p><small><?php echo $this->__('Click here not to receive alerts for this product') ?></small></p>
</td>
</tr>
<?php endforeach; ?>
</table>
<p><?php echo $this->__('Unsubscribe from all stock alerts') ?></p>
<?php endif; ?>
Do you know how to say to Magento that it has to take the french translation in my email template ?
To translate an email, you can copy it from the en_US folder to a corresponding language folder (es_ES, for example), then perform the translation. When you do this, you can also add or remove other vars from the email. Most emails will have headers that show you what vars are available.
As for adding a country code to the telephone number, you will need to define a new block in a module that will do this for you.
There is also another solution on link
First of possibility: https://magento.stackexchange.com/questions/25612/cron-job-template-block-not-being-translated-but-testobserver-is
Second possibility:
Function that's responsible for sending product out of stock alert is called send and exists in file around line 229:
app/code/core/Mage/ProductAlert/Model/Email.php
The function's using below code to get customer's store:
$store = Mage::getModel('core/store')->load($this->_customer->getStoreId());
Function getStoreId on customer gets data from field "Created from - account[created_in]"
So if customer was created by an Admin from backend - the customer will always get default store (admin's) settings for language, currency, translations, etc.
Check what is returned for the customer that get's wrong translation and/or url's by this code:
<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
echo $customerData->getStoreId();
} ?>
If it's 0 - that's the case.

Wrong product URLs magento

I've been working on custom up sells related products script, which is displaying 4 random products.
Problem is:
normal product url is:
/shop/$productname
This sometimes is generating url like: /$productname/
or url like: /catalog/product/view/id/$productID/4/s/$productname/category/$categoryid/
I want to have all my URLs the same so: /shop/$productname
<div class="upsell">
<h2>You might be interested in</h2>
<?php // List mode ?>
<?php $_iterator = 0; ?>
<?php // Grid Mode ?>
<table class="products-grid upsell" id="upsell-product-table">
<tbody>
<tr>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); $_columnCount=4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<td>
<?php // Initiate product model
$product = Mage::getModel('catalog/product');
// Load specific product whose tier price want to update
$product ->load($_product->getId()); ?>
<img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(170); ?>" width="125" height="125" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h3 class="product-name"><?php echo $_helper->productAttribute($product, $product->getName(), 'name') ?></h3>
<?php echo $this->getPriceHtml($product, true) ?>
</td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div>
Try
$this->getUrl('shop').$product->getUrlPath()
instead of
$product->getProductUrl()
for both image and product title.
If your indexes are up to date then
$product->getProductUrl()
Should give you the correct product url.
Do not try to build the url yourself from pieces like the url_key, or url_path and the base url. If you move your website to an other serve you're going to have some issues. Also if you change the config settings for categories in product url you can have problems.

Magento - pull one single customer review

I've been trying to pull one single customer review onto the product page.
I've no code to show as honestly i'm not sure where to start and can't find any mention of it online.
Anyone have any ideas?
I wrote a tutorial earlier on bringing all the review elements onto the product page, so you could follow this tutorial: http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php
All you'd have to do is rename the list block and bring it out in the same way. Then simply modify the loop which brings out the reviews in any way you see fit. E.g. limit to a certain number or only echo out review from a certain user.
EDIT:
To get the latest review is quite simple because the reviews are in date order anyway.
Go to review > product > list.phtml
Replace the code in that file with this:
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<h2><?php echo $this->__('Customer Reviews') ?></h2>
<?php echo $this->getChildHtml('toolbar') ?>
<dl>
<?php $r_count = 0; ?>
<?php foreach ($_items as $_review):?>
<?php if ($r_count == 0) { ?>
<dt>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
<small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
</dd>
<?php } ?>
<?php $r_count++; ?>
<?php endforeach; ?>
</dl>
<?php echo $this->getChildHtml('toolbar') ?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
I've simple put an interator into the loop $r_count and put a check inside the foreach which prevent it from progressing on the next loop iteration.

Categories