Jump to content

Run an SQL Query


ayz1

Recommended Posts

There are two hooks available, one before any form POSTed data is processed by CubeCart, and another after it all has been processed and databased.

So, I think we need to determine at what point would be easiest: massage the form's POSTed data and let CubeCart database that changed data, or actually update the database table.

Link to comment
Share on other sites

We will create a Code Snippet.

Backup the affected tables.

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

Enabled: Checked
Unique ID: grp_update@ayz1    -- 32 chars max
Execution Order: 99
Description: Makes a few updates to CubeCart_pricing_group after databasing Add/Edit product
Trigger: admin.product.save.post_process
Version: 1.0
Author: AYZ1
PHP Code:
<?php
/**
 * The following will update the Group Prices according to the following rules:
 * Determine the factors that will influence the outcome
 * Determine the formulas to derive the outcome
 * Create the $ayz1_record that will update the table with the new data
 * Create the $ayz1_where filter to positively identify which records to update
 * $GLOBALS['db']->update('CubeCart_pricing_group',$ayz1_record,$ayz1_where);
 */
// Put your code here
?>

Save.

Test.

Link to comment
Share on other sites

Thanks for that. I have set it up but getting a blank screen. I think the queries are being run BUT it appears that each time a product is updated if Groups are involved the product group table is updated and the group product is given a new ID which I find a bit strange. Also this appears to be happening after the queries in the hook have been run thereby overriding the changes I made with the queries. I've checked this on two back up stores and both do the same.

 

Link to comment
Share on other sites

Every time a product is edited the price_id in the pricing_group table is regenerated. So if you edit a product with original price_id of 1329 and you have say 4378 products when the edit to 1329 is saved the price_id will change to 4379. I am wondering if this is correct or is it a bug?

Link to comment
Share on other sites

I posted a question in the Github asking the developers to research why the code does this: Delete all Group Prices for this product, then work through the POSTed array of group prices (gets POSTed every time) inserting the values. There is code to update any changes but because there was a unilateral deletion first, there is nothing left to update. So, all the inserted rows gets new primary key numbers - not that getting new numbers affects anything.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...