java2dev Posted October 16, 2016 Share Posted October 16, 2016 Hola, en los siguientes codigos tengo los hooks de prestashop que ayudan a enviar la actualizacion de un atributo stock de skus, solo que al guardar el cambio nada sucede, la actualizacion no se aplica del otro lado donde he creado sincronizando los productos por el medio del mismo modulo. linsync.php require_once('classes/class.linapi.php'); require_once('classes/class.linproduct.php'); public function hookBackOfficeHeader() { if (Tools::getValue('module_name') == $this->name) { $this->context->controller->addJS($this->_path.'views/js/back.js'); $this->context->controller->addCSS($this->_path.'views/css/back.css'); } } public function hookActionProductAttributeUpdate($params) { ob_start(); p($params); $content = ob_get_contents(); file_put_contents('update-pr.txt', $content, FILE_APPEND); ob_end_clean(); } public function hookActionUpdateQuantity($params) { if ($params['id_product_attribute']) { $idp = $params['id_product']; $ida = $params['id_product_attribute']; $api = new LinApi(); $pr = new LinProduct($idp, false, Context::getContext()->language->id); $sku = $pr->getSku($ida); $xml = simplexml_load_string($api->getProductBySku(array($sku))); $qty = (int) $xml->Body->Products->Product->Quantity; $res = (int) $xml->Body->Products->Product->ReservedStock; $avl = StockAvailable::getQuantityAvailableByProduct($idp, $ida); if (($qty - $res) < $avl) { $api->updateProduct($pr->getXmlQty($ida)); } } } class.linapi.php public function updateProduct($xml) { return $this->makeRequest('ProductUpdate', $xml); } class.linproduct.php public function getXmlQty($attribute = null) { $sku = (!$attribute || !$this->attributes) ? $this->reference : $this->attributes[$attribute]['reference']; $qty = StockAvailable::getQuantityAvailableByProduct($this->id, $attribute); $xml = '<?xml version="1.0" encoding="UTF-8" ?><Request><Product>'; $xml .= $this->getXmlProperty('SellerSku', $sku); $xml .= $this->getXmlProperty('Quantity', $qty); $xml .= '</Product></Request>'; return $xml; } Gracias por su ayuda. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now