Prestashop get the product default image from the product name? - module

In Prestashop I want to know by which pattern prestashop shows the product default image? I mean lets say I have a mysql query for prestashop like this
SELECT ps_product.id_product,ps_product.id_category_default,description_short,ps_product_lang.name FROM ps_product_lang,ps_product WHERE ps_product_lang.id_lang=1 AND ps_product.id_product=ps_product_lang.id_product
Now here I will get the product id, product category, description, and name.
Now according to prestashop default products and database I have for the product iPod Nano the database fields are like
id_product id_category_default
1 3
Now if I want to get the product image I will use
img/p/id_product/id_category_default/id_product.id_category_default
This will make the img src like
img/p/1/3/13.jpg
Now when I used that I got the image for Belkin Leather Folio for iPod
but with the same condition I got the exact image for ipod shuffle. So can someone kindly tell me how to get the exact default image for the product name? Any help and suggestions will be really appreciable.

You can use this query to get the image id of the cover image (image displayed in category view) for a product:
SELECT id_image FROM ps_image WHERE cover = 1 AND id_product = $idProduct
Then you can generate the image path with the following code:
$imgPath = 'img/p/';
for ($i = 0; $i < strlen($idImage); $i++) {
$imgPath .= $idImage[$i] . '/';
}
$imgPath .= $idImage . '.jpg';
If you want to get the image id of the default thumbnail displayed in the product view then you can use this query:
SELECT id_image FROM ps_image WHERE position = 1 AND id_product = $idProduct

Related

Prestashop module SQL Query to get id_products from a specific feature value

I'm currently working with a module called "Leo Parts Filter" on prestashop, which sort id_products by make, model, year and device in a database "ps_leopartsfilter_product".
When i call a make, model, year a device that have an id_product in this table, prestashop show this id_product.
public static $definition = array(
'table' => 'leopartsfilter_product',
'primary' => 'id_product',
'multilang' => false,
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'leopartsfilter_product` WHERE 1=1 ';
if ($id_product != null && (int) $id_product) {
$sql .= ' AND id_product =' . (int) id_product;
}
I would like to change the way id_product is called, instead of calling only this id_product according this way :
I would like to query all products where the feature_id = 212 and where the feature_value_lang = id_product.
I tried to adapt this query but i can't make it work correctly (no data showing)
SELECT id_product, fl.name, value, pf.id_feature
FROM '._DB_PREFIX_.'feature_product pf
LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature =212 AND fl.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature)
'.Shop::addSqlAssociation('feature', 'f').'
WHERE fvl.`value` = '['id_product']'
GROUP BY id_product
ORDER BY f.position ASC
';
I'm not good at SQL so don't blame me, i learned everything by my way and i try to build my own company website, this module is all i need to finish.
If someone want some money for help, i'm open to give rewards to make it work.
Thanks
Your second query has nothing to do with the Leo Parts Filter module, since it only queries native Prestashop feature tables and not those of the Leo module itself, so your request is not very clear.
If you need to rely on basic features, it must be clear to you that the relationship between id features / id feature values and id products is all in the ps_feature_product table, so if you want products that have id_feature_value = 212 you just need a simple
SELECT id_product FROM ps_feature_product WHERE id_feature_value = 212;

Odoo- How load products with multiple parents

I am working on Odoo 10e . I have situation which i am unable to solve in here.
I have a relation like following
Customer 1-------* Shipments 1-------* Shipment Detail 1-----* Products
Now i have a separate form in which i want to show products which are associated against a specific Customer in dropdown . How can i do this in Odoo
Do you mean you want to sort all products that have related to the Customer who selected in form view?
You can do this way:
#api.depends('customer')
def get_related_product(self):
res = []
#compute to get your product id here
return res
customer = fields.Many2one(....)
related_product = fields.Many2many(......., compute='get_related_product')

WooCommerce products shortcode order by sku list

