Updating Schema.org availability on my website - microdata

In my ProductDetails.html page I have added the below mircodata, but I need to toggle it on and off based on inventory being InStock or OutofStock. Right now it is toggled InStock for all products. Please help!
<link itemprop="availability" href="schema.org/InStock"; />

Just change this to OutOfStock when the product is out of stock http://schema.org/OutOfStock, use -
<link itemprop="availability" href="http://schema.org/OutOfStock" />
and remove the InStock line. Whatever code you use to display the number in stock or an in stock/out of stock message can be used for this. Using json-ld for controlling the in stock/out of stock status can be done by using some code (javascript for example) to write a script that dynamically writes the JSON-LD.
If you want a very, very simple solution you could use a different, slightly ambiguious term instead of In Stock/Out of Stock, these are listed on http://schema.org/ItemAvailability as PreOrder, LimitedAvailability, InStoreOnly, Online Only. Not every bit of information is needed for your structured data to work. None are optional, although google does give an error if some things are missing it will recognize (and use) the remainder of the data.

Related

Laravel string limit with html tag shows less item than the actual number of items

I am using laravel and blade to loop over some blog items. I wanted to show blog with html tags and also with str_limit function.
When I try
{!!str_limit($blog->body, 450)!!}
It only shows 10 blogs or 11 out of 22. It should show all items.
If I use {{ str_limit($blog->body, 450) }} it shows all but without html tags I mean no effect of html tag.
str_limit has no knowledge of HTML tags, so using it on a string that contains HTML will often result in an unclosed tag that breaks the rest of the page.
As an example, an excerpt that ends in <a href="http://google.co because it got lopped off there means the rest of your page is part of the <a> tag until you accidentally output a " and a > again.
A couple options are available to you:
Strip the HTML tags. I know you wanted to preserve them, but this remains the easiest way of generating an excerpt.
Output the entire body, but give it max height and an overflow: hidden to hide the rest. This has bandwidth downsides, so if your posts are enormously long, it may not be the best approach.
Produce your own excerpts as a separate field. Manual work, but you're always in control that way.
Find/code a HTML-aware excerpt generator. I'm not aware of a good one I can recommend - it's a complicated problem. You could try generating a str_limited string and then running the results through Tidy, which can sort of fix invalid HTML.

Magento content management; prevent a mess

So, I started on a new project this week and of course I'm thinking about the problems I'm going to find during the whole development process. We are going to make a shop that has a pretty good design, pretty excited to work on this. However, the design uses a lot of content that can't be placed in the normal functions of magento. For example there is a catalog page that has a lot of content blocks with secondary information like unique selling points or a bit of story telling. This can and will be different for different categories. We are talking about a lot of small content blocks, not something you can cram into the category description field ;)
Until now I mostly used static blocks to make this content and show them on the pages, maybe even use xpath to extract the information I need from the blocks to prevent the end-user from destroying the design by using the WYSIWYG editor. However, I don't think this will be a good solution now because there will simply be to much static blocks to create and use without loosing the overview of everything, plus I doubt xpath is really good performance wise (something like getting a screw in with a hammer).
I was thinking about making a module or using a module that makes it possible to add attributes and use attribute sets in combination with static blocks. With that you can make your own fields and groups for certain pages and make it easy for the end-user to edit information on their webshop. However, making this myself (does sound like a lot of fun) will take to much time, and I can't really find a module that does something like this.
How do you guys solve these problems when creating a new webshop? Any tips?
I suppose you will be using your own theme with own template for the category page, here you will setup all the HTML that you don't want the admin to mess up with the WYSIWYG editor and let them change only certain parts of the page. For the admin to be able to edit these, you will need to add new attributes to the category entity. For example if the admin should add text for a certain box, add text type of attribute, if the admin wants to add HTML create WYSIWYG editor type of attribute and so on. Then in your template you will check if the category has any of these attributes and they have non-empty values then print them.
For example:
<?php if ($category->getCustomTextAttribute() != ''): ?>
<div id="your-div">
<?php echo $category->getCustomTextAttribute(); ?>
</div>
<?php endif; ?>
<?php if ($category->getPromotionHtml() != ''): ?>
<div id="promotion-div">
<?php echo $category->getPromotionHtml(); ?>
</div>
<?php endif; ?>
This goes the same for the product pages with the difference that for products you can create the attributes via the admin and then print them on the product page template, otherwise for Categories you need to write a module that does this, if you want me I can provide you with an example of module for creating Category attributes.
I ended up using a combination of zokibtmkd answer and adding fields to the default static blocks (a image upload function and a link field). The combination of these two solutions gave me enough to work with in the design without messing up the admin or the templates.

