This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing cron file and fix version
- Loading branch information
Showing
5 changed files
with
171 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Cron.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
require_once("Api/Facebook/MessengerBot.php"); | ||
require_once("Api/Telegram/TelegramBot.php"); | ||
|
||
// handle all cron tasks. | ||
class Werules_Chatbot_Model_Cron | ||
{ | ||
public function crontask() | ||
{ | ||
//Mage::log("Cron processed", null, 'chatbot_cron.log'); | ||
|
||
$chatbotCollection = Mage::getModel('chatbot/chatdata')->getCollection(); | ||
foreach($chatbotCollection as $chatbot) | ||
{ | ||
//$hasQuote = $chatbot->getSessionId() && $chatbot->getQuoteId(); // has class quote and session ids | ||
$enabled = // if backend promotional messages are disabled or if the customer wants to receive promotional messages | ||
(Mage::getStoreConfig('chatbot_enable/general_config/disable_promotional_messages') != "1") || | ||
($chatbot->getEnablePromotionalMessages() == "1"); | ||
$customer = Mage::getModel('customer/customer')->load((int)$chatbot->getCustomerId()); | ||
if (($customer->getId()) && ($enabled)) // if is a valid customer id | ||
{ | ||
$fbChatId = $chatbot->getFacebookChatId(); | ||
$tgChatId = $chatbot->getTelegramChatId(); | ||
$customerId = $customer->getId(); | ||
$lifetime = (int)Mage::getStoreConfig('chatbot_enable/general_config/abandoned_cart_days'); | ||
//$lifetime = 7; | ||
$quotes = Mage::getModel( 'sales/quote' )->getCollection(); | ||
$quotes->addFieldToFilter('customer_id', $customerId) | ||
//->addFieldToFilter('is_active', 1) | ||
->addFieldToFilter('updated_at', array('to' => date("Y-m-d", time() - ($lifetime * 86400)))) | ||
; | ||
if (count($quotes) > 0) // TODO | ||
{ | ||
$enableFb = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_abandoned_cart'); | ||
$enableTg = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_abandoned_cart'); | ||
|
||
if ($enableFb == "1") // messenger | ||
{ | ||
$message = Mage::getStoreConfig('chatbot_enable/facebook_config/abandoned_cart_msg'); | ||
if ($message != "") | ||
{ | ||
$apikey = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_api_key'); | ||
$facebook = new MessengerBot($apikey); | ||
$facebook->postMessage($fbChatId, $message); | ||
} | ||
} | ||
if ($enableTg == "1") // telegram | ||
{ | ||
$message = Mage::getStoreConfig('chatbot_enable/telegram_config/abandoned_cart_msg'); | ||
if ($message != "") | ||
{ | ||
$apikey = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_api_key'); | ||
$facebook = new TelegramBot($apikey); | ||
$facebook->postMessage($tgChatId, $message); | ||
} | ||
} | ||
} | ||
// foreach($quotes as $quote) | ||
// { | ||
// $orders = Mage::getModel('sales/order')->getCollection(); | ||
// $orders->addFieldToFilter('quote_id', $quote->getId()); | ||
// $items = Mage::getModel('sales/quote_item') | ||
// ->getCollection() | ||
// ->setQuote($quote); | ||
// } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters