Adding a custom attribute after the short description in magento - php

I'm quite new to magento and i'm struggling trying to add a custom attribute after the short description in products page
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<div class="std"<?php if($richSnippets['status'] == 1): ?> itemprop="description"<?php endif; ?>><h2><?php echo $this->__('Details:') ?></h2><?php echo $_helper>productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php $_item = $this->getProduct()->getId();
$_resource = $this->getProduct()->getResource();
$CustomAttribute = $_resource->getAttributeRawValue($_item, 'ratebeer', Mage::app()->getStore());
echo $CustomAttribute; ?>
Anyway the attribute does not appear after the short description...the same code works in another section of the same page so i don't really know what's going on

You should be able to just
echo $_product->getRatebeer();
But you may have to add the attribute to your flat tables first. You can do this by setting Include in product listing to Yes.
This is bad practice, but you could try this just to see if the attribute is set up correctly
echo $_product->load($_product->getId())->getRatebeer();

Related

acf on wordpress problem with Field Googlemap

I have a wordpress with acfpro. I use it the options page for to create option page header and footer, next I declare custom field map on option page footer and paste code in footer.php.
when I do it this, i have some pages where acf map not working and other pages is good!
wordpress 5.2, acfpro 5.7.13
<div class="left">
<div class="zto-containMap">
<?php
$location = get_field('map');
$long = $location['lng'];
$lat = $location['lat'];
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $lat; ?>" data-lng="<?php echo $long; ?>"></div>
</div>
<?php else: ?>
<div class="acf-map">
not working
</div>
<?php endif; ?>
</div>
</div>
I don't have a error message, and acf map is broken on 3 page on my site and the other pages are working nice width acf map
If you want to get the field value for an option, you have to declare the option scope in your second paramter of get_field($field, $scope). If no $scope is passed in the get_field() function it will automatically use the ID value of get_post().
This is what you're after:
$location = get_field('map', 'option');
Here's the docs on getting the value of an Option field in ACF.
While this is a little out of the scope of your question, these docs explain a little further about how the $scope variable can be used in the second parameter.

Hide Div title if there's no content

I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.
I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.
Here is the code:
<div class="customfields">
<h2 class="widgettitle">My Title</h2>
<?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
I would very much appreciate your help!
Thanks a ton,
T.
So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<div class="customfields">
<?php if(!empty($taxonomy)) : ?>
<h2 class="widgettitle">My Title</h2>
<?php echo $taxonomy; ?>
<?php endif; ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.

