joomla virtuemart search slash error - joomla

i am currently developing one joomla site which contains virtuemart and my written component which is working quite well, but the problem shows up when i try to search for products using virtuemart search in example when i search for 12/4 name it replaces 12/4 name with 124 name and displays no results.
So the question is where is that sql-query that loads those items so i can modify it?
or is there another plug-in or something that works with / or is there somekind of fix to this problem?

So after a while i finnaly fixed this issue. My fix is not weary good beacose i didn't find where exactly virtuemart component removes slash from search query so i just did like this......
As frontend uses modules who are located at admin/components/com_virtuemart/modules i had to edit module named product. And in the function named sortSearchListQuery2 i added some code
if ($useCore) {
// if ( $this->keyword !== "0" and $group ===false) {
if (!empty($this->keyword) and $this->keyword !== '' and $group === FALSE) {
$this->setKeyWord($_GET['keyword']);//Added this line!
//$keyword = trim(preg_replace('/\s+/', '%', $keyword), '%');
$keyword = '"%' . $this->_db->getEscaped ($this->keyword, TRUE) . '%"';
//var_dump($keyword,$this->keyword,$_GET['keyword']); debug_zval_dump($keyword); debug_print_backtrace(); die();
And on frontend view named Category in view.html.php i replaced $keyword=vmRequest::uword('keyword', '', ' ') with $keyword = $_GET['keyword']
And that is my approach to fix this problem!

Related

Drupal 7 - Image alt and title text bulk change for existing elements

I have a Drupal commerce website with about 100 000 products. Now customer wants me to change product image filenames and add alternative(alt) texts to images for all existing products - based product names and colors.
File field paths seemed to be great to changing the file names of image files. But I just cannot figure out how to add alt texts to images automatically. I've been trying hook_file_update, hook_file_presave, hook_entity_presave etc. I'm trying to add alt text during File field paths' batch update and all of the hooks are running but for some reason alt text data is not saved to entity.
Product image field is type of Image with Media browser widget.
Any help for this?
Here's hook_entity_presave() code:
if ($entity->type == 'image' && (empty($entity->alt) || empty($entity->field_file_image_alt_text))) {
$product = _get_referenced_product($entity->fid);
if ($product) {
$full_product = commerce_product_load($product->product_id);
$title = $full_product->title;
if (!empty($full_product->field_search_color)) {
$search_color = $full_product->field_search_color[LANGUAGE_NONE][0]['tid'];
$search_color = taxonomy_term_load($search_color);
$color_name = $search_color->name;
}
$entity->alt = $title . ' ' .ucfirst($color_name);
$entity->field_file_image_alt_text = $title . ' ' .ucfirst($color_name);
object_log('Entity', $entity);
object_log('Type', $type);
}
}
I had the same issue and I updated the alt tag of all images in my articles. Note, in my case I wanted to updated nodes.
And, I used following code:
https://www.gyanblog.com/gyan/34-how-add-alt-attribute-images-all-my-drupal-articles-or-other-content-type/
Actually the problem in my case was that I was trying to set alt field value in wrong way. "Field_file_image_alt_text" field the image element is using is a normal textfield so it clearly needs the following data structure.
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $title . ' ' .ucfirst($color_name);
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['safe_value'] = $title . ' ' .ucfirst($color_name);
So just a stupid mistake by me! And btw, I ended up using hook_file_presave() hook.

Google Sitemap issue Contao 4.4

I am using contao 4.4 instance.I have a problem in google sitemap generation.
I have a newsletter page (page type = regular ) . In that page I have some newsletter articles (with teaser) . When I generate the sitemap, the url of these articles generated twice. When I checked the core I found a class which creates the page array for generating sitemap
vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php
line no 662 - 680 .
Which append 'articles/' to the articles with teaser. So the sitemap generates url
with articles/
List item
without articles/
The first one is the correct url.Second Url generate 404. How I fix the issue ?
My siteconfiguration is as follows
->created a regular page with hidden in navigation and created articles with configuration show teaser
->created another page and created elements as 'teaser articles' and select articles from the above page
So your site structure is like this?
Page 1 with multiple articles
Page 2 with one article containing an „article teaser“ element, this page should be excluded from the sitemap
Is that correct? If yes this might be the solution:
In your „site structur“ you can EDIT Page 2: Scroll down to „Expert settings“, there is an option „Show in sitemap“ and you can select „Never show“.
I resolved the issue.
The url's were regenerated from the newsletter-bundle. In core bundle, the url of the article with teaser is generated. The newsletter-bundle is also contain hook for creating searchable page array. The hook regenerates the url. I wrote a function in vendor/contao/newsletter-bundle/src/Resources/contao/classes/Newsletter.php to check whether the array contain any duplicate url.
Modified function getSearchablePages() ( line 889-897
)
if($this->checkValidUrl($arrPages, $objItem, $strUrl)){
$arrPages[] = sprintf($strUrl, ($objItem->alias ?: $objItem->id));
}
Defining new function for finding duplicate
public function checkValidUrl($arrPages, $objItem, $strUrl)
{
$alias = $objItem->alias ?: $objItem->id;
$urlExplode = explode('%s', $strUrl);
$articleUrl = $urlExplode[0] . 'articles';
foreach ($arrPages as $arrPage) {
$validarticleUrl = $articleUrl . '/' . $alias;
if (strcasecmp($arrPage,$validarticleUrl) == 0) {
return false;
}
}
return true;
}

how to apply custom sanitation on inputs in codeigniter

I want to remove all multiple spaces from inputs (get) using this code:
preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $search);
but I don't know where to put this code so that it would affect all $this->input->get('myfield'); ?
EDIT
maybe I wasn't clear enough.. what I needed is one code that can affect all inputs in all modules throughout my project. e.g. by creating a function in the libraries or editing MY_Controller.php
You can put as like
<?php
$search = $this->input->get('myfield');
$search = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $search);
print $search;
?>

