changing attributes of product view in magento - php

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.

Related

Give two links in one HTML <td> tag

Here is one <td> tag that has the link to go to marks/details/index/someId,
<td>
<a href="<?php
echo $this->url('marks/details',array('action'=>'index','id'=>$item['studentAcademicId']))
?>">
<?php
if(($item['marksObtained'])!= Null )
{
echo $item['marksObtained'];
}
else {echo 'Add Marks'; };
?>
</td>
I want to add another link, in this same <td> after else {echo 'Add Marks'; } which would go to another link e.g Marks/details/addfromsession/someId
anchor tag is not closed after this you can add anchor. like as below
<td>
<a href="
<?php echo $this->url(
'marks/details',array('action'=>'index','id'=>$item['studentAcademicId']))?>">
<?php if(($item['marksObtained'])!= Null )
{ echo
$item['marksObtained'];}
else {echo 'Add Marks'; };?> </a>
SOME TEXT
</td>
This is the correct way to pass two links in one HTML <td> tag.
<?php foreach ($this->data as $item): ?>
<tr>
<td>
<?php if(isset( $item['marksObtained']) && $item['marksObtained'] > 0){?>
<a href="<?=$this->url( 'marks/details', array('action'=>'index', 'id'=>$item['studentAcademicId']))?>">
<?php echo $item['marksObtained']; ?></a>
<?php }else{ ?>
<a href="<?=$this->url( 'marks/details', array('action'=>'add', 'id'=>$item['studentAcademicId']))?>">
Add Marks</a>
<?php }?>
</td>
</tr>
<?php endforeach;?>
If condition is true, one link is passed, else the other link is passed, So now we have two tags that are working exactly to the question.

Clicking view button and nothing happens

After clicking the VIEW button and nothing happening, I started to wonder what's wrong?
GALLERIES NAME POST EDIT DELETE
Slideshow VIEW
SERVICES POST VIEW
Code:
<?php foreach ($gallery as $gallery_item): ?>
<tr>
<td><?php echo $gallery_item['galleries_name']; ?></td>
<td>
<?php if( $gallery_item['galleries_post_type'] == 'post') { echo "#"; }?>
</td>
<td>
<button type="button" class="edit" onclick="location.href = '
<?php
if( $gallery_item['galleries_post_type'] == 'post') {
echo site_url('cpages/galleries/'.$gallery_item['galleries_id']);
} else {
echo site_url('cpages/viewpictures/'.$gallery_item['galleries_id']);
}
?>
';">VIEW</button>
</td>
I think you should use links and describe them as button (role, type, whatsoever) and decore them with CSS. That is:
<?php
$id = $gallery_item['galleries_id']);
?>
<td>
<?php if ($gallery_item['galleries_post_type'] === 'post'): ?>
<a href="<?= site_url('cpages/galleries/'.$id); ?>" class="edit">
<?php elseif (): ?>
<a href="<?= site_url('cpages/viewpictures/'.$id); ?>" class="edit">
<?php endif; ?>
</td>
By searching for a better solution, I found an answer from BalusC that, I think, should solve your problem and help you understand how/what/when questions about buttons, links and so one.

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.

Product PDF attachment - Attribute with Multiple Files

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.

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.

Categories