Skip to content

Commit

Permalink
Merge pull request #11 from getbread/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
omgitsdev authored Jan 16, 2018
2 parents 9c499db + 057b0af commit 0c5bb1c
Show file tree
Hide file tree
Showing 45 changed files with 1,677 additions and 451 deletions.
5 changes: 2 additions & 3 deletions Bread/BreadCheckout/Block/Checkout/Overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getProductDataJson()
*/
protected function _toHtml()
{
if( $this->quoteHelper->isEnabledOnCOP() ) {
if ($this->quoteHelper->isEnabledOnCOP()) {
return parent::_toHtml();
}

Expand All @@ -115,5 +115,4 @@ public function getAllowCheckout()
{
return ($this->quoteHelper->getAllowCheckoutCP()) ? 'true' : 'false';
}

}
}
3 changes: 1 addition & 2 deletions Bread/BreadCheckout/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ protected function getJsLibLocation()
{
return $this->helper->getJsLibLocation();
}

}
}
30 changes: 26 additions & 4 deletions Bread/BreadCheckout/Block/Payment/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class Form extends \Magento\Payment\Block\Form
/**
* Constructor
*/
public function __construct(\Magento\Framework\View\Element\Template\Context $context,
\Bread\BreadCheckout\Helper\Catalog $helper,
array $data = [])
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Bread\BreadCheckout\Helper\Catalog $helper,
array $data = []
) {

$this->helper = $helper;
parent::__construct($context, $data);
}
Expand All @@ -30,6 +32,26 @@ public function getQuoteDataUrl()
return $this->helper->getQuoteDataUrl();
}

/**
* Get controller URL for cart generation
*
* @return string
*/
public function getGenerateCartUrl()
{
return $this->helper->getGenerateCartUrl();
}

/**
* Get controller URL for email sending
*
* @return string
*/
public function getSendMailUrl()
{
return $this->helper->getSendMailUrl();
}

/**
* Get button size config setting
*
Expand Down
3 changes: 1 addition & 2 deletions Bread/BreadCheckout/Block/Payment/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ protected function _prepareSpecificInformation($transport = null)
} else {
$transId = $info->getLastTransId();
}
$transport->addData( [(string)$label => $transId] );
$transport->addData([(string)$label => $transId]);
return $transport;
}

}
106 changes: 97 additions & 9 deletions Bread/BreadCheckout/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class View extends \Magento\ConfigurableProduct\Block\Product\View\Type\Configur
{
protected $_product;


/** @var \Magento\Framework\Registry */
protected $registry;

Expand Down Expand Up @@ -115,7 +114,18 @@ public function getProductDataJson()
*/
public function getDiscountDataJson()
{
$data = array();
$data = [];
return $this->jsonEncode($data);
}

/**
* Get cart size financing configuration
*
* @return string
*/
public function getCartSizeFinancingJson()
{
$data = $this->catalogHelper->getCartSizeFinancingData();
return $this->jsonEncode($data);
}

Expand Down Expand Up @@ -156,7 +166,7 @@ public function getAsLowAs()
*/
protected function _toHtml()
{
if( $this->catalogHelper->isEnabledOnPDP() ) {
if ($this->catalogHelper->isEnabledOnPDP()) {
return parent::_toHtml();
}

Expand Down Expand Up @@ -243,6 +253,16 @@ public function getAllowCheckout()
return ($this->catalogHelper->getAllowCheckoutPDP()) ? 'true' : 'false';
}

/**
* Is Healthcare mode?
*
* @return bool
*/
public function isHealthcare()
{
return (bool) ($this->dataHelper->isHealthcare());
}

/**
* Return Block View Product Code
*
Expand Down Expand Up @@ -281,7 +301,6 @@ public function getCartSizeThreshold()
public function getCartSizeFinancingId()
{
return $this->dataHelper->getCartSizeFinancingId();

}

/**
Expand All @@ -298,7 +317,7 @@ public function getChildProductIds(\Magento\Catalog\Model\Product $product)
->addFilterByRequiredOptions();

$itemIds = [];
foreach($usedChildrenProduct as $simpleProduct){
foreach ($usedChildrenProduct as $simpleProduct) {
$itemIds[] = [ $simpleProduct->getId() => $simpleProduct->getSku() ];
}

Expand All @@ -315,7 +334,7 @@ public function getCustomOptionsData($options)
{
$optionsData = [];

foreach($options as $option) {
foreach ($options as $option) {
if ($option->getValues()) {
foreach ($option->getValues() as $k => $v) {
$optionsData[$option->getId()][$k] = [
Expand All @@ -334,14 +353,83 @@ public function getCustomOptionsData($options)
return $this->jsonEncode($optionsData);
}

/**
* Get button location string for product page
*
* @return string
*/
public function getProductViewLocation()
{
return $this->dataHelper->getProductViewLocation();
}

/**
* Get button location string for cart summary page
*
* @return string
*/
public function getCartSummaryLocation()
{
return $this->dataHelper->getCartSummaryLocation();
}

/**
* Get button location string for checkout page
*
* @return string
*/
public function getCheckoutLocation()
{
return $this->dataHelper->getCheckoutLocation();
}

/**
* Get button location string for financing page
*
* @return string
*/
public function getFinancingLocation()
{
return $this->dataHelper->getFinancingLocation();
}

/**
* Get button location string for marketing page
*
* @return string
*/
public function getMarketingLocation()
{
return $this->dataHelper->getMarketingLocation();
}

/**
* Get button location string for category page
*
* @return string
*/
public function getCategoryPageLocation()
{
return $this->dataHelper->getCategoryPageLocation();
}

/**
* Get button location string for other purposes
*
* @return string
*/
public function getOtherLocation()
{
return $this->dataHelper->getOtherLocation();
}
/**
* Publicly accessible json encoder
*
* @param $data
* @return string
*/
public function jsonEncode($data) {
public function jsonEncode($data)
{
return $this->jsonHelper->jsonEncode($data);
}

}
}
105 changes: 105 additions & 0 deletions Bread/BreadCheckout/Controller/Adminhtml/Bread/GenerateCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Bread\BreadCheckout\Controller\Adminhtml\Bread;

