Jump to content

Edit History

dostoyevski

dostoyevski

hi how are things. I have a ps module (designed by me) to update the stock of the physical store every time an online sale is made. So what I do is search for the product reference in the database of the physical store to update the stock. It works fine for me for simple products, but for those with combinations it doesn't get me the reference. This is the hook code that is launched every time there is a sale in ps:
 

    public function hookActionPaymentConfirmation($params)
    {


        $db = \Db::getInstance();
        //$products = $params['cart']->getProducts(true);//en los nuevos ps ya no va y hay que hacerlo con las dos ordenes siguientes
        $order = new Order($params['id_order']);
    $products = $order->getCartProducts();
        foreach ($products as $product)
        {
            $id_product = $product['id_product'];
            $cantidad = $product['cart_quantity'];
            $referencia = $product['reference'];
            $referencia_a_mostrar = $product['reference_to_display'];
            $unidades = $db->getValue('SELECT unidades FROM productos WHERE codigo_de_barras = "'.$referencia.'"');
            $unidadesRestantes=$unidades-$cantidad;
            $db->Execute('UPDATE productos SET unidades="'.$unidadesRestantes.'" WHERE codigo_de_barras = "'.$referencia.'"');
            mail("[email protected]", "yay", $id_product." ".$referencia." ".$cantidad." ".$referencia_a_mostrar);
    }
        
    
    }

As you can see, I send an email to my account with the ID, the reference and the amount. Well, in the reference it does not print anything. How can I get the reference of a product with combinations? My version of prestashop is 1.7.8.6.

Best regards!

dostoyevski

dostoyevski

hi how are things. I have a ps module (designed by me) to update the stock of the physical store every time an online sale is made. So what I do is search for the product reference in the database of the physical store to update the stock. It works fine for me for simple products, but for those with combinations it doesn't get me the reference. This is the hook code that is launched every time there is a sale in ps:
 

    public function hookActionPaymentConfirmation($params)
    {


        $db = \Db::getInstance();
        //$products = $params['cart']->getProducts(true);//en los nuevos ps ya no va y hay que hacerlo con las dos ordenes siguientes
        $order = new Order($params['id_order']);
    $products = $order->getCartProducts();
        foreach ($products as $product)
        {
            $id_product = $product['id_product'];
            $cantidad = $product['cart_quantity'];
            $referencia = $product['reference'];
            $referencia_a_mostrar = $product['reference_to_display'];
            $unidades = $db->getValue('SELECT unidades FROM productos WHERE codigo_de_barras = "'.$referencia.'"');
            $unidadesRestantes=$unidades-$cantidad;
            $db->Execute('UPDATE productos SET unidades="'.$unidadesRestantes.'" WHERE codigo_de_barras = "'.$referencia.'"');
            mail("[email protected]", "yay", $id_product." ".$referencia." ".$cantidad." ".$referencia_a_mostrar);
    }
        
    
    }

As you can see, I send an email to my account with the ID, the reference and the amount. Well, in the reference it does not print anything. How can I get the reference of a product with combinations? My version of prestashop is 1.7.8.6.

Best regards!

×
×
  • Create New...