hey guys, having an issue with magento which i just cant seem to find a solution to.
i have tried many ways of getting a configurable products attributes (simple products) and listing them, now i have them listing from 2 ways but the way im working with is below
$confAttributes = #$_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$sizes = array();
foreach($confAttributes AS $atts){
//print '';//'<pre style="display:none;">'.print_r($atts).'</pre>';
if($atts['label'] == 'Size'){
foreach($atts['values'] AS $val){
$sizes[] = $val['store_label'];
}
}
}
my only problem with this now is i need to only pull back the size attributes which are in stock - looked through mage files to find solution but just cant see anything - the result i need is done in config product php file but i cant access it from in the code where i need to list the size attribute.
any help would be great, thanks!
Solution:
You can get easily all configurable(product) details page information on any other PHTML file by using following code:
e.g.: in my case i'm getting details on catalog/product/list.phtml.
<script src="<?php echo Mage::getBaseUrl('js') ?>varien/configurable.js" type="text/javascript"></script>
<?php
$temp = new Mage_Catalog_Block_Product_View_Type_Configurable();
$temp->setData('product', $_product);
$_attributes = Mage::helper('core')->decorateArray($temp->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<?php foreach($_attributes as $_attribute): ?>
<?php
$prices = $_attribute->getPrices();
foreach($prices as $price) {
echo $price['pricing_value'] . "<br/>";
}
?>
<?php endforeach; ?>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $temp->getJsonConfig() ?>);
</script>
<?php endif;?>
Thanks,
found the solution, i had to use the above what i had already coded and use assosicated products for the size and then check the stock levels and put them into an array and check the stock when building my attribute list - works great - anyone else have a better solution please share :D thanks
Related
Is it possible to only show the code below if there's a category description?
<h2>About <?php $cat = get_the_category(); echo $cat[0]->cat_name; ?></h2>
<?php $catID = get_the_category(); echo category_description ( $catID[0] ); ?>
I have these codes on my single posts in Wordpress but sometimes, I forgot to add descriptions on a new category that I added. So when a user visits the post, they will just see the word About Category and no description at all, making it looks like an incomplete article.
I'm not a developer and I'm also not familiar with PHP. I only added that code on the single.php to show the description. But I want it not to show when there's no description available.
Hope someone can give me the exact code to make it work.
Thanks!
Good practice to assign your values into variables at the top of your script before entering into HTML whenever possible. This will help prevent you making redundant calls and to debug your code better. Once you have your assigned values, you'll want to check if the value is empty. I am assuming the code you presented will always return some kind of value for index 0.
<?php
$cat = get_the_category();
$cat_0 = $cat[0];
$cat_0_name = $cat_0->cat_name;
$cat_0_desc = category_description($cat_0);
?>
<?php if(!empty($cat_0_desc)): ?>
<h2>About <?php echo $cat_0_name; ?></h2>
<?php echo $cat_0_desc; ?>
<?php endif; ?>
I should like to point out that I am choosing to use an alternative syntax for control structures versus the traditional brace control. This will make your code more readable and easily debugged when mixed in with HTML.
If your code is still throwing you errors, I would suggest you check your error logs as something would be happining during the get_the_cateory() call or that it's not returning any values resulting in error with $cat[0].
<?php if ($cat = get_the_category() && count($cat)>0) { ?>
<!-- <?php echo print_r($cat,1); ?> -->
<h2>About <?php echo $cat[0]->cat_name;?></h2>
<?php echo category_description ($cat[0]->cat_id); ?>
<?php } ?>
I am using Mijoshop which is a Opencart integration for Joomla. What I am currently looking to achieve is to display a specific div class in the header if a certain product or category is matched.
I've found this code which I've added to my category.tpl but without any luck or any of these being displayed:
<? php if($category_id==20){
echo "text1";}
else
{echo "text2"}
?>
Any ideas on how to get this to work? Some expert help would be greatly appreciated.
Try this:
<?php if($category['category_id'] == 20) { ?>
echo "text1";
} else {
echo "text2";
}
?>
The value should be called by $category['category_id'] and you had some syntax errors:
Space after ?
No semi-colon after "text2"
Firstly I would like to apologise if this question has been answered somewhere else but I am unable to find what I am looking for as I am new to PHP and assume I need this to solve my problem.
I have built a website and am using Mals-e shopping cart. I have everything up and running but I would like to show how many products are still in stock under the product description and if there are no items in stock. For example:
Available stock: 2
or
Sold Out
I have read that I need a text file with product name, price and quantity, a PHP file to read and rewrite the quantity available and out put the results on the product page and a mypage.php page but I really don't know where to start. I've spent days trying to sort this out.
I have Mysql database with some items in table called (items) with available quantity but don't know how to go about sorting it out. Any help would be most appreciated.
Thank you.
Without seeing the actual code you're using to display the product, it's hard to say buy all you should need is something like:
<?php
// get the product and stock level
if($product->numberInStock > 0) {
echo 'Available: ' . $product->numberInStock;
} else {
echo 'Out of stock';
}
If you're editing a phtml type template (HTML with embedded PHP), you might display it like:
<? if($product->numberInStock > 0): ?>
<p>Available: <?= $product->numberInStock; ?></p>
<? else ?>
<p>Out of stock</p>
<? endif; ?>
Had same issue, found out following.
Inside your catalog/product type template you can use this:
<?php
$_product = $this->getProduct();
$_qty = $_product->getStockItem()->getQty();
?>
<p>
<?php if($_qty > 0): ?>
Available: <?php echo $_qty; ?>
<?php else: ?>
Out of stock
<?php endif; ?>
</p>
session_start($_POST['quantity']);
if(isset($_POST['quantity']))
{
$postedquantity=$_POST['quantity'];
$productQuantity="20";
if($postedquantity<$productQuantity){
echo "In stock";
echo "<br/>";
}
$productQuantity=$productQuantity-$postedquantity;
echo $productQuantity."Remaining";
}
You can even do like this,storing quantity value in session and everytime it's posted it will check whether it is in stock or not and it will show how much quantity is remaining.
i want to highlight only the pressed menu item in magento, can it be done?
i have tried to achieve this in many ways but none of them succeeded (i can list some of them here if it helps)
thank you
1 tried php get url and compare it to the text written inside the a tag
2 tried built-in methodes/id specific to magento
i have made some progress -i added this code to my template file -2columns-left.phtml
<?php
$routeName = Mage::app()->getRequest()->getRouteName();
echo $routeName;
$body_class = $this->getLayout()->getBlock('root')->getBodyClass();
echo $body_class;
if(strpos(strtolower($body_class),strtolower($routeName)) !== false){
$nav_active = "class = 'nav_active'";
}
?>
now i have added $nav_active to the body tag in the same file ,have tried this but it didnt work
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?><?php if(strpos(strtolower($body_class),strtolower($routeName)) !== false):?> echo $nav_active ;?>>
you can try with my alternative solution
it is working at my end
just do it like this
<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'your_category_name') != false ) :?> active<?php endif;?>
hope this will sure help you.
I a sorry for the poor question but I have no idea where to start.
Basically I have a product template that utilises 15 custom options for Name, 15 for Tshirt size and 15 for tshirt number.
Using jquery the options are hidden on the personalisation based on the product quantity. It then puts a default * or none for the size.
The only problem is that if a customer orders say 3 tshirts in the emails and customer orders they will see a long list of options that they have not selected.
I was wondering if there was a way to exclufe the option if it equaled * or none.
SOLVED WITH THE BELOW
<?php
$optionvalue = $option['value'];
$array = array('None','*');
if(!in_array($optionvalue,$array)){
echo $option['label'];
}
?>
<?php
$optionvalue = $option['value'];
$array = array('None','*');
if(!in_array($optionvalue,$array)){
echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value'])));
}
?>
This is possible.
You'll have to modify the template of the email.
The base one is here :
magento\app\design\frontend\base\default\template\email\order\items\order\
This is the one for orders, don't forget about invoice, shipment and creditmemo.
<?php foreach ($this->getItemOptions() as $option): ?>
<dt><strong><em><?php echo $option['label'] ?></em></strong></dt>
<dd style="margin:0; padding:0 0 0 9px;">
<?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
</dd>
<?php endforeach; ?>
just add a control on the $option['value'] or $option['print_value']
Maybe also the Pdf function to have the same behaviour on the pdfs will need modifications
Of course as it's native core function, don't modify directly the code but create your module to extends and replace it.
Solved by using an array and if statement and with dagfr's pointer to the location of the function. Have updated the PDF functions as well as emails and on screen on the carso looks pretty tidy now.
<?php
$optionvalue = $option['value'];
$array = array('None','*');
if(!in_array($optionvalue,$array)){
echo $option['label'];
}
?>
<?php
$optionvalue = $option['value'];
$array = array('None','*');
if(!in_array($optionvalue,$array)){
echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value'])));
}
?>