I'm using ExpressionEngine for a multi-language website with products. I used Transcribe for controlling the multi-language. Products have the same title in different languages, and this gives me some problems selecting the correct product in a relationship field.
The builder of this site did not use the title for a unique name in the back-end only, but also displayed it everywhere in the front-end.
Dropdown example:
Product A
Product A
Product A
Product B
Product B
Product B
Product c
Product c
Product c
I found that the dropdown information is filled in /system/expressionengine/fieldtypes/rel/ft.rel.php from line 59
/**
* Display Relationship Field
*
* #access public
* #param string
* #return string
*/
function display_field($data)
{
if ($this->settings['field_related_orderby'] == 'date')
{
$this->settings['field_related_orderby'] = 'entry_date';
}
$this->EE->db->select('entry_id, title');
$this->EE->db->where('channel_id', $this->settings['field_related_id']);
$this->EE->db->order_by($this->settings['field_related_orderby'], $this->settings['field_related_sort']);
if ($this->settings['field_related_max'] > 0)
{
$this->EE->db->limit($this->settings['field_related_max']);
}
$relquery = $this->EE->db->get('channel_titles');
if ($relquery->num_rows() == 0)
{
return $this->EE->lang->line('no_related_entries');
}
else
{
if ( ! isset($_POST[$this->field_name]))
{
$this->EE->db->select('rel_child_id');
$relentry = $this->EE->db->get_where('relationships', array('rel_id' => $data));
if ($relentry->num_rows() == 1)
{
$data = $relentry->row('rel_child_id') ;
}
}
$field_options[''] = '--';
foreach ($relquery->result_array() as $relrow)
{
$field_options[$relrow['entry_id']] = $relrow['title'];
}
return form_dropdown($this->field_name, $field_options, $data, 'id="field_id_'.$this->field_id.'"');
}
}
How can I add the language name to the dropdown at line 98 ($field_options[$relrow['entry_id']] = $relrow['title'];)?
Transcribe did not found any possibilities in Expression Engine 2.5.
I created a workaround and added the url_title in the dropdown menu. It is not the best solution, but in this case it is workable.
$this->EE->db->select('entry_id, title');
changed into
$this->EE->db->select('entry_id, title, url_title');
And changed
$field_options[$relrow['entry_id']] = $relrow['title'];
into
$field_options[$relrow['entry_id']] = $relrow['title'] . " - " . $relrow['url_title'];
Related
I'm pretty new to PrestaShop - so sry if i ask basic thing
I'm currently working on a module which should display products you chose in the backend as additional section in the default products template - like "highly recommended products"
I finish the whole Backend part, and get the ID's as an array of the chosen products.
As I mentioned I wanna use the default templates which are available after a fresh installation and what I found is placed here themes\classic\templates\catalog\_partials\products.tpl.
Now my big problem is: I'm not able to get the data like it should be ...
If I debug e.g. the products which are displayed in the default search behaviour (this uses this template too) I see something like
object(PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingLazyArray)#323 (11) { ["imageRetriever":"Pr .....
but as I get my products with
new Product($productId, true);
it is no ProductListingLazyArray ... its just an array with products ... and i dont see anything in the frontend (of course I dont, cause e.g. {$product.id_product} doesnt look like this in my array ...
Have you any ideas what I can do to "transform" my array of products to an ProductListingLazyArray ??
Or is my thinking wrong ?
THANKS to you all!
Solution
I just "faked" a search and check if the data is in my array:
/**
* creates relevant product information for frontend output
*
* #param array $allSelectedProductIds array with all id's of the selected products
* #param int $languageId language id of the shop you are in
*
* #return array all product information we need for our frontend rendering
*/
public function getFrontendProductInformation($allSelectedProductIds, $languageId)
{
// set default category Home
$category = new Category((int)2);
// create new product search proider
$searchProvider = new CategoryProductSearchProvider(
$this->context->getTranslator(),
$category
);
// set actual context
$context = new ProductSearchContext($this->context);
// create new search query
$query = new ProductSearchQuery();
$query->setResultsPerPage(PHP_INT_MAX)->setPage(1);
$query->setSortOrder(new SortOrder('product', 'position', 'asc'));
$result = $searchProvider->runQuery(
$context,
$query
);
// Product handling - to get relevant data
$assembler = new ProductAssembler($this->context);
$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
$presenter = new ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
$products = array();
foreach ($result->getProducts() as $rawProduct) {
$productId = $rawProduct['id_product'];
if(in_array($productId, $allSelectedProductIds)) {
$product = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
array_push($products, $product);
}
}
return $products;
}
I am using Drupal 7 with the search api. I understand that one of the 'common pitfalls' of the search api is 'Changes in related entities don't lead to re-indexing'. I am bringing in a field called 'Collection Reference' in my search api index as 'type = content' . So when the title of a collection changes the search API doesn't realise it changes.
I have tried to sort this using the rules module as discussed - https://www.drupal.org/docs/7/modules/search-api/getting-started/common-pitfalls#indirect-changes - but I have not been able to get it working. Has anybody had any luck with this technique?
I solved the issue.
In my case I have photographs in an index and they have a gallery as an entity field and the galleries were not updating if they were modified in the photo index. So grabbed all of the photos relating to that gallery using SQL then put into a dirty ids array. So the code below:
function hook_entity_presave($entity, $type) {
if ($entity->type == 'MYCONTENTTYPE') {
if ($entity->original->title !== $entity->title) {
$dirty_ids = array();
$nid = $entity->nid;
$result = db_query('SELECT g.entity_id FROM {gallery} g WHERE c.id = :nid', array(':nid' => $nid));
foreach($result as $record) {
$dirty_ids[] = $record->entity_id;
}
if(!empty($dirty_ids)) {
search_api_track_item_change('node', $dirty_ids);
}
}
}
}
I was watching how to create a php code to show in a the countries chosen in the column enum type in the database, and in turn show the chosen country by default.
But it does not show the list of countries to select, it only shows the one I have selected and the rest is blank.
public static function getAllowFlags(){
$flaglist = [];
$flag_q = Db::query('SELECT flag FROM players');
while($l = $flag_q->fetch_assoc()) {
$flaglist[] = $l;
}
return $flaglist;
}
$AllowFlags = Account::getAllowFlags();
<?php foreach($AllowFlags as $key => $flag) { ?>
<option value="<?=$flag['flag'];?>" <?=$flag['flag']?'selected':'';?>><?=$flag['flag'];?></option>
<?php } ?>
Finditemsadvanced call in Ebay webservices and in the SDK for PHP includes the possibility to getHistograms for categories.
FindingServices.php display the following code:
public function getHistograms(\DTS\eBaySDK\Finding\Types\GetHistogramsRequest $request)
{
return $this->callOperation(
'getHistograms',
$request,
'\DTS\eBaySDK\Finding\Types\GetHistogramsResponse'
);
}
public function findItemsAdvanced(\DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest $request)
{
return $this->callOperation(
'findItemsAdvanced',
$request,
'\DTS\eBaySDK\Finding\Types\FindItemsAdvancedResponse'
);
}
In my controller I try two version to call FindingItemsAdvanced including GetHistograms.
/** Create the service object.*/
$service = new DTS\eBaySDK\Finding\Services\FindingService(array(
'appId' => $config['production']['appId'],
'apiVersion' => $config['findingApiVersion'],
'globalId' => DTS\eBaySDK\Constants\GlobalIds::US
));
/** Create the request object.*/
$request = new DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest();
$request->keywords = 'ipod nano';
$request->categoryId = array('73839');/** Search across two categories. * DVDs & Movies > DVDs & Blue-ray (617) * Books > Fiction & Literature (171228)*/
$request->outputSelector = array('AspectHistogram','CategoryHistogram','SellerInfo');
$itemFilter = new DTS\eBaySDK\Finding\Types\ItemFilter();/** Filter results to only include auction items or auctions with buy it now. */
$itemFilter->name = 'ListingType';
$itemFilter->value[] = 'FixedPrice';
$itemFilter->value[] = 'AuctionWithBIN';
$request->itemFilter[] = $itemFilter;
/** Get Histograms */
check below option 1 and option 2 and its errors
/** response */
$response = $service->findItemsAdvanced($request);
using option 1:
$request->getHistograms = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$request->getHistograms = (array('73839'));
but its giving me the following error: Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::getHistograms
using option 2:
$request1 = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$histograms = $service->getHistograms($request1);
$request->$histograms = (array('73839'));
but its giving me the following error: "Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::Object"
I know that in the SDK getHistograms() is not part of FindItemsAdvanced() but its a part of FindingService.php consequently I assume it could be called in the same action. Any help or example code using finditems with histograms in same call appreciated.
The category that you are using is Consumer Electronics > Portable Audio & Headphones > iPods & MP3 Players (73839). While this is a valid category ID, both getHistograms and findItemsAdvanced will not return a categoryHistogram element. The reason for this is explained in the documentation for getHistograms
This container is returned only when the specified category has
children categories.
And also in the findItemsAdvanced documentation.
The category IDs returned for items in search results are for the leaf
categories in which the items are listed. If you use these category
IDs as input, the response will not return a category histogram.
In other words the categoryHistogram element will not be returned by either service if a leaf category is specified in the request. A leaf category is just a category that has no children. Since the category 73839 is a leaf category you will instead have to use its parent Consumer Electronics > Portable Audio & Headphones (15052).
The links below should return the categoryHistogram. You just need to replace <YOUR APP ID> in the URL.
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052&outputSelector(0)=AspectHistogram&outputSelector(1)=CategoryHistogram&outputSelector(2)=SellerInfo
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=getHistograms&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052
I'd like to export categories from one magento store and import to another one.
The following information is part of categories which must to inserted in store.
Default Category 2
All Categories 2/30
Electronics 2/30/12
TV & Video 2/30/12/13
I try this following script to import one category but doesn't work. The script doesn't import the category.
require_once 'app/Mage.php';
Mage::app('default'); // Default or your store view name.
//get a new category object
$category = Mage::getModel('catalog/category');
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId().
//if update
if ($id) {
$category->load($id);
}
$general['name'] = "All Categories";
$general['path'] = "2/30"; // catalog path
$general['description'] = "";
$general['meta_title'] = ""; //Page title
$general['meta_keywords'] = "";
$general['meta_description'] = "";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['page_layout'] = 'two_columns_left';
$category->addData($general);
try {
$category->save();
echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
echo $e->getMessage();
}
I copied your exact code and tested it. As you sad, script is sucessfull but no category in magento backend ... but there is one in the database, just check the table catalog_category_entity.
The problem is, you pass the wrong path property. The top category is allways ID=1. When, after installation, you create your catalogs top category, it will be something greater then 1. In my case it is ID=3.
So to order the new category below the root category I created (ID=3), I must set the value 1/3 for path
$general['path'] = "1/3"; // catalog path
In your case I gues it should work with the following value
$general['path'] = "1/2/30"; // catalog path