Expression Engine limiting pagination and reverse related entries - expressionengine

I have an EE site running EE 1.7. It is a magazine site that has monthly "Editions", each edition may or may not have a book review in it. On the site, I need to list the book reviews, in reverse chronological order by edition. Here's my code:
{exp:weblog:entries weblog="editions" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
{reverse_related_entries weblog="book-reviews"}
....
My problem is that the pagination is working based on the editions weblog, thus paging through editions that do NOT contain any book reviews. Thoughts?

A little tricky, you'll need to use an embed for this (or alternately you could create a small plugin to do this in a similar fashion).
Try this setup in your template. Replace the weblog_ids in the query with your own (in this example, 1 is editions and 2 is book-reviews).
{embed="embeds/reviews" entry_ids="{exp:query
sql="SELECT DISTINCT r.rel_child_id FROM exp_relationships r, exp_weblog_titles t WHERE r.rel_parent_id IN( SELECT entry_id FROM exp_weblog_titles WHERE weblog_id = 2 ) AND r.rel_child_id = t.entry_id AND t.weblog_id = 1"
backspace="1"}{rel_child_id}|{/exp:query}"}
Then, in embeds/reviews:
{exp:weblog:entries weblog="editions" entry_id="{embed:entry_ids}" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
{reverse_related_entries weblog="book-reviews"}
...

Related

How to get localized CMS Element config data in controller of shopware6

I have the following situation. I have a custom CMS-Element with a form in it, I send the data via a AJAX in a written JS-Plugin to a custom controller. Now I would like to read informations from the CMS-Element Config. I peeked inside the Source of the Contact-Form and ended in their controller where they read out the configuration. I implemented it in my controller and basicly it worked but the only thing that isn’t working is that I always get the config of one Language (German).
My Primary language is English and my secondary is German.
I took the “Dailymotion” example from the guides. And added melted it with the code from the other guide for AJAX calls. (For testing purpose)
https://developer.shopware.com/docs/guides/plugins/plugins/content/cms/add-cms-element
https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-dynamic-content-via-ajax-calls
In the source of the ContactForm (ContactFormRoute.php) are the lines with
$mailConfigs['receivers'] = $slot->getEntities()->first()->getTranslated()['config']['mailReceiver']['value'];
https://github.com/shopware/platform/blob/d6c853ca3b6b167d61d70e6329f4fcface5c5245/src/Core/Content/ContactForm/SalesChannel/ContactFormRoute.php#L182
I’ve added the same but I only get the secondary language config data.
I modified the code that he get the dailyUrl value from the config.
What I noticed is that in my $context the languageIdChain contains both language IDs (the first one is the German one) in the contact thereis only the languageId of the current language:
These are the languageIdChain of the Context sended in the English language. (2fbb5fe2e29a4d70aa5854ce7ce3e20b is the English Language)
Context languageIdChain of the Contact form controller:
#languageIdChain: array:1 [
0 => "2fbb5fe2e29a4d70aa5854ce7ce3e20b"
]
Context languageIdChain of my controller:
#languageIdChain: array:2 [
0 => "2d7d7d698f634a04b5796e49aa846ae6"
1 => "2fbb5fe2e29a4d70aa5854ce7ce3e20b"
]
Ok, you know the moments where you struggle many hours, try this and that and then do the Stack Overflow post an after a half hour you find the solution yourself.
The reason why I always get the German data instead the data of the current Language is that my AJAX call simply calls always the route for the German language /example like in the Guide shown.
Instead using a hard coded URL in the JS-Plugin I updated the template
<button id="ajax-button" data-url="{{path('frontend.example.example.submit')}}">Button</button>
And in my JS-Plugin I just read out the data-url
this.button = this.el.children['ajax-button'];
this.actionUrl = this.button.dataset.url;
This ways I get the url /example or /en/example depending on the current language.

Amazon Product Search API Python UPC

I am using this code to search for products on amazon. Is there a way for me to look the product up by UPC?
from amazon.api import AmazonAPI
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
product = amazon.lookup(ItemId='B00EOE0WKQ')
product.title
Well answer a bit late but for the sake of future genertions...
You can find all possible lookup types in scraper's documentation
Anyway to lookup object by UPC you use
api = API(locale='uk')
api.item_lookup([UPC], SearchIndex='Books', IdType='UPC')
Disclaimer: I do not have python-amazon-simple-product-api installed. (I use python-amazon-product-api 0.2.8)
However, I do believe that adding IdType='UPC', and SearchIndex='All' to your amazon.product call should get you closer.
e.g.:
product = amazon.lookup(ItemId='028000467012', IdType='UPC', SearchIndex='All')
also, be sure to use the IdType that matches your ItemId, to avoid errors.

How to set a category to a Liferay Web Content in Java?

In Liferay 7, I have a Web Content, a vocabulary and a category.
How to set the category to the Web Content?
I wrote this code:
article = JournalArticleLocalServiceUtil.addArticle(...);
category = AssetCategoryLocalServiceUtil.addCategory(...);
AssetCategoryLocalServiceUtil.setAssetEntryAssetCategories(
article.getPrimaryKey(), new long[]{category.getPrimaryKey()});
At execution no error, but the category does not show up on the edit page of the created Web Content:
The category has been created successfully, but the Web Content does not get that category assigned.
What am I doing wrong?
I have also tried addAssetEntryAssetCategories, addAssetEntryAssetCategory, addAssetCategoryAssetEntry: same problem.
Try using any of these 2 functions to add category:
addAssetEntryAssetCategory(long entryId, long categoryId);
addAssetEntryAssetCategories(long entryId, long[] categoryIds);
In your code, you are using primary_key, however, as per documentation you should be using entry id and category id. So your function call should look like this:
AssetEntry entry = AssetEntryLocalServiceUtil.fetchEntry(JournalArticle.class.getName(), article.getResourcePrimKey());
AssetCategoryLocalServiceUtil.addAssetEntryAssetCategory(
entry.getEntryId(), category.getCategoryId());
Since 7.0, they removed the getEntryId method from JournalArticle you would need an additional call to fetch it. There is a update method which you may also consider that would do this in single call. I'm still using 6.2 and catching up 7 :).
Please note categories are designed for use by administrators, not regular users.
I am using liferay 7.1 dxp
In my case I have to update category of journal article or web content using program.
In order to achieve this I have to use assetEntryAssetCategoryRel class.
to access this and related class first I added dependency to my build.gradle file
compileOnly group: "com.liferay", name: "com.liferay.asset.entry.rel.api", version: "1.1.0"
List<AssetEntryAssetCategoryRel> assetEntryAssetCategoryRelsByAssetEntryId = AssetEntryAssetCategoryRelLocalServiceUtil.
getAssetEntryAssetCategoryRelsByAssetEntryId(assetEntry.getEntryId());
if(assetEntryAssetCategoryRelsByAssetEntryId!=null && !assetEntryAssetCategoryRelsByAssetEntryId.isEmpty()){
AssetEntryAssetCategoryRel assetEntryAssetCategoryRel = assetEntryAssetCategoryRelsByAssetEntryId.get(0);
assetEntryAssetCategoryRel.setAssetCategoryId(assetCategory.getCategoryId());
assetEntryAssetCategoryRel = AssetEntryAssetCategoryRelLocalServiceUtil.updateAssetEntryAssetCategoryRel(assetEntryAssetCategoryRel);
}
I had assetentry and assetcategory object
This works fine for me

Search phrase in a sentence using Lucene 5.5

Purpose: To build a dictionary (Sample Dictionary taken from Gutenberg project). This application should have the capability to return the "word" is part of the meaning is provided. Example:
CONSOLE
Con*sole", v. t. [imp. & p.p. Consoled; p.pr. & vb.n. Consoling.]
Etym: [L. consolari,. p.p. consolatus; con- + solari to console, comfort: cf. F. consoler. See Solace.]
Defn: To cheer in distress or depression; to alleviate the grief and raise the spirits of; to relieve; to comfort; to soothe. And empty heads console with empty sound. Pope. I am much consoled by the reflection that the religion of Christ has been attacked in vain by all the wits and philosophers, and its triumph has been complete. P. Henry.
Syn. -- To comfort; solace; soothe; cheer; sustain; encourage; support. See Comfort.
So if my query is "To cheer in distress", it should return me "Console" as the output.
Am trying to build this tool using Lucene 5.5 (lower versions won't do for now). This is what I tried:
Indexing:
Document doc = new Document();<br>
doc.add(new Field(MEANING, meaningOfWord, Store.YES, Field.Index.ANALYZED));<br>
doc.add(new Field(WORD, word, Store.YES, Field.Index.ANALYZED));<br>
indexWriter.addDocument(doc);<br>
Analyzing:
Analyzer analyzer = new WhitespaceAnalyzer();<br>
QueryParser parser = new QueryParser(MEANING, analyzer);<br>
parser.setAllowLeadingWildcard(true);<br>
parser.setAutoGeneratePhraseQueries(true);<br>
Query query = parser.parse(".*" + searchString + ".*");<br>
TopDocs tophits = isearcher.search(query, null, 1000);<br>
This (tophits) is not returning me what I want. (I have been trying Lucene from last week or so, so please excuse if this is very naive). Any clues?
Sounds like a different analyzer was used when the documents were indexed. Probably KeywordAnalyzer or something. You (usually) need to pass the same analyzer to IndexWriter when indexing your documents as the one you will use when searching. Also, bear in mind, after correcting the IndexWriter's analyzer, you will need to reindex your documents in order for them to be indexed correctly.
Wrapping what should be a simple phrase query in wildcards is a extremely poor substitute for analyzing correctly.
Found the solution, use WildCardQuery, like this:
WildcardQuery wildCardQ = new WildcardQuery(new Term(MEANING, searchString));
But for incorrect words/phrases, it sometimes takes long time to come back with the answer.

Using a postcode range for shipping (expresso-store)

We're building a online-store/site for a winery, and they have a matrix/table of shipping costs to different regions (in Australia).
In Exp-resso Store 1.6.0, is there anyway of setting up a post-code for a specific shipping cost?
i.e. postcode= 2000-2249, 2555-2574 = $10 + $1/kg. 1250-1263 = $12 +$1.1/kg
Additional info: The deliveries are technically through AusPost, but using their "Wine Delivery Service" which doesn't match their normal parcel delivery stuff, so we can't use the AusPost plugin/API :(
There's no way to do this from the control panel. However, you can easily write your own shipping calculator using PHP.
An example of a simple custom shipping plugin is here:
https://gist.github.com/2176462

Resources