Commit 1c3aa02a by lmf

增加WhatsApp 插件

parent 2758bfdc
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
"phpseclib/phpseclib": "2.0.*", "phpseclib/phpseclib": "2.0.*",
"ramsey/uuid": "~4.1.0", "ramsey/uuid": "~4.1.0",
"sparsh/magento-2-advanced-sorting-extension": "^1.3", "sparsh/magento-2-advanced-sorting-extension": "^1.3",
"sparsh/whatsapp-chat-extension": "1.3.0",
"swissup/breeze-blank": "^1.2", "swissup/breeze-blank": "^1.2",
"symfony/console": "~4.4.0", "symfony/console": "~4.4.0",
"symfony/event-dispatcher": "~4.4.0", "symfony/event-dispatcher": "~4.4.0",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c25f21a48780f0491f5334e83669ae20", "content-hash": "7f02c533dc0cbf8b1519153f59f34ac0",
"packages": [ "packages": [
{ {
"name": "airwallex/payments-plugin-magento", "name": "airwallex/payments-plugin-magento",
...@@ -6580,6 +6580,31 @@ ...@@ -6580,6 +6580,31 @@
"description": "Sparsh Advanced Sorting for Magento 2" "description": "Sparsh Advanced Sorting for Magento 2"
}, },
{ {
"name": "sparsh/whatsapp-chat-extension",
"version": "1.3.0",
"dist": {
"type": "zip",
"url": "https://repo.magento.com/archives/sparsh/whatsapp-chat-extension/sparsh-whatsapp-chat-extension-1.3.0.0.zip",
"shasum": "e723445356db04f1ea13deee10845d570437c2f1"
},
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"type": "magento2-module",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\WhatsAppChat\\": ""
}
},
"license": [
"OSL-3.0"
],
"description": "Sparsh WhatsApp Chat Extension for Magento 2"
},
{
"name": "spomky-labs/aes-key-wrap", "name": "spomky-labs/aes-key-wrap",
"version": "v6.0.0", "version": "v6.0.0",
"source": { "source": {
......
...@@ -142,5 +142,6 @@ return array( ...@@ -142,5 +142,6 @@ return array(
'aa75ea0761a2f40c1f3b32ad314f86c4' => $vendorDir . '/phpseclib/mcrypt_compat/lib/mcrypt.php', 'aa75ea0761a2f40c1f3b32ad314f86c4' => $vendorDir . '/phpseclib/mcrypt_compat/lib/mcrypt.php',
'9b38cf48e83f5d8f60375221cd213eee' => $vendorDir . '/phpstan/phpstan/bootstrap.php', '9b38cf48e83f5d8f60375221cd213eee' => $vendorDir . '/phpstan/phpstan/bootstrap.php',
'550719157da16285530f4f2ca5eee610' => $vendorDir . '/sparsh/magento-2-advanced-sorting-extension/registration.php', '550719157da16285530f4f2ca5eee610' => $vendorDir . '/sparsh/magento-2-advanced-sorting-extension/registration.php',
'5309a32e543f477e86cff80a798c1cc0' => $vendorDir . '/sparsh/whatsapp-chat-extension/registration.php',
'27a5783f6a5e8d8d1a4f54dff608a187' => $baseDir . '/app/etc/NonComposerComponentRegistration.php', '27a5783f6a5e8d8d1a4f54dff608a187' => $baseDir . '/app/etc/NonComposerComponentRegistration.php',
); );
...@@ -44,6 +44,7 @@ return array( ...@@ -44,6 +44,7 @@ return array(
'Swissup\\Rtl\\' => array($vendorDir . '/swissup/module-rtl'), 'Swissup\\Rtl\\' => array($vendorDir . '/swissup/module-rtl'),
'Swissup\\Breeze\\' => array($vendorDir . '/swissup/module-breeze'), 'Swissup\\Breeze\\' => array($vendorDir . '/swissup/module-breeze'),
'Swissup\\BreezeIntegrations\\' => array($vendorDir . '/swissup/module-breeze-integrations'), 'Swissup\\BreezeIntegrations\\' => array($vendorDir . '/swissup/module-breeze-integrations'),
'Sparsh\\WhatsAppChat\\' => array($vendorDir . '/sparsh/whatsapp-chat-extension'),
'Sparsh\\AdvancedSorting\\' => array($vendorDir . '/sparsh/magento-2-advanced-sorting-extension'), 'Sparsh\\AdvancedSorting\\' => array($vendorDir . '/sparsh/magento-2-advanced-sorting-extension'),
'Seld\\PharUtils\\' => array($vendorDir . '/seld/phar-utils/src'), 'Seld\\PharUtils\\' => array($vendorDir . '/seld/phar-utils/src'),
'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'), 'Seld\\JsonLint\\' => array($vendorDir . '/seld/jsonlint/src/Seld/JsonLint'),
......
...@@ -143,6 +143,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -143,6 +143,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
'aa75ea0761a2f40c1f3b32ad314f86c4' => __DIR__ . '/..' . '/phpseclib/mcrypt_compat/lib/mcrypt.php', 'aa75ea0761a2f40c1f3b32ad314f86c4' => __DIR__ . '/..' . '/phpseclib/mcrypt_compat/lib/mcrypt.php',
'9b38cf48e83f5d8f60375221cd213eee' => __DIR__ . '/..' . '/phpstan/phpstan/bootstrap.php', '9b38cf48e83f5d8f60375221cd213eee' => __DIR__ . '/..' . '/phpstan/phpstan/bootstrap.php',
'550719157da16285530f4f2ca5eee610' => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension/registration.php', '550719157da16285530f4f2ca5eee610' => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension/registration.php',
'5309a32e543f477e86cff80a798c1cc0' => __DIR__ . '/..' . '/sparsh/whatsapp-chat-extension/registration.php',
'27a5783f6a5e8d8d1a4f54dff608a187' => __DIR__ . '/../..' . '/app/etc/NonComposerComponentRegistration.php', '27a5783f6a5e8d8d1a4f54dff608a187' => __DIR__ . '/../..' . '/app/etc/NonComposerComponentRegistration.php',
); );
...@@ -199,6 +200,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -199,6 +200,7 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
'Swissup\\Rtl\\' => 12, 'Swissup\\Rtl\\' => 12,
'Swissup\\Breeze\\' => 15, 'Swissup\\Breeze\\' => 15,
'Swissup\\BreezeIntegrations\\' => 27, 'Swissup\\BreezeIntegrations\\' => 27,
'Sparsh\\WhatsAppChat\\' => 20,
'Sparsh\\AdvancedSorting\\' => 23, 'Sparsh\\AdvancedSorting\\' => 23,
'Seld\\PharUtils\\' => 15, 'Seld\\PharUtils\\' => 15,
'Seld\\JsonLint\\' => 14, 'Seld\\JsonLint\\' => 14,
...@@ -529,6 +531,10 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf ...@@ -529,6 +531,10 @@ class ComposerStaticInitb71ce7c407b65980cf51508f463c8dcf
array ( array (
0 => __DIR__ . '/..' . '/swissup/module-breeze-integrations', 0 => __DIR__ . '/..' . '/swissup/module-breeze-integrations',
), ),
'Sparsh\\WhatsAppChat\\' =>
array (
0 => __DIR__ . '/..' . '/sparsh/whatsapp-chat-extension',
),
'Sparsh\\AdvancedSorting\\' => 'Sparsh\\AdvancedSorting\\' =>
array ( array (
0 => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension', 0 => __DIR__ . '/..' . '/sparsh/magento-2-advanced-sorting-extension',
......
...@@ -11168,6 +11168,34 @@ ...@@ -11168,6 +11168,34 @@
"install-path": "../sparsh/magento-2-advanced-sorting-extension" "install-path": "../sparsh/magento-2-advanced-sorting-extension"
}, },
{ {
"name": "sparsh/whatsapp-chat-extension",
"version": "1.3.0",
"version_normalized": "1.3.0.0",
"dist": {
"type": "zip",
"url": "https://repo.magento.com/archives/sparsh/whatsapp-chat-extension/sparsh-whatsapp-chat-extension-1.3.0.0.zip",
"shasum": "e723445356db04f1ea13deee10845d570437c2f1"
},
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"type": "magento2-module",
"installation-source": "dist",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\WhatsAppChat\\": ""
}
},
"license": [
"OSL-3.0"
],
"description": "Sparsh WhatsApp Chat Extension for Magento 2",
"install-path": "../sparsh/whatsapp-chat-extension"
},
{
"name": "spomky-labs/aes-key-wrap", "name": "spomky-labs/aes-key-wrap",
"version": "v6.0.0", "version": "v6.0.0",
"version_normalized": "6.0.0.0", "version_normalized": "6.0.0.0",
......
...@@ -2904,6 +2904,15 @@ ...@@ -2904,6 +2904,15 @@
'reference' => NULL, 'reference' => NULL,
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'sparsh/whatsapp-chat-extension' => array(
'pretty_version' => '1.3.0',
'version' => '1.3.0.0',
'type' => 'magento2-module',
'install_path' => __DIR__ . '/../sparsh/whatsapp-chat-extension',
'aliases' => array(),
'reference' => NULL,
'dev_requirement' => false,
),
'spomky-labs/aes-key-wrap' => array( 'spomky-labs/aes-key-wrap' => array(
'pretty_version' => 'v6.0.0', 'pretty_version' => 'v6.0.0',
'version' => '6.0.0.0', 'version' => '6.0.0.0',
......
<?php
namespace Sparsh\WhatsAppChat\Helper;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\App\RequestInterface;
/**
* Class Data
* @package Sparsh\WhatsAppChat\Helper
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* Data constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
Repository $assetRepo,
RequestInterface $request
) {
$this->_storeManager = $storeManager;
$this->assetRepo = $assetRepo;
$this->request = $request;
parent::__construct($context);
}
/**
* Return module status
*
* @return string
*/
public function getWAStatus()
{
return $this->scopeConfig->getValue(
'wa_chat/general/enable',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
/**
* Return phone number
*
* @return string
*/
public function getWAPhone()
{
return $this->scopeConfig->getValue(
'wa_chat/general/phone_number',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
/**
* Return message
*
* @return string
*/
public function getWAMessage()
{
return $this->scopeConfig->getValue(
'wa_chat/general/message',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
/**
* Return icon position
*
* @return string
*/
public function getWAPosition()
{
return $this->scopeConfig->getValue(
'wa_chat/general/position',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
/**
* Return relative position
*
* @return string
*/
public function getWARelPx()
{
return $this->scopeConfig->getValue(
'wa_chat/general/rel_px',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
/**
* Return icon image url
*
* @return string
*/
public function getWAIconUrl()
{
$whatsAppIcon = $this->scopeConfig
->getValue('wa_chat/general/sparsh_whatsapp_chat_icon_upload', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if (!$whatsAppIcon) {
$params = ['_secure' => $this->request->isSecure()];
return $this->assetRepo->getUrlWithParams('Sparsh_WhatsAppChat::images/whatsapp-chat-button.png', $params);
}
return $this->getMediaUrl(). 'sparsh/whatsapp_chat_image/'.$whatsAppIcon;
}
/**
* Return media path
*
* @return string
*/
public function getMediaUrl()
{
return $this->_storeManager->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
}
}
<?php
namespace Sparsh\WhatsAppChat\Model\Config\Source;
/**
* Class Position
* @package Sparsh\WhatsAppChat\Model\Config\Source
*/
class Position implements \Magento\Framework\Option\ArrayInterface
{
/**
* @return array
*/
public function toOptionArray()
{
return [
['value' => 'top-left', 'label' => __('Top-Left')],
['value' => 'top-right', 'label' => __('Top-Right')],
['value' => 'top-middle', 'label' => __('Top-Middle')],
['value' => 'left-middle', 'label' => __('Left-Middle')],
['value' => 'right-middle', 'label' => __('Right-Middle')],
['value' => 'bottom-middle', 'label' => __('Bottom-Middle')],
['value' => 'bottom-left', 'label' => __('Bottom-Left')],
['value' => 'bottom-right', 'label' => __('Bottom-Right')]
];
}
}
##WhatsApp Chat Extension
This extension is a perfect tool for store visitors to communicate instantly with the admin regarding any inquiries, queries, guidance and after-sale service..
##Support:
version - 2.3.x, 2.4.x
##How to install Extension
1. Download the archive file.
2. Unzip the file
3. Create a folder [Magento_Root]/app/code/Sparsh/WhatsAppChat
4. Drop/move the unzipped files to directory '[Magento_Root]/app/code/Sparsh/WhatsAppChat'
#Enable Extension:
- php bin/magento module:enable Sparsh_WhatsAppChat
- php bin/magento setup:upgrade
- php bin/magento cache:clean
- php bin/magento setup:static-content:deploy
- php bin/magento cache:flush
#Disable Extension:
- php bin/magento module:disable Sparsh_WhatsAppChat
- php bin/magento setup:upgrade
- php bin/magento cache:clean
- php bin/magento setup:static-content:deploy
- php bin/magento cache:flush
{
"name": "sparsh/whatsapp-chat-extension",
"description": "Sparsh WhatsApp Chat Extension for Magento 2",
"type": "magento2-module",
"version": "1.3.0",
"license": "OSL-3.0",
"require": {
"php": "~7.0.13|~7.1.0|~7.2.0|~7.3.0|~7.4.0|^8.0"
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sparsh\\WhatsAppChat\\": ""
}
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="sparsh" translate="label" sortOrder="500">
<label>Sparsh Extensions</label>
</tab>
<section id="wa_chat" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>WhatsApp Chat</label>
<tab>sparsh</tab>
<resource>Sparsh_WhatsAppChat::wa_chat</resource>
<group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General Settings</label>
<field id="enable" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Enable WhatsApp Chat</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="phone_number" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>WhatsApp Number</label>
<comment>Phone number with country code and in format e.g. +9195xxxxxxxx</comment>
<depends>
<field id="status">1</field>
</depends>
</field>
<field id="message" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Message</label>
<comment>Pre-filled message that will automatically appear in the text field of a chat</comment>
<depends>
<field id="status">1</field>
</depends>
</field>
<field id="sparsh_whatsapp_chat_icon_upload" translate="label" type="Magento\Config\Block\System\Config\Form\Field\Image" sortOrder="4" showInDefault="1" showInWebsite="1" >
<label>WhatsApp Chat Image</label>
<comment>WhatsApp Chat Image to be shown on frontend</comment>
<backend_model>Magento\Config\Model\Config\Backend\Image</backend_model>
<upload_dir config="system" scope_info="1">sparsh/whatsapp_chat_image</upload_dir>
<base_url type="media" scope_info="1">sparsh/whatsapp_chat_image</base_url>
<depends>
<field id="status">1</field>
</depends>
</field>
<field id="position" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>WhatsApp Chat Image Position</label>
<comment>WhatsApp Chat Image position to be shown on frontend</comment>
<source_model>Sparsh\WhatsAppChat\Model\Config\Source\Position</source_model>
<depends>
<field id="status">1</field>
</depends>
</field>
<field id="rel_px" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Relative Position</label>
<comment>E.G. "20px 10px", "0px 0px", "-10px 20px" etc...</comment>
<depends>
<field id="status">1</field>
</depends>
</field>
</group>
</section>
</system>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<wa_chat>
<general>
<enable>0</enable>
<phone_number>+9195xxxxxxxx</phone_number>
<message>Hello! I am interested in your product</message>
<position>bottom-left</position>
<rel_px>0px 0px</rel_px>
</general>
</wa_chat>
</default>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sparsh_WhatsAppChat" setup_version="1.3.0"></module>
</config>
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sparsh_WhatsAppChat',
__DIR__
);
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Sparsh_WhatsAppChat::css/whatsapp-chat.css" />
</head>
<body>
<referenceContainer name="before.body.end">
<block class="Magento\Framework\View\Element\Template" name="sparsh_whatsappchat"
template="Sparsh_WhatsAppChat::button.phtml">
</block>
</referenceContainer>
</body>
</page>
<?php $helper = $this->helper(\Sparsh\WhatsAppChat\Helper\Data::class);?>
<?php if ($helper->getWAStatus()): ?>
<div id="whatsappchat">
<a href="https://web.whatsapp.com/send?phone=<?= /* @noEscape */
$helper->getWAPhone(); ?>&amp;text=<?= /* @noEscape */
$helper->getWAMessage(); ?>" target="_blank" class="btn-web <?= /* @noEscape */
$helper->getWAPosition() ?>">
<img src="<?= /* @noEscape */
$helper->getWAIconUrl(); ?>" alt="WhatsApp Chat">
</a>
<a href="https://wa.me/<?= /* @noEscape */
$helper->getWAPhone(); ?>?text=<?= /* @noEscape */
$helper->getWAMessage(); ?>" target="_blank" class="btn-mobile <?= /* @noEscape */
$helper->getWAPosition() ?>">
<img src="<?= /* @noEscape */
$helper->getWAIconUrl(); ?>" alt="WhatsApp Chat">
</a>
</div>
<?php
$whatsAppRelPx1 = '0px';
$whatsAppRelPx2 = '0px';
$whatsAppRelPx = $helper->getWARelPx();
if ($whatsAppRelPx) {
$whatsAppRelPxArray = explode(" ", $whatsAppRelPx);
$whatsAppRelPx1 = trim($whatsAppRelPxArray[0]);
if (isset($whatsAppRelPxArray[1])) {
$whatsAppRelPx2 = trim($whatsAppRelPxArray[1]);
}
}
?>
<style type="text/css">
#whatsappchat a.top-left {
top: <?= $whatsAppRelPx1; ?>;
left: <?= $whatsAppRelPx2; ?>;
}
#whatsappchat a.top-right {
top: <?= $whatsAppRelPx1; ?>;
right: <?= $whatsAppRelPx2; ?>;
}
#whatsappchat a.top-middle {
top: <?= $whatsAppRelPx1; ?>;
left: 50%;
transform: translateX(-50%);
}
#whatsappchat a.left-middle {
left: <?= $whatsAppRelPx1; ?>;
top: 50%;
transform: translateY(-50%);
}
#whatsappchat a.right-middle {
right: <?= $whatsAppRelPx1; ?>;
top: 50%;
transform: translateY(-50%);
}
#whatsappchat a.bottom-middle {
bottom: <?= $whatsAppRelPx1; ?>;
left: 50%;
transform: translateX(-50%);
}
#whatsappchat a.bottom-left {
left: <?= $whatsAppRelPx1; ?>;
bottom: 0px;
}
#whatsappchat a.bottom-right {
right: <?= $whatsAppRelPx1; ?>;
bottom: <?= $whatsAppRelPx2; ?>;
}
</style>
<?php endif; ?>
#whatsappchat a {
position: fixed;
z-index: 9999;
float: right;
cursor: pointer;
min-width: 40px;
max-width: 200px;
text-align: center;
-webkit-transition: All .5s ease;
-moz-transition: All .5s ease;
-o-transition: All .5s ease;
-ms-transition: All .5s ease;
transition: All .5s ease;
}
@media(max-width: 767px) {
#whatsappchat a {
max-width: 150px;
}
#whatsappchat .btn-web{
display: none;
}
}
@media(min-width: 768px) {
#whatsappchat .btn-mobile{
display: none;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment