Dynamic variables FOP / XSLT – font changing problem (switching font languages)
I’ve been working on the PDFs once again and I’ve spotted that I have a problem with changing languages depending on the variables. In other words if somebody speaks Asian languages font should be different than Arial.ttf which is as defualt.
To solve this problem we need to change our XML file which is used for populating all fields in the PDF to add to them another option indicates language parameter. Below you’ll find my quick solution for this problem. I assume that you’ve already configurated your envirovement and FOP / PDF thing.
1 2 3 4 5 6 7 8 9 10 |
<xsl:variable name="font"> <xsl:choose> <xsl:when test="language = 'JA'">japan-font</xsl:when> <xsl:otherwise>standard-font</xsl:otherwise> </xsl:choose> </xsl:variable> <fo:root font-family="{$font}"> .. your code here </fo:root> |
In Java, first I’m getting XML and parse it putting the value indicates language in the XML. Something like this
1 2 3 |
// … doc = dBuilder.parse(xmlfile); doc.getFirstChild().getChildNodes().item(1).getFirstChild().setNodeValue("JA"); |
In my XML file the first node within the root is
1 2 3 |
<documents> <language>language</language> </documents> |
So I’m dynamically changing language node to the language parameter and in XSL file I am just choosing in using the structure that I’ve written above. And that’s all.
1 2 3 4 5 6 7 8 9 |
<xsl:variable name="font"> <xsl:choose> <xsl:when test="language = 'RU'">123arial</xsl:when> <xsl:otherwise>999arial999</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:value-of select="$font" /> |
Drupal, UberCart – How to return / get back the cart from database
I’ve tried to found the solution how to revert the cart that is already in the database but as always I didn’t found any good solution though. I was looking the files which can help me to regenerate it and finally I’ve found it! Below you got the code that get any cart from the db and populate it.
1 2 3 4 5 6 7 8 9 10 |
function revertCart($cartId) { $items = uc_cart_get_contents($cartId, 'rebuild'); if (! empty($items)) { foreach ($items as $item) { uc_cart_add_item($item->nid, $item->qty, $item->data); } } } // revertCart('the ID from uc_cart_products |
Enjoy!
How to Change the Original Price in Prestashop
That’s a really useful snipet for anybody who wants to change the original price to the new one.
Solution for this is very easy …
Ok .. here it is:
Product.php, line 1686
1 2 3 4 5 6 |
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = NULL, $id_cart = NULL, $id_address = NULL, &$specificPriceOutput = NULL, $with_ecotax = TRUE) { // .... find some space before `return` $my_new_price = Warehouse::getPriceByDay(); return $my_new_price; |
Using PayPal WPP (Express Checkout) with Django
A couple days ago I had to deal with PayPal WPP (Express Checkout) for some application and I found the module in the GitHub: https://github.com/dcramer/django-paypal.
Which works great but it was very hard to find how to set up the PayPal Payment Pro with Express Checkout method and fill customer forms in PayPal. I decided to find how to deal with it and I figured out how to do that.
After all developing stuff related to install this module to your django aplication you need to know how to send requests to PayPal using this method. And here’s the answer:
Read the full article »