Jump to content

hookActionUpdateQuantity doesn't work


Recommended Posts

hi, I have the presta hook hookActionUpdateQuantity with some codelines at the first I put an echo to see if the function executes but it doesn't print the echo. any idea?

include(dirname(__FILE__).'/sql/install.php');

        return parent::install() &&
            Configuration::updateValue('LIN_LAST_SYNC', date('c')) &&
            $this->registerHook('actionProductAttributeUpdate') &&
            $this->registerHook('actionUpdateQuantity');
....
public function hookActionUpdateQuantity($params)
    {

       echo 'test';

//My code

     }
Link to comment
Share on other sites

when I added die; and click on save I received a message error as in the picture "parser error: SyntaxError: Unexpected token e in JSON in position 1"

but I have put it more at the end

public function hookActionUpdateQuantity($params)
    {
        echo 'test1';
        echo $params;
        if ($params['id_product_attribute']) {
            echo 'test2';
            $idp = $params['id_product'];
            echo "el id_product is : $idp";
            $ida = $params['id_product_attribute'];
            echo "el id_product_attribute is : $ida";
            $api = new LinioApi();
            $pr = new LinioProduct($idp, false, Context::getContext()->language->id);
echo 'test3';
            $sku = $pr->getSku($ida);
            $xml = simplexml_load_string($api->getProductBySku(array($sku)));
echo 'test4';
            $qty = (int) $xml->Body->Products->Product->Quantity;
            $res = (int) $xml->Body->Products->Product->ReservedStock;
            $avl = StockAvailable::getQuantityAvailableByProduct($idp, $ida);
            echo 'test5';
            if (($qty - $res) < $avl) {
                echo 'test6';
                $api->updateProduct($pr->getXmlQty($ida));
                echo 'test7';
                die;
                echo 'test8';
            }
            echo 'test9';
        }
        echo 'test10';
    }

but I have printed test1Arraytest10test1Arraytest2el id_product is : 2el id_product_attribute is : 7test3test4test5test6test7

post-1272022-0-70501500-1476802183_thumb.jpg

Edited by java2dev (see edit history)
Link to comment
Share on other sites

I've found where is the issue, in the hook function this line has his value always is NULL

$sku = $pr->getSku($ida);

the getSku function I have like this

public function getSku($attrib = 0)
    {
        return !$attrib ? $this->reference : $this->attributes[$attrib]['reference'];
    }

for the $ida and $idp they print the value without problem, the dump of $pr print a huge array with many product information and include the sku value I need to have in getSku.

Edited by java2dev (see edit history)
Link to comment
Share on other sites

Yep, it's working, the "die" has help me to check the output, know it's working I had a problem in if condition at the top. I have a doubt as mentienned before I don't understand why there is a first hookaction (without loop) only test1 test10 and second time the function enter by the if $param.

 

another question

 

why I can't print id_product in this function (but it works for quantity hook)

public function hookActionProductAttributeUpdate($params)
    {
		//a verificar.
	if ($params['id_product_attribute']) {
			$idp = $params['id_product'];
			echo $idp;
			$ida = $params['id_product_attribute'];
			echo $ida;
			$api = new LinioApi();
			$pr = new LinioProduct($idp, false, Context::getContext()->language->id);
			$sku = $pr->getSku($ida);
			$xml = simplexml_load_string($api->getProductBySku(array($sku)));
			$api->updateProduct($pr->getXmlDesc($ida));
			
        }
		echo "test9";
		die;
		
    }

I want to update description for combination, upc, price, etc

Edited by java2dev (see edit history)
Link to comment
Share on other sites

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
×
×
  • Create New...