Migrating Wordpress Images to Drupal with Migrate 2.4

I'm having a time migrating images from Wordpress to Drupal with the Migrate 2.4 module. Here are my mappings:
$this->addFieldMapping('field_image','images');
$this->addFieldMapping('destination_file', 'images');
$this->addFieldMapping('field_image:source_dir')
->defaultValue('/Users/grafa/htdocs/wordpress/wp-content/uploads');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileUri');
The images come from a function that queries the wp_postmeta table then returns the result to the prepareRow() function.
function getImages($row) {
$post_id = $row->id;
$results = db_query("
SELECT pm.post_id, pm.meta_key, pm.meta_value FROM streetroots_wp.wp_postmeta AS pm LEFT JOIN streetroots_wp.wp_posts AS p ON pm.post_id=p.id WHERE p.post_parent = $post_id AND pm.meta_key='_wp_attached_file';");
$images = array();
foreach($results as $result) {
$images[] = $result->meta_value;
}
return !empty($images) ? $images : NULL;
}
This basically returns the image name and relative path from the wp_postmeta table something like '2012/05/figure1.jpg'. I then use prepareRow() like this:
function prepareRow($row) {
$row->images = $this->getImages($row);
}
I'm guessing there's something funky with how I'm using the new-ish migrate module that handles the file fields. The sql is outputs the file names correctly but it doesn't seem like the images are getting copied over. This is a Drupal 7 using Migrate 2.4. Any help is appreciated.
You might want to have a look at the beer.inc lines 377 - 383 within migrate_example folder and at the associated content type *migrate_example_beer* which has an image field defined not a file field which was my mistake and lead to my images not being populated.
Hope this helps!
Migrate 2.5 has largely simplified the handling of files, you should check it out!

Magento getProductUrl() is not returning the right url (random?)

I am using Magento 1.5.0.1 and the getProductUrl() function used in the cross sell and up sell blocks on the product page is throwing up different URL formats.
Either the correct url like:
/laptop-bag.html
Or the wrong one (well it works, but of course its not the rewrite URL):
/catalog/product/view/id/825/s/laptop-bag/category/16/
Sometimes both cross sell and up sell blocks return the correct URL, sometimes both use the longer version, and in some cases, one uses the correct and the other uses the long version??
Any ideas why this is happening?
I have already run a magento database repair, reindexed, and refreshes / flushed all caches.
Try $product->getUrlPath() instead of $product->getProductUrl()
UPDATE: As per below comment by #jordan314, Magento recommends to EE customers:
The url_path attribute is no longer used as of 1.13 but is still available for backward-compatibility, and Magento will not assign a value to it for new products, so it's not recommended to continue using it. Perhaps you could try using $product->getProductUrl() instead.
The incorrect url is generated because it can't find the rewritten url.
Maybe it is caused because incorrect store_id.
eg:
$id = 290;
Mage::app()->setCurrentStore('default');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
//change store id
Mage::app()->setCurrentStore('admin');
echo "store_id: ".Mage::app()->getStore()->getId()."<br>";
$url = Mage::helper('catalog/product')->getProductUrl($id);
echo $url."<br>";
result:
store_id: 1
http://local.com/surestep-pro-diabetic-test-strips-50-strips-professional-care.html
store_id: 0
https://local.com/index.php/catalog/product/view/id/290/s/surestep-pro-diabetic-test-strips-50-strips-professional-care/
The correct url rewrite can be found in table named core_url_rewrite (including the information about the store_id)
If it found match value in core_url_rewrite, it will generate 'the correct url' else it will concat the product_id + url key + category_id
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
Try add this when you're getting your collection
$collection->addUrlRewrite();
It has helped me.
$id = 10;
Mage::app()->setCurrentStore('admin');
$url = Mage::helper('catalog/product')->getProductUrl($id);

Resources