Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
azemoh committed Sep 18, 2020
0 parents commit 4a29fed
Show file tree
Hide file tree
Showing 21 changed files with 935 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/app/etc/local.xml

/errors/local.xml

/details5.php
/var
/media
/details5.php
/details5.php

/app/code/community/Fera/Aiconnector/CustomerBalance/license.txt
/.idea
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fera.ai Magento 2 Extension
This extension makes it easy to use Fera.ai to offer customers a live shopping experience in your product pages. To learn more about Fera go to https://www.fera.ai


## Installation
### 1. Create An Account
Go to https://app.fera.ai/signup?platform=magento and create a new account.

### 2. Follow the instructions to install the extension.
You will be provided with a link to the latest install files. Follow the instructions to install the app into your Magento store.

*That's it!*. If you follow the instructions described then your store will automatically be configured to connected to the Fera.ai servers.

## Usage
Go to https://app.fera.ai/skills to customize your experience!

## Help
If you're seeing this repo you're probably a trusted developer - so just feel free to email help a-t fera dot ai with any questions.
98 changes: 98 additions & 0 deletions src/app/code/Fera/Ai/Block/Footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* @author: Sviatoslav Lashkiv
* @email: ss.lashkiv@gmail.com
* @team: MageCloud
*/

namespace Fera\Ai\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Customer\Model\Session as CustomerSession;
use Fera\Ai\Helper\Data;

/**
* Class Footer
* @package Fera\Ai\Block
*/
class Footer extends Template
{
/**
* @var CustomerSession
*/
protected $customerSession;

/**
* @var Data
*/
protected $helper;

/**
* Footer constructor.
* @param Context $context
* @param CustomerSession $customerSession
* @param Data $helper
* @param array $data
*/
public function __construct(
Context $context,
CustomerSession $customerSession,
Data $helper,
array $data = [])
{
$this->customerSession = $customerSession;
$this->helper = $helper;
parent::__construct($context, $data);
}

public function isEnabled()
{
return $this->helper->isEnabled();
}

public function getDebugJs()
{
return $this->helper->getDebugJs();
}

public function getPublicKey()
{
return $this->helper->getPublicKey();
}

public function getApiUrl()
{
return $this->helper->getApiUrl();
}

public function getJsUrl()
{
return $this->helper->getJsUrl();
}

public function getShopperData()
{
$customer = $this->customerSession->getCustomer();

if (!$customer->getId()) return false;

$shopperData = [
'customer_id' => $customer->getId(),
'email' => $customer->getEmail(),
'name' => $customer->getName(),
];

return $this->helper->jsonEncode($shopperData);
}

public function getCartJson()
{
return $this->helper->getCartJson();
}

public function jsonEncode($data)
{
return $this->helper->jsonEncode($data);
}
}
119 changes: 119 additions & 0 deletions src/app/code/Fera/Ai/Block/Footer/Checkout/Success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* @author: Sviatoslav Lashkiv
* @email: ss.lashkiv@gmail.com
* @team: MageCloud
*/

namespace Fera\Ai\Block\Footer\Checkout;

use Magento\Framework\View\Element\Template\Context;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Sales\Model\Order\Config;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Directory\Helper\Data as DirectoryHelperData;
use Fera\Ai\Helper\Data as FeraHelper;

/**
* Class Success
* @package Fera\Ai\Block\Footer\Checkout
*/
class Success extends \Magento\Checkout\Block\Onepage\Success
{
/**
* @var CustomerSession
*/
protected $customerSession;

/**
* @var DirectoryHelperData
*/
protected $directoryHelper;

/**
* @var FeraHelper
*/
protected $helper;

/**
* Success constructor.
* @param Context $context
* @param CheckoutSession $checkoutSession
* @param Config $orderConfig
* @param HttpContext $httpContext
* @param CustomerSession $customerSession
* @param DirectoryHelperData $directoryHelper
* @param FeraHelper $helper
* @param array $data
*/
public function __construct(
Context $context,
CheckoutSession $checkoutSession,
Config $orderConfig,
HttpContext $httpContext,
CustomerSession $customerSession,
DirectoryHelperData $directoryHelper,
FeraHelper $helper,
array $data = []
)
{
$this->customerSession = $customerSession;
$this->directoryHelper = $directoryHelper;
$this->helper = $helper;
parent::__construct($context, $checkoutSession, $orderConfig, $httpContext, $data);
}

/**
* @return bool|mixed
*/
public function isEnabled()
{
return $this->helper->isEnabled();
}

/**
* Get last order, JSONify it and return it.
* @return String
*/
public function getOrderJson()
{
$order = $this->_checkoutSession->getLastRealOrder();

$customer = null;
if (!empty($this->customerSession->getCustomerId())) {
$customer = $this->customerSession->getCustomer();
$address = $customer->getDefaultShippingAddress();

if (!empty($address)) {
$address = $address->getData();
}

$customer = [
'id' => $this->customerSession->getCustomerId(),
'first_name' => $this->customerSession->getCustomer()->getFirstname(),
'email' => $this->customerSession->getCustomer()->getEmail(),
'address' => $address
];
}

$currencyCode = $this->_storeManager->getStore()->getCurrentCurrencyCode();
$total = $order->getGrandTotal();
$totalUsd = $this->directoryHelper->currencyConvert($total, $currencyCode, 'USD');

$orderData = [
'id' => $order->getId(),
'number' => $order->getIncrementId(),
'total' => $total,
'total_usd' => $totalUsd,
'created_at' => $this->helper->formatDate($order->getCreatedAt()),
'modified_at' => $this->helper->formatDate($order->getUpdatedAt()),
'line_items' => $this->helper->serializeQuoteItems($order->getAllItems()),
'customer' => $customer,
'source_name' => 'web'
];

return $this->helper->jsonEncode($orderData);
}

}
Loading

0 comments on commit 4a29fed

Please sign in to comment.