Skip to content

Commit

Permalink
Merge pull request #329 from magento-folks/bugs
Browse files Browse the repository at this point in the history
[Folks] Define Public API & Bugfix
  • Loading branch information
Idolov, Stanislav(sidolov) committed May 29, 2015
2 parents ea7b254 + 7458919 commit 02223fb
Show file tree
Hide file tree
Showing 24 changed files with 588 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ define(
"paymentMethod": methodData
};

var shippingMethodCode = quote.getSelectedShippingMethod()().split("_"),
var shippingMethodCode = quote.getSelectedShippingMethod()().slice(0).split("_"),
shippingMethodData = {
"shippingCarrierCode" : shippingMethodCode[0],
"shippingMethodCode" : shippingMethodCode[1]
"shippingCarrierCode" : shippingMethodCode.shift(),
"shippingMethodCode" : shippingMethodCode.join('_')
},
serviceUrl;
if (quote.getCheckoutMethod()() === 'guest') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
/*global define*/
define(
['ko', 'jquery'],
function (ko, $) {
"use strict";
var rates = ko.observable([]);
return {
shippingRates: ko.observableArray([]),
Expand All @@ -30,29 +30,34 @@ define(
return this.shippingRates;
},
getTitleByCode: function(methodCodeParts) {
var shippingMethodTitle = '';
if (methodCodeParts) {
$.each(rates(), function (key, entity) {
if (entity['carrier_code'] == methodCodeParts[0]
&& entity['method_code'] == methodCodeParts[1]) {
shippingMethodTitle = entity['carrier_title'] + " - " + entity['method_title'];
}
});
var shippingMethodTitle = '', shippingMethodCode, carrierCode, methodCode;
if (!methodCodeParts) {
return shippingMethodTitle;
}
shippingMethodCode = methodCodeParts.slice(0);
carrierCode = shippingMethodCode.shift();
methodCode = shippingMethodCode.join('_');
$.each(rates(), function (key, entity) {
if (entity['carrier_code'] === carrierCode && entity['method_code'] === methodCode) {
shippingMethodTitle = entity['carrier_title'] + " - " + entity['method_title'];
}
});
return shippingMethodTitle;
},
getRateByCode : function(methodCodeParts) {
var shippingRates = [];
var shippingRates = [],
shippingMethodCode = methodCodeParts.slice(0),
carrierCode = shippingMethodCode.shift(),
methodCode = shippingMethodCode.join('_');
if (methodCodeParts) {
$.each(rates(), function (key, entity) {
if (entity['carrier_code'] == methodCodeParts[0]
&& entity['method_code'] == methodCodeParts[1]) {
if (entity['carrier_code'] === carrierCode && entity['method_code'] === methodCode) {
shippingRates.push(entity);
}
});
}
return shippingRates;
}
}
};
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,55 @@
*/
namespace Magento\CheckoutAgreements\Api;

/**
* Interface CheckoutAgreementsRepositoryInterface
* @api
*/
interface CheckoutAgreementsRepositoryInterface
{
/**
* Return data object for specified checkout agreement ID and store.
*
* @param int $id
* @param int $storeId
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface
*/
public function get($id, $storeId = null);

/**
* Lists active checkout agreements.
*
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface[]
*/
public function getList();

/**
* Create/Update new checkout agreements with data object values
*
* @param \Magento\CheckoutAgreements\Api\Data\AgreementInterface $data
* @param int $storeId
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException If there is a problem with the input
* @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist
*/
public function save(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data, $storeId = null);

/**
* Delete checkout agreement
*
* @param \Magento\CheckoutAgreements\Api\Data\AgreementInterface $data
* @return bool
* @throws \Magento\Framework\Exception\CouldNotDeleteException If there is a problem with the input
*/
public function delete(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data);

/**
* Delete checkout agreement by id
*
* @param int $id
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist
* @throws \Magento\Framework\Exception\CouldNotDeleteException If there is a problem with the input
*/
public function deleteById($id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface;
use Magento\CheckoutAgreements\Model\Resource\Agreement as AgreementResource;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\Store;

/**
* Checkout agreement repository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CheckoutAgreementsRepository implements CheckoutAgreementsRepositoryInterface
{
Expand All @@ -41,21 +46,37 @@ class CheckoutAgreementsRepository implements CheckoutAgreementsRepositoryInterf
*/
private $scopeConfig;

/**
* @var AgreementResource
*/
private $resourceModel;

/**
* @var AgreementFactory
*/
private $agreementFactory;

/**
* Constructs a checkout agreement data object.
*
* @param AgreementCollectionFactory $collectionFactory Collection factory.
* @param \Magento\Store\Model\StoreManagerInterface $storeManager Store manager.
* @param ScopeConfigInterface $scopeConfig Scope config.
* @param AgreementResource $agreementResource
* @param AgreementFactory $agreementFactory
*/
public function __construct(
AgreementCollectionFactory $collectionFactory,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
AgreementResource $agreementResource,
AgreementFactory $agreementFactory
) {
$this->collectionFactory = $collectionFactory;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->resourceModel = $agreementResource;
$this->agreementFactory = $agreementFactory;
}

/**
Expand All @@ -81,4 +102,67 @@ public function getList()

return $agreementDataObjects;
}

/**
* {@inheritdoc}
*/
public function save(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data, $storeId = null)
{
$id = $data->getAgreementId();

if ($id) {
$data = $this->get($id, $storeId)->addData($data->getData());
}
if ($storeId === null) {
$storeId = $this->storeManager->getStore()->getId();
}
$data->setStores($storeId);
try {
$this->resourceModel->save($data);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\CouldNotSaveException(
__('Unable to save checkout agreement %1', $data->getAgreementId())
);
}
return $data;
}

/**
* {@inheritdoc}
*/
public function delete(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data)
{
try {
$this->resourceModel->delete($data);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\CouldNotDeleteException(
__('Unable to remove checkout agreement %1', $data->getAgreementId())
);
}
return true;
}

/**
* {@inheritdoc}
*/
public function deleteById($id)
{
$model = $this->get($id);
$this->delete($model);
return true;
}

/**
* {@inheritdoc}
*/
public function get($id, $storeId = null)
{
/** @var AgreementFactory $agreement */
$agreement = $this->agreementFactory->create();
$this->resourceModel->load($agreement, $id);
if (!$agreement->getId()) {
throw new NoSuchEntityException(__('Checkout agreement with specified ID "%1" not found.', $id));
}
return $agreement;
}
}
Loading

0 comments on commit 02223fb

Please sign in to comment.