I've added product by sql query but even when I have ps_product_shop and ps_product_lang set correctly the product in back office is shown with null name and no description what so ever and additionaly there is no category connection too.
What am I missing, can I add product by SQL? If so how do I do it.
I was looking everywhere but there was no query to help me, if someone could help me out I would appreciate that.
Manually adding products directly to database through sql query is not advisable. If you did so, problem may be your id_lang field in ps_product_lang table. For English id_lang is 1. Please check with your query.
Here I did for English lang. You can add through code like below otherwise you can use admin panel for product creation.
$product = new Product();
$product->name[1] = "This is test product";
$product->description[1] = "Description";
$product->description_short[1] = "Descriptio short";
$product->active = 1;
$product->condition = "new";
$product->link_rewrite = Tools::link_rewrite('This is test product');;
$product->id_tax_rules_group = 1;
$product->price = 100;
$product->wholesale_price = 90;
$product->id_manufacturer = 1;
$product->add();
Related
I need to mass change product categories. I updated two tables in database: ps_category_product (changed old id_category) and ps_products (changed old id_category_default) but in BO product table and webshop I still see old category (home).
When I edit product, select tab associations I see that product is associated with my new caterogy. Only when I save the product by click save button I see that product in properly categories.
I compared two rows in database (product with changed category by mysql query and product changed in BO) and these two look identical.
What am I doing wrong? I was trying clean cache (delete cache/cachefs and smarty/compile), disable all cache options but with no result.
To change the category, the following queries must be executed:
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'category_product SET id_category = NEW_ID_CATEGORY WHERE id_category = OLD_ID_CATEGORY');
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product_shop SET id_category_default = NEW_ID_CATEGORY WHERE id_category_default = OLD_ID_CATEGORY AND id_shop = ID_SHOP');
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET id_category_default = NEW_ID_CATEGORY WHERE id_category_default = OLD_ID_CATEGORY');
Regards
I'm using HP Vertica 7 as data warehouse DB.
I need to update two tables at the same time.
foreach (row r in table_1)
{
foreach (row r2 in table_2)
{
if(r.key1 == r2.key1 && r.key2 ==r2.key2 && r.soldQuantity > r2.Quantity)
{
updateRowInT1(); //r.Partner = r2.Partner;
updateRowInT2(); //r2.Quantity = r2.Quantity - r.soldQuantity;
break;
}
}
}
This part of code best describes what I need to do.
Is there any way to do this in SQL (with user-defined functions).
Because of changes in second table I can't use update and join. Or I can?
Also, this is part of ETL process done by Pentaho Kettle. Is perhaps way to do this inside this tool.?
Thanks
Edit:
I have changed code above.
What I need to achieve?
Regular Sales by Partner.
What's wrong right now?
When some SKU is sold in retail shop, I can see SKU LAST Partner. But, company I work for is buying same SKU from more Partners.
Slowly Changing Dimension is not applicable because when we switch partner on SKU, there is still some quantity of that SKU on shelf.
Assumption:
FIFO - first In first Out.
So, for initial matching, I need to compare (in date order) both sales and buying and to decrement bought quantity.
You probably should be thinking in a more set oriented way.
Assuming I understand what you are trying to do properly, I would do this in two update statements:
-- Update table_1's Partner based on a row in table_2.
UPDATE table_1 r
SET Partner = r2.Partner
FROM table_2 r2
WHERE r2.key1 = r.key1
AND r2.key2 = r.key2;
-- Reduce the Quantity in table_2 based on table_1's soldQuantity
UPDATE table_2 r2
SET Quantity = r2.Quantity - r.soldQuantity
FROM table_1 r
WHERE r.key1 = r2.key1
AND r.key2 = r2.key2
AND r2.Quantity >= r.soldQuantity;
-- Both of these should be done in a transaction so it is all or none. Commit the work.
COMMIT;
You can see the SQLFiddle here.
I'm working with PeopleSoft Campus Solutions, and we need to update about 22,000 rows of data. This is data between the tables of ACAD_PLAN_VW and ACAD_PROG. Students are listed on both, so their IDs match between the two.
Basically what we are trying to do is say that when the ID, academic career, student career number, effective sequence, and effective date match, AND where the academic plan (their degree, as stored on the ACAD_PLAN_VW) is a specific value, update the ACAD_PROG on the ACAD_PROG table to X value.
I tried to do some very interesting combinations of FROM statements, constantly getting errors. After some researching, I found out that SQLTools doesn't really like FROM statements within UPDATE statements, so I rewrote it to just make the connections manually. I'm assuming I'm doing this right, unless I need to reword it.
The statement I have is:
UPDATE PS_ACAD_PROG SET PS_ACAD_PROG.ACAD_PROG = 'UGDS'
WHERE PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
AND PS_ACAD_PLAN_VW.ACAD_PLAN = 'DSTDS'
Theoretically, I would assume that this would update any student who has those connections. However, the error that I'm currently getting is as follows:
ORA-00904: "PS_ACAD_PLAN_VW"."ACAD_PLAN": invalid identifier
I have, as of yet, been unable to figure out the issue. I do have the correct access to view and update those fields, and the field does indeed exist.
Oracle doesn't know it should use the PS_ACAD_PLAN_VW table. Somehow you should reference it.
For example can you try this way?
UPDATE (
select
PS_ACAD_PROG.ACAD_PROG,
PS_ACAD_PLAN_VW.ACAD_PLAN
from
PS_ACAD_PROG,
PS_ACAD_PLAN_VW
where
PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
)
SET
ACAD_PROG = 'UGDS'
WHERE
ACAD_PLAN = 'DSTDS'
Try to use the table which is not getting identified,by keeping in where clause so that you can use the select statement.That will help identifying the tables.
The following implementation should work:
UPDATE PS_ACAD_PROG
SET ACAD_PROG = 'UGDS'
WHERE ROWID IN(SELECT PROG.ROWID
FROM PS_ACAD_PROG PROG
, PS_ACAD_PLAN_VW PLAN
WHERE PLAN.EMPLID = PROG.EMPLID
AND PLAN.ACAD_CAREER = PROG.ACAD_CAREER
AND PLAN.STDNT_CAR_NBR = PROG.STDNT_CAR_NBR
AND PLAN.EFFSEQ = PROG.EFFSEQ
AND PLAN.EFFDT = PROG.EFFDT
AND PLAN.ACAD_PLAN = 'DSTDS');
I've built a MySQL query that returns 452 entries when I try it via phpMyAdmin, here's the query :
SELECT csp.id FROM child_subscription_prices csp
JOIN child_moments cm ON csp.child_moment_id = cm.id
JOIN moments m ON cm.moment_id = m.id
JOIN poles p ON m.pole_id = p.id
JOIN persons pr ON pr.id = csp.payer_id
WHERE cm.day BETWEEN '2013-1-15' AND '2013-1-17' AND p.type_id IN (1,2,3) AND csp.center_id = 1
ORDER BY pr.lastname ASC
But when I call it using Ebean (Play!Framework 2.1.1), like this :
SimpleDateFormat format = new SimpleDateFormat("y-M-d");
StringBuilder querySql = new StringBuilder();
querySql.append("SELECT csp.id FROM child_subscription_prices csp ");
querySql.append("JOIN child_moments cm ON csp.child_moment_id = cm.id ");
querySql.append("JOIN moments m ON cm.moment_id = m.id ");
querySql.append("JOIN poles p ON m.pole_id = p.id ");
querySql.append("JOIN persons pr ON pr.id = csp.payer_id ");
querySql.append("WHERE cm.day BETWEEN :start AND :end AND p.type_id IN (:poles) AND csp.center_id = :center ");
querySql.append("ORDER BY pr.lastname ASC;");
SqlQuery query = Ebean.createSqlQuery(querySql.toString());
query.setParameter("start", format.format(start));
query.setParameter("end", format.format(end));
query.setParameter("poles", StringUtils.join(poleIds.toArray(), ","));
query.setParameter("center", Session.getCenter().getId());
List<SqlRow> rows = query.findList();
rows.size(); // Return 409 !!
Of course, I tested the parameter in Java and compared them, they are identical ! (I even updated my first query to match the dates (2013-01-15 => 2013-1-15, to be like the one made in Java!
I don't have any clue why I have 50 entries less using Java, is there a particular Ebean configuration that doesn't follow some related database for any reason, or something like this that would explain the differences ?
Update
I also tried to count the number of results from the SQL query made in Java:
querySql.append("SELECT COUNT(csp.id) as total FROM child_subscription_prices csp ");
// ...
query.findUnique().getLong("total"); // Also 409 !
So it clearly seems to be a difference between the configuration in PhpMyAdmin and EBean, but I can't see which one!
For information, the problem was coming from this line :
query.setParameter("poles", StringUtils.join(poleIds.toArray(), ","));
Instead, I just had to replace it to this :
// poleids is a List<Long>
query.setParameter("poles", poleIds);
And everything worked fine :)
I'm having some difficulty with an Update statement.
UPDATE DownPeriod
SET
DownPeriod.EquipmentID = ? ?? ?? ? ?? ?? ? ?,
DownPeriod.DownDate = Forms!Edit!EditDownDateBox,
DownPeriod.DownTime = Forms!Edit!EditDownTimeBox,
DownPeriod.[UpDate] = Forms!Edit!EditUpDateBox,
DownPeriod.UpTime = Forms!Edit!EditUpTimeBox,
DownPeriod.isScheduled = Forms!Edit!EditSchedCheck,
DownPeriod.isUnscheduled = Forms!Edit!EditUnschedCheck,
DownPeriod.Comments = Forms!Edit!EditCommentsDropDown
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID;
Where the question marks are is where im having difficulty, and am not sure what to put.
Everything else about the update will work if I remove that statement so I know im on the right track. The difference with the EquipmentID is that I'm getting this value based on an input for another table entry. To elaborate the user chooses an Equipment Title, which is another field in my Equip Table that will relate to a unique ID.
So far I have tried DLOOKUP("[EquipmentID]", "Equipment", "[Title] = Forms!Edit!EditEquipmentDropDown")
Select statment and
using inner join
I'm at a loss and need help plz!
Thank you!
You say that the user is selecting the title from a dropdown. The dropdown should have a row source on these lines:
SELECT ID, Title FROM Equipment
With ID as a hidden column. Your update should then be:
DownPeriod.EquipmentID = Forms!Edit!EditTitleDropDown
As an aside, I suspect you are doing a lot more work that you need to do to make an MS Access form work.
If it is a new unique id you need an INSERT. If it already exists you should include it as part of your WHERE clause.
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID
AND DownPeriod.EquipmentID = Forms!Edit!EditEquipmentDropDown;