Skip to content

Commit a878e0c

Browse files
committed
update
1 parent e591dfb commit a878e0c

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Block/Chat/Chat.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Chat extends \Magento\Framework\View\Element\Template
3535
protected $_customerSession;
3636
/**
3737
*
38-
* @var \Magento\Customer\Model\Url
38+
* @var \Lof\ChatSystem\Model\ChatFactory
3939
*/
4040
protected $chat;
4141
/**
@@ -48,26 +48,32 @@ class Chat extends \Magento\Framework\View\Element\Template
4848
* @var \Magento\Customer\Model\Url
4949
*/
5050
protected $_customerUrl;
51-
/**
52-
* @param \Magento\Framework\View\Element\Template\Context $context
53-
* @param \Magento\Customer\Model\Session $customerSession
54-
* @param array $data
55-
*/
51+
52+
53+
5654
public function __construct(
5755
\Magento\Framework\View\Element\Template\Context $context,
5856
\Magento\Customer\Model\Session $customerSession,
5957
\Lof\ChatSystem\Helper\Url $customerUrl,
6058
\Lof\ChatSystem\Helper\Data $helper,
61-
\Lof\ChatSystem\Model\Chat $chat,
59+
\Lof\ChatSystem\Model\ChatFactory $chatFactory,
6260
array $data = []
6361
) {
6462
$this->helper = $helper;
65-
$this->chat = $chat;
63+
$this->chat = $chatFactory;
6664
$this->_customerSession = $customerSession;
6765
$this->_customerUrl = $customerUrl;
6866
parent::__construct($context, $data);
6967
}
7068

69+
public function _toHtml()
70+
{
71+
if($this->helper->getConfig("general_settings/enable")){
72+
return parent::_toHtml();
73+
}
74+
return;
75+
}
76+
7177
public function isLogin() {
7278
if ($this->_customerSession->isLoggedIn()) {
7379
return true;
@@ -77,24 +83,25 @@ public function isLogin() {
7783
public function getChatId() {
7884

7985
if($this->isLogin()) {
80-
$chat = $this->chat->getCollection()->addFieldToFilter('customer_email',$this->getCustomer()->getData('email'));
81-
if(count($chat) > 0) {
86+
$chat = $this->chat->create()->getCollection()->addFieldToFilter('customer_email',$this->getCustomer()->getData('email'));
87+
if($chat->getSize() > 0) {
8288
$chat_id = $chat->getFirstItem()->getData('chat_id');
8389
}else {
84-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance ();
85-
$chatModel = $objectManager->create ( 'Lof\ChatSystem\Model\Chat' );
90+
$chatModel = $this->chat->create();
8691

87-
$chatModel->setCustomerId($this->getCustomerSession()->getCustomerId())->setCustomerName($this->getCustomer()->getData('firstname').' '.$this->getCustomer()->getData('lastname'))->setCustomerEmail($this->getCustomer()->getData('email'));
92+
$chatModel
93+
->setCustomerId($this->getCustomerSession()->getCustomerId())
94+
->setCustomerName($this->getCustomer()->getData('firstname').' '.$this->getCustomer()->getData('lastname'))
95+
->setCustomerEmail($this->getCustomer()->getData('email'));
8896
$chatModel->save();
8997
$chat_id = $chatModel->getData('chat_id');
9098
}
9199
} else {
92-
$chat = $this->chat->getCollection()->addFieldToFilter('ip',$this->helper->getIp());
93-
if(count($chat) > 0) {
100+
$chat = $this->chat->create()->getCollection()->addFieldToFilter('ip',$this->helper->getIp());
101+
if($chat->getSize() > 0) {
94102
$chat_id = $chat->getFirstItem()->getData('chat_id');
95103
} else {
96-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance ();
97-
$chatModel = $objectManager->create ( 'Lof\ChatSystem\Model\Chat' );
104+
$chatModel = $this->chat->create();
98105
$chatModel->setIp($this->helper->getIp());
99106
$chatModel->save();
100107
$chat_id = $chatModel->getData('chat_id');

0 commit comments

Comments
 (0)