Is there a way to modify the WooCommerce Products shortcode to order by a list of product sku's?
A search engine send a Post to the page with a list of sku's. The page should display the Products in the same order the http post is.
Example php and mysql select (the code like this worked in my old shop system where I can use SQL syntax):
$_POST['skus'] = "51,57,34,12,111";
$skus = $_POST['skus'];
select * from products where sku in ('$skus') order by FIELD(sku,'$skus);
How can I do an "orderby" like the example with products shortcode from woocommerce or is there a better way to do that with woocommerce?
Thanks for every answer.
With the help from Gavin and the code from https://wordpress.stackexchange.com/a/67830/43362
I found this solution:
function wpse67823_orderby_post_in($orderby, $query){
//Remove it so it doesn't effect future queries
remove_filter(current_filter(), __FUNCTION__);
$post__in = $_POST['skus'];
$post__in = str_replace(',','\',\'',$post__in);
return "FIELD(CAST(mt2.meta_value AS CHAR), '$post__in' )";
}
//Add filter and perform query
add_filter('posts_orderby','wpse67823_orderby_post_in',10,2);
echo do_shortcode('[products skus="'.$skus.'" orderby="sku"]');
remove_filter('posts_orderby','wpse67823_orderby_post_in',10,2);

Display Product Combinations in Prestashop Customer View

I am trying to get the product combinations displayed in Prestashop admin Customer detail view in addition to the products that are displayed for the customer.
This seems to be the relevant call from AdminCustomersController.php in public form renderForm():
$products = $customer->getBoughtProducts();
Then in the Customer class I found the method:
public function getBoughtProducts()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT * FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
WHERE o.valid = 1 AND o.`id_customer` = '.(int)$this->id);
}
How can I modify this method to show the product combination alongside the product name?
I am using Prestashop version 1.6.0.9.
you can get it using 2 ways:
order_detail table already have field 'product_name' that contains value like 'Product Name - Combination', so you can use $products['product_name'] in that case.
or
if for some reason it is not good for you, same table contains also product_attribute_id field, it is combination id, so:
$combination = new Combination($product['product_attribute_id']);
$attributes = $combination->getAttributesName($id_lang);
var_dump($attributes);
will give you array of attributes that current combination contains.

Magento SQL Query to show product manufacturer

I am trying to query the Product Manufacturer in Magento 1.7.0.2 . I browse again and again all the table to where I can get the manufacturer table and connect it with product SKU.
I try this query to hope that I can get the manufacturers of the product:
SELECT
eav_attribute_option_value.value FROM
eav_attribute,
eav_attribute_option,
eav_attribute_option_value
WHERE
eav_attribute.attribute_code = 'manufacturer' AND
eav_attribute_option.attribute_id = eav_attribute.attribute_id AND
eav_attribute_option_value.option_id = eav_attribute_option.option_id
but it is not equal to the product manufacturer when I compare the result to my magento admin product manufacturer.
My question is that what should I do to query so that I can get the list of manufacturers of the product so that I can sql join in with catalog_product_enity's SKU.
Does anyone has an idea about my case? I am new with magento so please be gentle with me.
Any help will be appreciated, Thanks in advance
I hope I understood correctly.
If you want to get the manufacturer for a product, you don't need any query.
This should work. Let's assume that you already have the product in var $_product;
$_product->getAttributeText('manufacturer');//this gets you the label
$_product->getManufacturer(); //gets the manufacturer id
[EDIT]
To get this for all the products do this:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('manufacturer');
$collection->addAttributeToFilter('status', 1);//optional for only enabled products
$collection->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search
foreach ($collection as $product) {
$sku = $product->getSku();
$manufacturerId = $product->getManufacturer();
$manufacturerLabel = $product->getAttributeText('manufacturer');
//do something with the values above - like write them in a csv or excel
}
Little late, but this is what I came up with. Works like a charm.
SELECT cpe.sku, cpev.value, cpf1.manufacturer_value
FROM catalog_product_entity cpe
JOIN catalog_product_entity_varchar cpev ON cpev.entity_id = cpe.entity_id
JOIN catalog_product_flat_1 cpf1 ON cpf1.entity_id = cpe.entity_id
WHERE cpev.attribute_id = 191