Jump to content

Recommended Posts

private function cancelledCart($count = false)
	{
		$email_logs = $this->getLogsEmail(1);
$sql = 'SELECT c.id_cart, c.id_lang, cu.id_customer, c.id_shop, cu.firstname, cu.lastname, cu.email, ca.id_product, pl.link_rewrite,ca.id_product_attribute,cv.reference,pi.id_image
FROM cart as c
LEFT JOIN orders as o ON (o.id_cart = c.id_cart)
LEFT JOIN cart_product as ca ON (ca.id_cart = c.id_cart)
LEFT JOIN product_attribute_image
as pi ON (ca.id_product_attribute = pi.id_product_attribute)

LEFT JOIN product_attribute
as cv ON (cv.id_product_attribute = pi.id_product_attribute)

LEFT JOIN product_lang as pl ON (pl.id_product= ca.id_product)
RIGHT JOIN customer as cu ON (cu.id_customer = c.id_customer)
WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= c.date_add AND o.id_order IS NULL';

		$sql .= Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');

		if (!empty($email_logs))
			$sql .= ' AND c.id_cart NOT IN ('.join(',', $email_logs).')';

		$sql .= ' GROUP BY cu.id_customer';

		$emails = Db::getInstance()->executeS($sql);

		if ($count || !count($emails))
			return count($emails);


		$conf = Configuration::getMultiple(array('PS_FOLLOW_UP_AMOUNT_1', 'PS_FOLLOW_UP_DAYS_1'));
		foreach ($emails as $email)
		{

        

			$voucher = $this->createDiscount(1, (float)$conf['PS_FOLLOW_UP_AMOUNT_1'], (int)$email['id_customer'], strftime('%Y-%m-%d', strtotime('+'.(int)$conf['PS_FOLLOW_UP_DAYS_1'].' day')), $this->l('Discount for your cancelled cart'));
			if ($voucher !== false)
			{
				$template_vars = array(
					'{email}' => $email['email'],
					'{lastname}' => $email['lastname'],
					'{firstname}' => $email['firstname'],
					'{productreference}' =>$email['reference'],
					'{imageattribute}' =>$email['id_image'],
					'{idproduct}' => $email['id_product'],
					'{link}' => $email['link_rewrite'],
					'{amount}' => $conf['PS_FOLLOW_UP_AMOUNT_1'],
					'{days}' => $conf['PS_FOLLOW_UP_DAYS_1'],
					'{voucher_num}' => $voucher->code
				);
				Mail::Send((int)$email['id_lang'], 'followup_1', Mail::l('Your abandonded cart', (int)$email['id_lang']), $template_vars, $email['email'], $email['firstname'].' '.$email['lastname'], null, null, null, null, dirname(__FILE__).'/mails/');
				$this->logEmail(1, (int)$voucher->id, (int)$email['id_customer'], (int)$email['id_cart']);
			}
		}
	} 

Hola comunidad!

 

Tengo una pequeña duda, que no acabo de sacar adelante. Estoy adaptando el código del módulo followup para mandar a mis clientes recordatorios de sus carritos abandonados. Total, he modificado la consulta a la bbdd para que en el mail del cliente envíe los productos que añadió en su carrito de la compra que dejó abandonado. todo bien, hasta que ocurre lo siguiente, si son varios articulos los que metió en su carro, solo se muestra uno de ellos...el código es el que os pongo arriba, y el problema lo tengo con 

 

                    '{productreference}' =>$email['reference'],

                    '{imageattribute}' =>$email['id_image'],

                    '{idproduct}' => $email['id_product'],

                    '{link}' => $email['link_rewrite'],

 

ya que estos valores son múltiples, pero solamente me muestra uno, se que el fallo está en mi código, y he probado varias cosas, pero ya no se si esque estoy un poco espesa, no logro que me muestre el array de datos...

Link to comment
Share on other sites

De esa manera no vas a poder incluir un array en el cuerpo de un email. Lo mejor es que de esa consulta extraigas el id_cart y de ahi saques algo asi

$cart = new Cart(id_cart);
$products = $cart->getProducts();
$items_table = '';

foreach ($products as $key => $product) {
$unit_price = Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt'];
			$customization_text = '';
			if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
			{
				foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']][$order->id_address_delivery] as $customization)
				{
					if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
						foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text)
							$customization_text .= $text['name'].': '.$text['value'].'<br />';
					if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
						$customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]).' '.$this->l('image(s)').'<br />';
					$customization_text .= '---<br />';
				}
				if (method_exists('Tools', 'rtrimString'))
					$customization_text = Tools::rtrimString($customization_text, '---<br />');
				else
					$customization_text = preg_replace('/---<br \/>$/', '', $customization_text);
			}
			$url = $context->link->getProductLink($product['product_id']);
$items_table .=
				'<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
					<td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
                                         <td style="padding:0.6em 0.4em;">
						<strong><a href="'.$url.'">'.$product['product_name'].'</a>'
							.(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
							.(!empty($customization_text) ? '<br />'.$customization_text : '')
						.'</strong>
					</td>
                                        <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td>
					<td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
					<td style="padding:0.6em 0.4em; text-align:right;">'
						.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false)
					.'</td>
				</tr>';
	}

Y en el array de las variables del mail, añades

'{items}' => $items_table,
Link to comment
Share on other sites

  • 4 weeks later...

SI, tienes razón, estaba mal planteado ventura, estaba mal, no lograba verlo pero es verdad que es mejor sacar primero el id_cart y a partir de ello, sacar los demás datos.

 

Muchas gracias por tu tiempo y respuesta. Gracias Ventura

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...