How to Properly Read Colon Tags (<p:id>) in google_merchant.xml in PHP
How to read xml with tags that have a colon <p:id>, like in Google Merchant upload. Using registerXPathNamespace or referencing the tag directly.
The other day, I faced the task of sorting the output of products according to a table that is not described in schema.xml. I will give a brief example of the table schema and table structure with positions, by which I should have sorted the products.
Simplified product table (merged the translation table with the main one and truncated the fields):
| id | (int) | product id |
| name | (string) | Name |
| create_date | (int) | the date |
Schema of this table (schema.xml):
<table name="shop_products" phpName="SProducts">
<vendor type="mysql">
<parameter name="Charset" value="utf8"/>
</vendor>
<column name="id" type="INTEGER" required="true" autoIncrement="true" primaryKey="true"/>
<column name="name" type="varchar" size="500" required="true"/>
<column name="create_date" type="INTEGER"/>
</table>
Let's say we have a binding of products to articles, and each article can have the same product and each product can have its own position in each article.
I will give an example of a table of articles and product links (let's call the table link_page):
| page_id | (int) | Article ID (given as an example) |
| product_id | (int) | Product ID from the SProducts schema |
| position | (int) | The position in which the product is in the article |
Here there is a position for each product in the article, but there is no link in the product table to make join a sing-song. So let's start doing this:
SProductsQuery::create()
->addJoin('shop_products.id' , 'link_page.product_id', Criteria::INNER_JOIN)
->addAsColumn('position', 'link_page.position')
->where('page_link_product.page_id = ' . 'ID страницы товара')
->orderBy('position','ASC')
->find();
In my case, the full path to Criteria::INNER_JOIN is \Propel\Runtime\ActiveQuery\Criteria::INNER_JOIN .
SProductsQuery - the generated model according to the scheme, simplified for understanding and described above.
This query will make it possible to connect a table not declared in the models to the query, so as not to make crutches and bicycles for sorting.
Try it, figure it out, in my case, addJoin() allowed me to save the time of rewriting and regenerating the schema for the needs, thereby not burdening the page of the article, which contains products.
How to read xml with tags that have a colon <p:id>, like in Google Merchant upload. Using registerXPathNamespace or referencing the tag directly.
Parsing JWT HS256 encryption, decrypting JWT HS256, comparing sha256 signatures for information integrity.
Let's look at fixing the disappearance of spaces before variables in the old version of Twig on php 7.4 without updating the version.
Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.
Latest templates from ImageCMS 4.12, authorization is required to download.