Jump to content

[ps_emailalerts] Problem with id_product


Recommended Posts

Good evening,

I have strange problem. Prestashop 1.7.4.4. I have mail alerts module. When I use the default theme - classic the module works good. But when I change to my theme there is a problem with:

$id_product = (int) Tools::getValue('id_product');

$id_product is null when I use my theme. The whole code I paste below:

public function processAdd()
    {
        $context = Context::getContext();

        if ($context->customer->isLogged()) {
            $id_customer = (int) $context->customer->id;
            $customer = new Customer($id_customer);
            $customer_email = (string) $customer->email;
        } else if (Validate::isEmail((string)Tools::getValue('customer_email'))) {
            $customer_email = (string) Tools::getValue('customer_email');
            $customer = $context->customer->getByEmail($customer_email);
            $id_customer = (isset($customer->id) && ($customer->id != null)) ? (int) $customer->id : null;
        } else {
            die(json_encode(
                array(
                    'error' => true,
                    'message' => $this->trans('Your e-mail address is invalid', array(), 'Modules.Mailalerts.Shop'),
                )
            ));
        }

        $id_product = (int) Tools::getValue('id_product');
        $id_product_attribute = (int) Tools::getValue('id_product_attribute');
        $id_shop = (int) $context->shop->id;
        $id_lang = (int) $context->language->id;
        $product = new Product($id_product, false, $id_lang, $id_shop, $context);

        $mail_alert = MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop, null, $customer_email);

        if ($mail_alert) {
            die(json_encode(
                array(
                    'error' => true,
                    'message' => $this->trans('You already have an alert for this product', array(), 'Modules.Mailalerts.Shop'),
                )
            ));
        } elseif (!Validate::isLoadedObject($product)) {
            die(json_encode(
                array(
                    'error' => true,
                    'message' => $this->trans('Your e-mail address is invalid', array(), 'Modules.Mailalerts.Shop'),
                )
            ));
        }

        $mail_alert = new MailAlert();

        $mail_alert->id_customer = (int) $id_customer;
        $mail_alert->customer_email = (string) $customer_email;
        $mail_alert->id_product = (int) $id_product;
        $mail_alert->id_product_attribute = (int) $id_product_attribute;
        $mail_alert->id_shop = (int) $id_shop;
        $mail_alert->id_lang = (int) $id_lang;

        if ($mail_alert->add() !== false) {
            die(json_encode(
                array(
                    'error' => false,
                    'message' => $this->trans('Request notification registered', array(), 'Modules.Mailalerts.Shop'),
                )
            ));
        }

        die(json_encode(
            array(
                'error' => true,
                'message' => $this->trans('Your e-mail address is invalid', array(), 'Modules.Mailalerts.Shop'),
            )
        ));
    }

Where could be a problem?

Kind regards

----

I was forget. I use displayProductAdditionalInfo hooh and this hook I display in:  templates\catalog\_partials\product-details.tpl in both themes. Of course in source code in html I see hidden input with id id_product.

Edited by mr.suchy
mailalerts (see edit history)

Share this post


Link to post
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...

Important Information

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