How do I add additional info next to the product price in magento?

Im trying to add pm2 (per meter squared) next to the price on the product page in magento, here is an example:
after looking at the souce code for how they showed this it was:
<span class="metres">m<sup>2</sup>
so I added that little bit of code to my theme template in magento file location (app/design/frontend/default/THEMENAME/template/catalog/product/view/price.phtml):
<div class="price-box" id="product_price">
<p class="old-price"><?php echo $this->__('Old Price:') ?><?php echo $this->getPrice() ?></p>
<p class="special-price"><?php echo $this->getPrice() ?><span class="metres">m<sup>2</sup></p>
</div>
but nothing shows up, see example:
any ideas on how to achieve this ?
As an alternative approach you could try the :afer pseudo element (see http://css-tricks.com/almanac/selectors/a/after-and-before/). I don't like modifying core files (even if you do take a copy in your theme like you have) because a future upgrade may change the file significantly and your version might even become incompatible. This approach at least would avoid that.
And to get your superscripted 2, see CSS :before superscript "6"?.
if you look at price.phtml you will see there are many repetitions of price and special price, as the file is used to cover every possible price permutation - product type and tax display etc. Step through each price echo and add [WHAT EVER] to the output until you find the code being fired for your particular instance and then add the m2 code to it.
EDIT: Looks like you are editing the wrong file. You should edit template/catalog/product/price.html, not template/catalog/product/view/price.phtml. You can see from your screen grab and your code they are not the same. Your code is echo'ing 'old price' which doesnt appear.

Magento checkout working except for progress boxes

I have recently been having problems with Magento's one page checkout system.
At the moment it is working in a basic way, but the progress steps which are normally displayed on the right hand side are not being updated when the steps are completed. The step headings are showing up (Billing Address, Shipping Address, etc.), and I can control their styles through the boxes.css settings, but they don't get filled in with the content as the customer step through the process.
I have tried a number of solutions, including:
changing the xml and
tweaking the opchecout.js file
What is the best way to debug something like this?
check that the ID of the block you insert matches the ID that is refreshed by the JavaScript function. I had that problem. If you are using the base/default/js/opcheckout.js file, it should be
id='checkout-progress-wrapper'
like so (in your onepage.phtml template):
<div id="checkout-progress-wrapper">
<?php echo $this->getChildHtml('checkoutProgress') ?>
</div>
Best if you check the js file also

extract xpath

I want to retrieve the xpath of an attribute (example "brand" of a product from a retailer website).
One way of doing it is using addons like xpather or xpath checker to firefox, opening up the website using firefox and right clicking the desired attrbute I am interested in. This is ok. But I want to capture this information for many attributes and right clicking each and every attribute maybe time consuming. Also, the other problem I have is that attributes I maybe interested in will be there for one product. The other attributes maybe for some other product. So, I will have to go that product & then do it manually again.
Is there an automated or programatic way of retrieving the xpath of the desired attributes from a website rather than having to do this manually?
You must notice that not all websites use valid XML that you can use xpath on...
That said, you should check out some HTML parsers that will allow you to use xpath on HTML even if it is not a valid XML.
Since you did not specify the technology you are working with - I'll suggest the .NET HTML Agility Pack, if you need others, search for questions dealing with this here on SO.
The solution I use for this kind of thing is to write an xpath something like this:
//*[text()="Brand"]/following-sibling::*
//*[text()="Color"]/following-sibling::*
//*[text()="Size"]/following-sibling::*
//*[text()="Material"]/following-sibling::*
It works by finding all elements (labels) with the text you want and then looking to the next sibling in the HTML. Without a specific URL to see I can't help any further.
This is a generalised version you can make more specific versions by replacing the asterisks is tag types, and you can navigate differently by replacing the axis following sibling with something else.
I use xPaths in import.io to make APIs for this kind of thing all the time, It's just a matter of finding a xPath that's generic enough to find the HTML no matter where it is on the page, but being specific enough to get the right data.

Resources