Jump to content

[SOLVED] data recovery on prestashop 1.6.1.24


overbags
 Share

Recommended Posts

Posted (edited)

hello everyone I have a problem to expose you
I am trying to manipulate the StockAvailable.php file in class / stock / to register two custom fields of ps_product_attribute in ps_stock_available
"reference_uni" and "reference_uni_conf"

I cannot retrieve these two fields and have them recorded in the ps_stock_available table when updating the stock

I found the lines that record the quantities and I thought I would act on these lines (I attach image)

img1.png

 

if (!$depends_on_stock) {
            $id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);            
            if ($id_stock_available) {
                $stock_available = new StockAvailable($id_stock_available);
                $stock_available->quantity = (int)$quantity;
                $stock_available->reference_uni = "test1";
                $stock_available->reference_uni_conf = "test2";
                $stock_available->update();
            } else {
                $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
                $stock_available = new StockAvailable();
                $stock_available->out_of_stock = (int)$out_of_stock;
                $stock_available->id_product = (int)$id_product;
                $stock_available->id_product_attribute = (int)$id_product_attribute;
                $stock_available->quantity = (int)$quantity;
                $stock_available->reference_uni = "test3";
                $stock_available->reference_uni_conf = "test4";

 

image.thumb.png.0741532da91b23d4375657c804048a9c.png

Edited by overbags
forgotten script (see edit history)

Share this post


Link to post
Share on other sites

I solved it with an adapted script found online

 

--------------------------------------

// REFERENCE_UNI REFERENCE_UNI_CONF
            $query_ebay = 'SELECT reference_uni, reference_uni_conf FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute;    
            $ebaym = Db::getInstance()->executeS($query_ebay);
            $ebayKeys = array_keys($ebaym);
            $lastebayKey = array_pop($ebayKeys);
            $reference_uni = '';
            $reference_uni_conf = '';
            foreach ($ebaym as $eba_k => $ebay) {
                $reference_uni .= $ebay['reference_uni'];
                $reference_uni_conf .= $ebay['reference_uni_conf'];
                
                if ($eba_k != $lastebayKey) {
                    $reference_uni .= ' | ';
                    $reference_uni_conf .= ' | ';
                }
            }                
        
        if (!$depends_on_stock) {
            $id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);            
            if ($id_stock_available) {
                $stock_available = new StockAvailable($id_stock_available);
                $stock_available->quantity = (int)$quantity;
                $stock_available->reference_uni = $reference_uni;
                $stock_available->reference_uni_conf = $reference_uni_conf;
                $stock_available->update();
            } else {
                $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
                $stock_available = new StockAvailable();
                $stock_available->out_of_stock = (int)$out_of_stock;
                $stock_available->id_product = (int)$id_product;
                $stock_available->id_product_attribute = (int)$id_product_attribute;
                $stock_available->quantity = (int)$quantity;
                $stock_available->reference_uni = $reference_uni;
                $stock_available->reference_uni_conf = $reference_uni_conf;

 

  • Like 1

Share this post


Link to post
Share on other sites

  • overbags changed the title to [SOLVED] data recovery on prestashop 1.6.1.24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More