Skip to content

Commit 02223fb

Browse files
author
Idolov, Stanislav(sidolov)
committed
Merge pull request #329 from magento-folks/bugs
[Folks] Define Public API & Bugfix
2 parents ea7b254 + 7458919 commit 02223fb

24 files changed

+588
-30
lines changed

app/code/Magento/Checkout/view/frontend/web/js/action/select-payment-method.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ define(
2121
"paymentMethod": methodData
2222
};
2323

24-
var shippingMethodCode = quote.getSelectedShippingMethod()().split("_"),
24+
var shippingMethodCode = quote.getSelectedShippingMethod()().slice(0).split("_"),
2525
shippingMethodData = {
26-
"shippingCarrierCode" : shippingMethodCode[0],
27-
"shippingMethodCode" : shippingMethodCode[1]
26+
"shippingCarrierCode" : shippingMethodCode.shift(),
27+
"shippingMethodCode" : shippingMethodCode.join('_')
2828
},
2929
serviceUrl;
3030
if (quote.getCheckoutMethod()() === 'guest') {

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-service.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Copyright © 2015 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
/*jshint browser:true jquery:true*/
6-
/*global alert*/
5+
/*global define*/
76
define(
87
['ko', 'jquery'],
98
function (ko, $) {
9+
"use strict";
1010
var rates = ko.observable([]);
1111
return {
1212
shippingRates: ko.observableArray([]),
@@ -30,29 +30,34 @@ define(
3030
return this.shippingRates;
3131
},
3232
getTitleByCode: function(methodCodeParts) {
33-
var shippingMethodTitle = '';
34-
if (methodCodeParts) {
35-
$.each(rates(), function (key, entity) {
36-
if (entity['carrier_code'] == methodCodeParts[0]
37-
&& entity['method_code'] == methodCodeParts[1]) {
38-
shippingMethodTitle = entity['carrier_title'] + " - " + entity['method_title'];
39-
}
40-
});
33+
var shippingMethodTitle = '', shippingMethodCode, carrierCode, methodCode;
34+
if (!methodCodeParts) {
35+
return shippingMethodTitle;
4136
}
37+
shippingMethodCode = methodCodeParts.slice(0);
38+
carrierCode = shippingMethodCode.shift();
39+
methodCode = shippingMethodCode.join('_');
40+
$.each(rates(), function (key, entity) {
41+
if (entity['carrier_code'] === carrierCode && entity['method_code'] === methodCode) {
42+
shippingMethodTitle = entity['carrier_title'] + " - " + entity['method_title'];
43+
}
44+
});
4245
return shippingMethodTitle;
4346
},
4447
getRateByCode : function(methodCodeParts) {
45-
var shippingRates = [];
48+
var shippingRates = [],
49+
shippingMethodCode = methodCodeParts.slice(0),
50+
carrierCode = shippingMethodCode.shift(),
51+
methodCode = shippingMethodCode.join('_');
4652
if (methodCodeParts) {
4753
$.each(rates(), function (key, entity) {
48-
if (entity['carrier_code'] == methodCodeParts[0]
49-
&& entity['method_code'] == methodCodeParts[1]) {
54+
if (entity['carrier_code'] === carrierCode && entity['method_code'] === methodCode) {
5055
shippingRates.push(entity);
5156
}
5257
});
5358
}
5459
return shippingRates;
5560
}
56-
}
61+
};
5762
}
5863
);

app/code/Magento/CheckoutAgreements/Api/CheckoutAgreementsRepositoryInterface.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,55 @@
55
*/
66
namespace Magento\CheckoutAgreements\Api;
77

8+
/**
9+
* Interface CheckoutAgreementsRepositoryInterface
10+
* @api
11+
*/
812
interface CheckoutAgreementsRepositoryInterface
913
{
14+
/**
15+
* Return data object for specified checkout agreement ID and store.
16+
*
17+
* @param int $id
18+
* @param int $storeId
19+
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface
20+
*/
21+
public function get($id, $storeId = null);
22+
1023
/**
1124
* Lists active checkout agreements.
1225
*
1326
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface[]
1427
*/
1528
public function getList();
29+
30+
/**
31+
* Create/Update new checkout agreements with data object values
32+
*
33+
* @param \Magento\CheckoutAgreements\Api\Data\AgreementInterface $data
34+
* @param int $storeId
35+
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface
36+
* @throws \Magento\Framework\Exception\CouldNotSaveException If there is a problem with the input
37+
* @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist
38+
*/
39+
public function save(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data, $storeId = null);
40+
41+
/**
42+
* Delete checkout agreement
43+
*
44+
* @param \Magento\CheckoutAgreements\Api\Data\AgreementInterface $data
45+
* @return bool
46+
* @throws \Magento\Framework\Exception\CouldNotDeleteException If there is a problem with the input
47+
*/
48+
public function delete(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data);
49+
50+
/**
51+
* Delete checkout agreement by id
52+
*
53+
* @param int $id
54+
* @return bool
55+
* @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist
56+
* @throws \Magento\Framework\Exception\CouldNotDeleteException If there is a problem with the input
57+
*/
58+
public function deleteById($id);
1659
}

app/code/Magento/CheckoutAgreements/Model/CheckoutAgreementsRepository.php

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
use Magento\Store\Model\StoreManagerInterface;
1515
use Magento\Store\Model\ScopeInterface;
1616
use Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface;
17+
use Magento\CheckoutAgreements\Model\Resource\Agreement as AgreementResource;
18+
use Magento\Framework\Exception\NoSuchEntityException;
19+
use Magento\Store\Model\Store;
1720

1821
/**
1922
* Checkout agreement repository.
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2025
*/
2126
class CheckoutAgreementsRepository implements CheckoutAgreementsRepositoryInterface
2227
{
@@ -41,21 +46,37 @@ class CheckoutAgreementsRepository implements CheckoutAgreementsRepositoryInterf
4146
*/
4247
private $scopeConfig;
4348

49+
/**
50+
* @var AgreementResource
51+
*/
52+
private $resourceModel;
53+
54+
/**
55+
* @var AgreementFactory
56+
*/
57+
private $agreementFactory;
58+
4459
/**
4560
* Constructs a checkout agreement data object.
4661
*
4762
* @param AgreementCollectionFactory $collectionFactory Collection factory.
4863
* @param \Magento\Store\Model\StoreManagerInterface $storeManager Store manager.
4964
* @param ScopeConfigInterface $scopeConfig Scope config.
65+
* @param AgreementResource $agreementResource
66+
* @param AgreementFactory $agreementFactory
5067
*/
5168
public function __construct(
5269
AgreementCollectionFactory $collectionFactory,
5370
StoreManagerInterface $storeManager,
54-
ScopeConfigInterface $scopeConfig
71+
ScopeConfigInterface $scopeConfig,
72+
AgreementResource $agreementResource,
73+
AgreementFactory $agreementFactory
5574
) {
5675
$this->collectionFactory = $collectionFactory;
5776
$this->storeManager = $storeManager;
5877
$this->scopeConfig = $scopeConfig;
78+
$this->resourceModel = $agreementResource;
79+
$this->agreementFactory = $agreementFactory;
5980
}
6081

6182
/**
@@ -81,4 +102,67 @@ public function getList()
81102

82103
return $agreementDataObjects;
83104
}
105+
106+
/**
107+
* {@inheritdoc}
108+
*/
109+
public function save(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data, $storeId = null)
110+
{
111+
$id = $data->getAgreementId();
112+
113+
if ($id) {
114+
$data = $this->get($id, $storeId)->addData($data->getData());
115+
}
116+
if ($storeId === null) {
117+
$storeId = $this->storeManager->getStore()->getId();
118+
}
119+
$data->setStores($storeId);
120+
try {
121+
$this->resourceModel->save($data);
122+
} catch (\Exception $e) {
123+
throw new \Magento\Framework\Exception\CouldNotSaveException(
124+
__('Unable to save checkout agreement %1', $data->getAgreementId())
125+
);
126+
}
127+
return $data;
128+
}
129+
130+
/**
131+
* {@inheritdoc}
132+
*/
133+
public function delete(\Magento\CheckoutAgreements\Api\Data\AgreementInterface $data)
134+
{
135+
try {
136+
$this->resourceModel->delete($data);
137+
} catch (\Exception $e) {
138+
throw new \Magento\Framework\Exception\CouldNotDeleteException(
139+
__('Unable to remove checkout agreement %1', $data->getAgreementId())
140+
);
141+
}
142+
return true;
143+
}
144+
145+
/**
146+
* {@inheritdoc}
147+
*/
148+
public function deleteById($id)
149+
{
150+
$model = $this->get($id);
151+
$this->delete($model);
152+
return true;
153+
}
154+
155+
/**
156+
* {@inheritdoc}
157+
*/
158+
public function get($id, $storeId = null)
159+
{
160+
/** @var AgreementFactory $agreement */
161+
$agreement = $this->agreementFactory->create();
162+
$this->resourceModel->load($agreement, $id);
163+
if (!$agreement->getId()) {
164+
throw new NoSuchEntityException(__('Checkout agreement with specified ID "%1" not found.', $id));
165+
}
166+
return $agreement;
167+
}
84168
}

0 commit comments

Comments
 (0)