Magento - cart not showing and checkout/cart page empty (doesn't show the .cart div)

Okay, so I'm a newbie to Magento and have been making lots of changes to get it working the way a client is wanting.
Obviously at install and early on, the shopping cart was working fine. I moved it up to the top right corner for a while w/ CSS and then I THOUGHT that I display:none'd it, as I just wanted to focus on other things for a while before moving on to styling it. Now I've done all those other things and want to deal with the cart. Trouble is - it is nowhere to be found and the display:none that I thought I'd used to turn it off is similarly missing. Maybe I never did it?
I can't find anything in the CSS that would have turned off the cart - I can't find a display:none on it or any parents. Most of the site is using a 2 column with left sidebar layout, and I know the shopping cart resides by default in the right. But when I turn back on the right sidebar - no cart. Furthermore, when I go to add a product to the cart, I am redirected to mydomain.com/checkout/cart as expected, but there is nothing on the page. My styling, menus, etc are present but the .col-main element where the full-page detailed cart should be is empty. Which makes me think again that the problem isn't CSS.
It's as if the site just isn't calling for the cart (I assume cart.phtml?). It is totally possible that I screwed something up while messing with other things (adding a CMS page menu at top, lots to do with resizing images, moving the category menu to the left sidebar). My php isn't good enough to find the culprit and I'm not even sure which file I should be looking at - checkout.phtml?
I realize this question has very little valuable information, but does anyone have any ideas as to where I should be looking? I can post the relevant code if I know which file to look in. The site is cart.oldfloridian.com. If you want to try to add a product, there is only one at the moment, at "ak starfish --> starfish women's"
Edit: so the /checkout/cart page is a 3column layout. Here is the 3columns.phtml code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<div id="cms-menu">
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()
->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route') { ?>
<li>
<?php echo $PageData['title'] ?>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col3-layout">
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-wrapper">
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>
There does seem to be a bug in there somewhere - we had a similar issue where two devs in the team couldnt see the cart, 1 could - but it wasnt just the cart it was the whole customer section (login, cart, my account etc).
We tried enabling Template Path Hints but the only thing in the main section of the page was "frontend/default/default/template/catalog/msrp/popup.phtml". We re-installed most of magento - no luck
We tried pretty much everything and what fixed it was coping all of the theme files into a new theme and re-naming it. Only thing I can think of that it could have been was a hyphen in the theme name

Attribute assign image to each multi option

I have created a multi option attribute so that I show an image for each option but i can not get it to work.
I have used this code from another post on here to get a list of the options to show.
The code I used is:
<?php if($_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)): ?>
<h4>Suitable for:</h4>
<ul><li><?php
$_comma = ",";
$_list = "</li><li>";
echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)) ?>
</li></ul>
<?php endif; ?>
So this now shows a list of the options, one of on top of each other.
As I said I would like an image to be shown for each option.
I thought the best way would be to have divs and assign an image to each div.
I was hoping that I could get the output to be:
<div class="option1"></div>
<div class="option2"></div>
<div class="option3"></div>
<div class="option3"></div>
instead of the output that the code above has:
<ul>
<li>option1</li>
<li>option2</li>
<li>option3</li>
<li>option4</li>
</ul>
Change your code to
<?php if($_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)): ?>
<h4>Suitable for:</h4>
<div class="<?php
$_comma = ",";
$_list = "\"></div><div class=\"";
echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)) ?>
</div>
<?php endif; ?>

how to create new custom options type in magento?

How do I create new product custom options type in magento?
For example, I have to give new image a custom option type in magento which fetches an image from my custom module table, and I want to assign that image to my custom options image field.
As Dustin Graham said, it is very tricky. First steps:
Add new node under global/catalog/product/options/custom/groups. See examples in /app/code/core/Mage/Catalog/etc/config.xml.
Create new block to render your custom option.
Rewrite Mage_Catalog_Model_Product_Option and implement saving your custom type options (saveOptions() method) and loading your custom type options (getProductOptionCollection method).
If your custom type isn't very custom :) - it should be enough.
I forgot this question but i need again to create new custom option type in my another project. I had Created new custom options type using this link.
http://magento.ikantam.com/qa/custom-input-types-custom-options
Solution is bit lengthy and its not possible to put whole code here, so i have just share this link, going through this link i had create new custom options type easily, explanation is good in this article.
I have modify some changes for my need .
Hope this will help some one.
As Dustin Graham said its incredibly tricky.
#Mufaddal thanks for sharing this link. I'd like to offer an alternative to this since it requires quite a bit knowledge.
If you're only trying to change the way a specific dropdown (for example) is displayed you can also overwrite the /template/catalog/product/view/options/type/select.phtml as follows:
`
getOption() ?>
<dt><label<?php if ($_option->getIsRequire()) echo ' class="required"' ?>><?php if ($_option->getIsRequire()) echo '<em>*</em>' ?><?php echo $this->escapeHtml($_option->getTitle()) ?></label> </dt>
<dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<?php echo $this->getValuesHtml(); ?>
<?php if($_option->option_id == 2) : ?>
<script type="text/javascript">
jQuery('#select_2').css('display', 'none');
</script>
<?php foreach ($_option->getValues() as $_value) { ?>
<?php echo $_value->getTitle(); // the title of the option ?>
<?php echo $_value->getOptionTypeId(); // the id ?>
<?php } ?>
<!-- add custom code that triggers select in the background -->
<?php endif ?>
<?php if ($_option->getIsRequire()): ?>
<?php if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO || $_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX): ?>
<span id="options-<?php echo $_option->getId() ?>-container"></span>
<?php endif; ?>
<?php endif;?>
</div>
`
You can then hide the select and interact with the select through jQuery.

Categories