prestashop get total quantity - combinations

I would like to output my products quantity, but if product has combination I can`t get quantity.
Im using: $product[ 'quantity' ] to get product quantity. It works if I have product without combinations.
And its strange that in BO if I open products tab I can see total quantity: 20 (10 qnt red comb, 10 qnt black comb). So it would be fine for me. But when im exporting data i get quantity: 0 because main product quantity: 0 and product has 10 red qnt and 10 black qnt combination. Im able to get attributes list, but how to get combination list with quantities or just total quantity?

If you need it at the Front Office template, you need to call is as object property:
{$product->quantity}
This will return the total quantity of all combinations.
If you need it at the controller, it's the same:
$product = new Product($id_product);
echo $product->quantity;
This will return again the total quantity of all combinations.
Regarding the database: The quantities are being kept at the: ps_stock_available table. If you need to get the total quantity of a product including combinations, get the "quantity" field where "id_product_attribute" = 0.
Here's a sample query for product with ID=1:
SELECT p.id_product, sa.quantity
FROM ps_product p
INNER JOIN ps_stock_available sa ON p.id_product = sa.id_product AND id_product_attribute = 0
WHERE p.id_product = 1
If you loop through products from $products = Product::getProducts(...)
foreach ($products as $product)
echo Product::getQuantity($product['id_product']);

In templates (Smarty) you can use:
{$product->quantity_all_versions}
{$product.quantity_all_versions}

To get quantity with Sizes I use Advanced -> SQL Manager
SELECT DISTINCT CONCAT(ps_product_lang.id_product) AS ID, CONCAT(ps_product_lang.name) AS Nazwa, CONCAT(ps_attribute_lang.name) AS Rozmiar, CONCAT(ROUND(ps_product_shop.price*1.23,2)) AS Cena, CONCAT(ps_stock_available.quantity) AS Ilość, CONCAT('http://pasujemito.pl/',ps_category_lang.link_rewrite,'/',ps_product_lang.id_product,'-',ps_product_lang.link_rewrite,'.html') AS Link
FROM ps_stock_available INNER JOIN ps_product_lang
USING (id_product) INNER JOIN ps_product_attribute_combination
USING (id_product_attribute) INNER JOIN ps_attribute_lang
USING (id_attribute) INNER JOIN ps_product_shop
USING (id_product) INNER JOIN ps_category_product
USING (id_product) INNER JOIN ps_category_lang
USING (id_category)
WHERE quantity=0 AND id_category NOT IN (1 ,2, 44, 45, 46, 75) AND (id_product_attribute!=0)
ORDER BY Nazwa;
or if I want to see image link:
SELECT DISTINCT CONCAT(ps_product_lang.id_product) AS ID, CONCAT(ps_product_lang.name) AS Nazwa, CONCAT(ps_attribute_lang.name) AS Rozmiar, CONCAT(ROUND(ps_product_shop.price*1.23,2)) AS Cena, CONCAT(ps_stock_available.quantity) AS Ilość, CONCAT('http://pasujemito.pl/',ps_image.id_image,'-tm_thickbox_default/',ps_product_lang.link_rewrite,'.jpg') AS Zdjęcie
FROM ps_stock_available INNER JOIN ps_product_lang
USING (id_product) INNER JOIN ps_product_attribute_combination
USING (id_product_attribute) INNER JOIN ps_attribute_lang
USING (id_attribute) INNER JOIN ps_product_shop
USING (id_product) INNER JOIN ps_image
USING (id_product)
WHERE quantity=0 AND (ps_image.position=1) AND (id_product_attribute!=0)
ORDER BY Nazwa;

Related

How do i update sql value with sum comparison

I am trying to update a value to show the picked status of an order based on the picked status against the order qty. The data is in the same table but i cannot figure out the correct syntax. I tried:
Update Orders set Status = 'FULL' where Sum(Qty_Order) = sum(Qty_Picked)
How can i apply this logic using an aggregate query?
Thanks in advance for any help/
One approach uses an update join:
UPDATE Orders o1
INNER JOIN
(
SELECT id
FROM Orders
GROUP BY id
HAVING SUM(Qty_Order) = SUM(Qty_Picked)
) o2
ON o2.id = o1.id
SET
Status = 'FULL';
This assumes that your Orders table has a column id which uniquely identifies each order.

Using SELECTEDVALUE in PowerBI

I have a table that contains the sample data from the attached image.
The sample table can be interpreted as follows: I have a list of customers with Customer_id, Customer_name and Email that have an account on 1 or more e-commerce sites. Every e-commerce site can be identified by the EcommerceSite_Id column.
If a customer has more than one account (eg: on EcommerceSite_Id = 111 and also on EcommerceSite_Id = 112) the GlobalClient_Id will have the same value (e.g. John has an account on the following EcommerceSite_Id: 111, 113 and 114. Therefore, he has the same GlobalClient_Id – “11” which is attributed based on some automatic criteria – in this example, email address).
What I want to achieve:
By using a slicer with the EcommerceSite_Id column, when selecting the EcommerceSite_Id 114, it should display all customers with a unique email address, that do not have an account in 114, by taking into account the GlobalClient_Id.
Therefore, the output should be
:
Therefore, as you can see I excluded the following customer_ids: 5 and 9. They do not have an account on 114, but I excluded them because they have the same ClientGlobal_Id with customers_ids 10 and 8, customers that have an account on 114.
I cannot find a solution. I tried to use selected values, but I don’t know if I am using it correctly.
Can you please give me an idea on how to solve it?
Welcome to SO. Here's one solution that might work for you:
Step 1. EcommerceSite_Id needs to be added to a separate table - it will contain distinct IDs:
Here's how the data model should look like:
Step 2. Create a measure
For each client, the measure will count the number of rows where a chosen EcommerceSite_Id appeared:
mExclude =
var EcommerceSite = SELECTEDVALUE(ES[EcommerceSite_Id])
var ThisCustomer = SELECTEDVALUE(CustomerData[Customer_name])
var Check = COUNTROWS(FILTER(ALL(CustomerData), CustomerData[Customer_name] = ThisCustomer && CustomerData[EcommerceSite_Id] = EcommerceSite))
return
Check + 0
When added to a table, and having a single EcommerceSite_Id selected (use your new table as a slicer), you get the following results:
Step 3. Finishing up
Finally, remove mExclude form the table and add it to the table filters. Set it up to filter values that are equal to zero.
The final result:

Google Sheet Formula for finding an element across multiple tabs

I`m trying to populate values in column F, "Product Sold Date" in "TABLES" tab
Basically... the logic is as follows:
1) If Column C (Product Status) = "Paused", then return "Paused"
2) If Product start date = NULL or Product end date = NULL, then return NULL
3) If Product start date < today`s date, then return "No Data"
4) If Product start date >= today`s date, return "Upcoming"
5) If product End date <= today`s date, return "Ended"
6) If product start date <= today`s date, return "In Market"
7) If the condition does not belong to any of the above cases, then return the actual Product launch dates
Below is the link to the sample data I`m working on..
I`m pasting the link itself, becaues there are multiple tabs included
https://docs.google.com/spreadsheets/d/120rHOt8Pa_PdMKPgLkSYOKTO2Cv1hBH6PpTrg7FfJLk/edit?usp=sharing
Ultimately, I need to populate the actual "Product Launch Date" by scanning data in each tab
I tried using nested if statements with combination of Index Match.
But I`m totally lost in case of multiple tabs
Can anyone please provide suggestion on this?
Should we think about using query statements instead in this case?
Sidenote: The returned values will be mix of dates and character
[In market/ Ended/ Upcoming/ No Data/ NULL/ Paused/ Actual Date]
=ARRAYFORMULA(
IF(C2:C="Paused", C2:C,
IF((A2:A="")+(B2:B=""), ,
IF(A2:A >= TODAY(), "Upcoming",
IF(B2:B <= TODAY(), "Ended",
IF(A2:A = TODAY(), "In Market",
IF(E2:E<>"", IFERROR(VLOOKUP(D2:D&E2:E,
{'Eaton Centre'!A2:A &"Eaton Centre", 'Eaton Centre'!B2:B;
'Yorkdale Mall'!A2:A&"Yorkdale Mall", 'Yorkdale Mall'!B2:B;
'Vaughan Mills'!A2:A&"Vaughan Mills", 'Vaughan Mills'!B2:B}, 2, 0)), )))))))
Your formula would be
=IF(C2="Paused",C2,if(OR(A2="",B2=""),"",IF(A2<TODAY(),"No Data",IF(A2>=TODAY(),"Upcoming",IF(B2<=TODAY(),"Ended",IF(A2<=TODAY(),"In Market","Actual Product Launch dates"))))))
In the above formula, you should be using a Query formula in place of "Actual Product Launch dates", to extract the actual date.
But the points 3 & 6 don't make any sense. The 6th condtion should be If product start date = todays date, return "In Market"

PowerBI DAX function to count number of occurrences using DISTINCT (Countif)

I am trying to create a column in PowerBI that counts how times a customer name occurs in a list.
I may be going in the wrong direction, but what I have so far is;
My SQL query returns a table of customer site visits (Query1), from which I have created a new table (Unique) and column (Customer) that lists the distinct names (cust_company_descr) from Query1;
Unique = DISTINCT(Query1[cust_company_descr])
What I need is a new column in the Unique table (Count) that will give me a count of how many times each customer name in the Query1 table appears.
If I were working in Excel, the solution would be to generate a list of unique values and do a COUNTIF, but I can't find a way to replicate this.
I have seen a few solutions that involve this sort of thing;
CountValues =
CALCULATE ( COUNTROWS ( TableName ); TableName[ColumnName] = " This Value " )
The issue I have with this is the Unique table contains over 300 unique entries, so I can't make this work.
Example (The Count column is what I'm trying to create)
Query 1
cust_company_descr
Company A
Company B
Company A
Company C
Company B
Company A
Unique
Company_____Count
Company A_____3
Company B_____2
Company C_____1
Any help is gratefully received.

Doctrine distinct createQueryBuilder

I am trying to select MAX scores objects for unique user(s).
So user should be distinct and i should receive max score for a user (order), and I need to get other object values like dataAdded for this max score.
$query = $this->createQueryBuilder('s');
$query->select('DISTINCT s.user, s');
$query->where('s.challenge = :challenge')->setParameter('challenge', $challenge);
$query->andWhere('s.date_added BETWEEN :monday AND :sunday')
->setParameter('monday', $startDate->format('Y-m-d'))
->setParameter('sunday', $endDate->format('Y-m-d'));
$query->orderBy('s.score', 'DESC');
//$query->groupBy('s.user');
$query->setMaxResults($limit);
$results = $query->getQuery();
Does not matter how I try i can't make distinct to work. I have tried group by MAX(s.score) but this will associate random object with max score rather then the same object..
Does anyone have a solution to this? Distinct simply don't seem to work...
Generated query:
SELECT DISTINCT s.user, s FROM Digital\ApplicationBundle\Entity\ChallengeScore s WHERE s.challenge = :challenge AND (s.date_added BETWEEN :monday AND :sunday) ORDER BY s.score DESC
But an error ;(
[Semantical Error] line 0, col 18 near 'user, s FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression
Its worth to mention that user is a relation. When i try this on other files this works fine...
If you need get count distinct values, you can use countDistinct. But if you must get all distinct values, use groupBy