use Braintree\Exception;

class GenerateCart extends \Magento\Backend\App\Action
{
/** @var \Bread\BreadCheckout\Helper\Quote */
protected $helper;
protected $cart;
protected $config;
protected $paymentApiClient;
protected $customerHelper;
protected $breadMethod;
protected $urlHelper;

public function __construct(
\Magento\Backend\App\Action\Context $context,
\Bread\BreadCheckout\Helper\Quote $helper,
\Magento\Checkout\Model\Cart $cart,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Bread\BreadCheckout\Model\Payment\Api\Client $paymentApiClient,
\Bread\BreadCheckout\Helper\Customer $customerHelper,
\Bread\BreadCheckout\Model\Payment\Method\Bread $breadMethod,
\Bread\BreadCheckout\Helper\Url $urlHelper
)
{
$this->resultFactory = $context->getResultFactory();
$this->helper = $helper;
$this->cart = $cart;
$this->config = $scopeConfig;
$this->paymentApiClient = $paymentApiClient;
$this->customerHelper = $customerHelper;
$this->breadMethod = $breadMethod;
$this->urlHelper = $urlHelper;
parent::__construct($context);
}

/**
* Generate cart from backend
*
* @return \Magento\Framework\Controller\Result\Json
*/
public function execute()
{
try {
$quote = $this->helper->getSessionQuote();

$ret = [ "error" => false,
"successRows" => [],
"errorRows" => [],
"cartUrl" => ""
];

if (!$quote || ($quote && $quote->getItemsQty() == 0)) {
throw new Exception(__("Cart is empty"));
}

if ($quote->getPayment()->getMethodInstance()->getCode() != $this->breadMethod->getMethodCode()) {
throw new Exception(__("In order to checkout with bread you must choose bread as payment option."));
}

if (!$this->helper->getShippingOptions()) {
throw new Exception(__("Please specify a shipping method."));
}

$arr = [];

$arr["expiration"] = date('Y-m-d', strtotime("+" . $this->config->getValue('checkout/cart/delete_quote_after', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) . "days"));
$arr["options"] = [];
$arr["options"]["orderRef"] = $quote->getId();

$arr["options"]["completeUrl"] = $this->urlHelper->getLandingPageURL();
$arr["options"]["errorUrl"] = $this->urlHelper->getLandingPageURL(true);

$arr["options"]["shippingOptions"] = [ $this->helper->getShippingOptions() ];

$arr["options"]["shippingContact"] = $this->helper->getShippingAddressData();
$arr["options"]["billingContact"] = $this->helper->getBillingAddressData();

$arr["options"]["items"] = $this->helper->getQuoteItemsData();

$arr["options"]["discounts"] = $this->helper->getDiscountData() ? $this->helper->getDiscountData() : [];

$arr["options"]["tax"] = $this->helper->getTaxValue();

$result = $this->paymentApiClient->submitCartData($arr);

$ret["successRows"] = [
__("Cart with Financing was successfully created."),
__('Following link can be used by your customer to complete purchase.'),
sprintf('<a href="%1$s">%1$s</a>', $result["url"])
];

$ret["cartUrl"] = $result["url"];

}catch (\Exception $e){
$ret["error"] = true;
$ret["errorRows"][] = __("There was an error in cart creation:");
$ret["errorRows"][] = $e->getMessage();
}
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->setData($ret);
}
}
14 changes: 11 additions & 3 deletions Bread/BreadCheckout/Controller/Adminhtml/Bread/QuoteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ class QuoteData extends \Magento\Backend\App\Action
/** @var \Bread\BreadCheckout\Helper\Quote */
protected $helper;

/** @var \Bread\BreadCheckout\Helper\Data */
protected $helperData;

public function __construct(
\Magento\Backend\App\Action\Context $context,
\Bread\BreadCheckout\Helper\Quote $helper
\Bread\BreadCheckout\Helper\Quote $helper,
\Bread\BreadCheckout\Helper\Data $helperData
)
{
$this->resultFactory = $context->getResultFactory();
$this->helper = $helper;
$this->helperData = $helperData;
parent::__construct($context);
}

Expand All @@ -37,10 +42,13 @@ public function execute()
'shippingOptions' => $this->helper->getShippingOptions(),
'tax' => $this->helper->getTaxValue(),
'discounts' => $this->helper->getDiscountData(),
'cartSizeFinancing' => $this->helper->getCartSizeFinancingData(),
'grandTotal' => $this->helper->getGrandTotal(),
'asLowAs' => $this->helper->isAsLowAs(),
'paymentUrl' => $this->helper->getAdminPaymentUrl(),
'buttonCss' => $this->helper->getButtonDesign()
'buttonCss' => $this->helper->getButtonDesign(),
'buttonLocation' => $this->helperData->getOtherLocation(),
'isHealthcare' => $this->helper->isHealthcare()
]);
}
}
}
Loading

0 comments on commit 0c5bb1c

Please sign in to comment.