Skip to content

Commit

Permalink
Merge pull request #2 from craftcms/develop
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
samuelbirch committed Jul 1, 2020
2 parents 0afbf0e + f95c044 commit 268eddf
Show file tree
Hide file tree
Showing 42 changed files with 397 additions and 126 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -20,9 +20,10 @@ What did you expect to happen?

**Additional info**
- Craft version:
- Commerce version:
- PHP version:
- Database driver & version:
- Plugins & versions:
- Other Plugins & versions:

**Additional context**
Add any other context about the problem here.
40 changes: 36 additions & 4 deletions CHANGELOG.md
Expand Up @@ -3,18 +3,50 @@
## Unreleased

### Added
- Added `craft\commerce\base\Gateway::getTransactionHashFromWebhook()`;
- Added `craft\commerce\events\ModifyCartInfoEvent::$cart`. ([#1536](https://github.com/craftcms/commerce/issues/1536))
- Added the `hasVariant` argument to GraphQL product queries. ([#1544](https://github.com/craftcms/commerce/issues/1544))
- Added `craft\commerce\gql\types\input\Variant`.

### Fixed
- Fixed a bug products were incorrectly showing as having sales when using the `hasSales` query parameter.
- Fixed a bug where the Edit Order page would save the previous order status message after only changing the status. ([#1366](https://github.com/craftcms/commerce/issues/1366))
- Fixed a bug where it wasn’t possible to delete all line item statuses.

## 3.1.10 - 2020-06-23

### Added
- Added the `salePrice` and `sales` fields to GraphQL variant queries. ([#1525](https://github.com/craftcms/commerce/issues/1525))
- Added support for non-parameterized gateway webhook URLs. ([#1530](https://github.com/craftcms/commerce/issues/1530))
- Added `craft\commerce\gql\types\SaleType`.

### Changed
- The selected shipping method now shows both name and handle for completed orders on the Edit Order page. ([#1472](https://github.com/craftcms/commerce/issues/1472))

### Fixed
- Fixed a bug where the current user’s email was unintentionally being used as a fallback when creating a customer with an invalid email address on the Edit Order page. ([#1523](https://github.com/craftcms/commerce/issues/1523))
- Fixed a bug where an incorrect validation error would be shown when using custom address validation on the Edit Order page. ([#1519](https://github.com/craftcms/commerce/issues/1519))
- Fixed a bug where `defaultVariantId` wasn’t being set when saving a Product. ([#1529](https://github.com/craftcms/commerce/issues/1529))
- Fixed a bug where custom shipping methods would show a zero price. ([#1532](https://github.com/craftcms/commerce/issues/1532))
- Fixed a bug where the payment form modal wasn’t getting sized correctly on the Edit Order page. ([#1441](https://github.com/craftcms/commerce/issues/1441))
- Fixed the link to Commerce documentation from the control panel. ([#1517](https://github.com/craftcms/commerce/issues/1517))
- Fixed a deprecation warning for `Order::getAvailableShippingMethods()` on the Edit Order page. ([#1518](https://github.com/craftcms/commerce/issues/1518))

## 3.1.9 - 2020-06-17

### Added
- Added `craft\commerce\base\Gateway::getTransactionHashFromWebhook()`.
- Added `craft\commerce\services\OrderAdjustments::EVENT_REGISTER_DISCOUNT_ADJUSTERS`.
- Added `craft\commerce\services\Webhooks`;
- Added `craft\commerce\services\Webhooks`.

### Changed
- Discount calculations now take into account discount adjustments created by custom discount adjusters. ([#1506](https://github.com/craftcms/commerce/issues/1506))
- Discount calculations now take adjustments created by custom discount adjusters into account. ([#1506](https://github.com/craftcms/commerce/issues/1506))
- Improved handling of race conditions between processing a webhook and completing an order. ([#1510](https://github.com/craftcms/commerce/issues/1510))
- Improved performance when retrieving order statuses. ([#1497](https://github.com/craftcms/commerce/issues/1497))

### Fixed
- Fixed a bug where zero stock items would be removed from the order before accepting payment. ([#1503](https://github.com/craftcms/commerce/issues/1503))
- Fixed an error that occurred when saving an order with a deleted variant on the Edit Order page. ([#1504](https://github.com/craftcms/commerce/issues/1504))
- Fixed an error that occurred when saving an order with a deleted variant on the Edit Order page. ([#1504](https://github.com/craftcms/commerce/issues/1504))
- Fixed a bug where line items weren’t being returned in the correct order after adding a new line item to the card via Ajax. ([#1496](https://github.com/craftcms/commerce/issues/1496))
- Fixed a bug where countries and states weren’t being returned in the correct order. ([#1512](https://github.com/craftcms/commerce/issues/1512))
- Fixed a deprecation warning. ([#1508](https://github.com/craftcms/commerce/issues/1508))

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "craftcms/commerce",
"description": "Craft Commerce",
"type": "craft-plugin",
"version": "3.1.8",
"version": "3.1.10",
"keywords": [
"cms",
"craftcms",
Expand All @@ -16,7 +16,7 @@
"issues": "https://github.com/craftcms/commerce/issues?state=open",
"forum": "https://craftcms.stackexchange.com/",
"source": "https://github.com/craftcms/commerce",
"docs": "https://docs.craftcms.com/commerce/v2/",
"docs": "https://docs.craftcms.com/commerce/v3/",
"rss": "https://github.com/craftcms/commerce/releases.atom"
},
"require": {
Expand All @@ -36,7 +36,7 @@
"name": "Craft Commerce",
"description": "Create beautifully bespoke ecommerce experiences",
"developer": "Pixel & Tonic",
"documentationUrl": "https://docs.craftcms.com/commerce/v2/"
"documentationUrl": "https://docs.craftcms.com/commerce/v3/"
},
"require-dev": {
"roave/security-advisories": "dev-master",
Expand Down
23 changes: 8 additions & 15 deletions src/Plugin.php
Expand Up @@ -150,12 +150,12 @@ public function init()
parent::init();
$this->_setPluginComponents();
$this->_registerCpRoutes();
$this->_registerSiteRoutes();
$this->_addTwigExtensions();
$this->_registerFieldTypes();
$this->_registerRedactorLinkOptions();
$this->_registerPermissions();
$this->_registerCraftEventListeners();
$this->_registerSessionEventListeners();
$this->_registerProjectConfigEventListeners();
$this->_registerWidgets();
$this->_registerVariables();
Expand All @@ -171,7 +171,7 @@ public function init()
$this->_registerElementExports();
$this->_defineResaveCommand();

Craft::setAlias('@commerceLib', Craft::getAlias('@craft/commerce/../lib'));
Craft::setAlias('@commerceLib', Craft::getAlias('@craft/commerce/../lib'));
}

/**
Expand Down Expand Up @@ -377,18 +377,6 @@ private function _registerPermissions()
});
}

/**
* Register Commerce’s session event listeners
*/
private function _registerSessionEventListeners()
{
if (!Craft::$app->getRequest()->getIsConsoleRequest()) {
Event::on(UserElement::class, UserElement::EVENT_AFTER_SAVE, [$this->getCustomers(), 'saveUserHandler']);
Event::on(User::class, User::EVENT_AFTER_LOGIN, [$this->getCustomers(), 'loginHandler']);
Event::on(User::class, User::EVENT_AFTER_LOGOUT, [$this->getCustomers(), 'logoutHandler']);
}
}

/**
* Register Commerce’s project config event listeners
*/
Expand Down Expand Up @@ -446,9 +434,14 @@ private function _registerProjectConfigEventListeners()
*/
private function _registerCraftEventListeners()
{
if (!Craft::$app->getRequest()->isConsoleRequest) {
Event::on(User::class, User::EVENT_AFTER_LOGIN, [$this->getCustomers(), 'loginHandler']);
Event::on(User::class, User::EVENT_AFTER_LOGOUT, [$this->getCustomers(), 'logoutHandler']);
}

Event::on(Sites::class, Sites::EVENT_AFTER_SAVE_SITE, [$this->getProductTypes(), 'afterSaveSiteHandler']);
Event::on(Sites::class, Sites::EVENT_AFTER_SAVE_SITE, [$this->getProducts(), 'afterSaveSiteHandler']);
Event::on(UserElement::class, UserElement::EVENT_AFTER_SAVE, [$this->getCustomers(), 'afterSaveUserHandler']);
Event::on(UserElement::class, UserElement::EVENT_AFTER_SAVE, [$this->getCustomers(), 'afterSaveUserHandler'], null, false); // Lets run this before other plugins if we can
Event::on(UserElement::class, UserElement::EVENT_BEFORE_DELETE, [$this->getSubscriptions(), 'beforeDeleteUserHandler']);
Event::on(Purchasable::class, Elements::EVENT_BEFORE_RESTORE_ELEMENT, [$this->getPurchasables(), 'beforeRestorePurchasableHandler']);
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/Gateway.php
Expand Up @@ -130,7 +130,7 @@ abstract public function getPaymentFormHtml(array $params);
* Returns the transaction hash based on a webhook request
*
* @return string|null
* @since 3.x
* @since 3.1.9
*/
public function getTransactionHashFromWebhook()
{
Expand Down
2 changes: 1 addition & 1 deletion src/base/GatewayInterface.php
Expand Up @@ -209,7 +209,7 @@ public function availableForUseWithOrder(Order $order): bool;
* param or part of the response data.
*
* @return mixed
* @since 3.x
* @since 3.1.9
*/
public function getTransactionHashFromWebhook();
}
11 changes: 4 additions & 7 deletions src/base/ShippingMethod.php
Expand Up @@ -7,8 +7,7 @@

namespace craft\commerce\base;

use Craft;
use craft\base\Model;
use craft\commerce\base\Model as BaseModel;
use craft\commerce\elements\Order;
use craft\commerce\errors\NotImplementedException;

Expand All @@ -18,7 +17,7 @@
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 2.0
*/
abstract class ShippingMethod extends Model implements ShippingMethodInterface
abstract class ShippingMethod extends BaseModel implements ShippingMethodInterface
{
/**
* @var int ID
Expand Down Expand Up @@ -149,15 +148,13 @@ public function getPriceForOrder(Order $order)

foreach ($lineItems as $item) {
$purchasable = $item->getPurchasable();
if($purchasable && !$purchasable->getIsShippable())
{
if ($purchasable && !$purchasable->getIsShippable()) {
$nonShippableItems[$item->id] = $item->id;
}
}

// Are all line items non shippable items? No shipping cost.
if(count($lineItems) == count($nonShippableItems))
{
if (count($lineItems) == count($nonShippableItems)) {
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/controllers/BaseFrontEndController.php
Expand Up @@ -68,7 +68,9 @@ protected function cartArray(Order $cart): array
// Fire a 'modifyCartContent' event
$event = new ModifyCartInfoEvent([
'cartInfo' => $cartInfo,
'cart' => $cart
]);

$this->trigger(self::EVENT_MODIFY_CART_INFO, $event);

return $event->cartInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/OrdersController.php
Expand Up @@ -405,7 +405,7 @@ private function _orderToArray($order)
// Typecast order attributes
$order->typeCastAttributes();

$extraFields = ['lineItems.snapshot', 'availableShippingMethods', 'billingAddress', 'shippingAddress'];
$extraFields = ['lineItems.snapshot', 'availableShippingMethodOptions', 'billingAddress', 'shippingAddress'];

$orderArray = $order->toArray($orderFields, $extraFields);

Expand Down
18 changes: 14 additions & 4 deletions src/controllers/WebhooksController.php
Expand Up @@ -9,8 +9,9 @@

use Craft;
use craft\commerce\Plugin;
use Throwable;
use yii\web\BadRequestHttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;

/**
Expand All @@ -35,10 +36,19 @@ class WebhooksController extends BaseController
* @return Response
* @throws HttpException If webhook not expected.
*/
public function actionProcessWebhook(): Response
public function actionProcessWebhook($gatewayId = null): Response
{
$gatewayId = Craft::$app->getRequest()->getRequiredParam('gateway');
$gateway = Plugin::getInstance()->getGateways()->getGatewayById($gatewayId);
if ($gatewayId == null) {
$gatewayId = Craft::$app->getRequest()->getRequiredParam('gateway');
}

if (!$gatewayId) {
throw new BadRequestHttpException('Invalid gateway ID: ' . $gatewayId);
}

if (!$gateway = Plugin::getInstance()->getGateways()->getGatewayById($gatewayId)) {
throw new NotFoundHttpException('Gateway not found');
}

return Plugin::getInstance()->getWebhooks()->processWebhook($gateway);
}
Expand Down
7 changes: 5 additions & 2 deletions src/elements/Order.php
Expand Up @@ -40,6 +40,7 @@
use craft\db\Query;
use craft\elements\User;
use craft\errors\ElementNotFoundException;
use craft\helpers\ArrayHelper;
use craft\helpers\Db;
use craft\helpers\StringHelper;
use craft\helpers\Template;
Expand Down Expand Up @@ -1491,7 +1492,7 @@ public function addLineItem($lineItem)
}

if (!$replaced) {
$lineItems[] = $lineItem;
ArrayHelper::prepend($lineItems, $lineItem);
}

$this->setLineItems($lineItems);
Expand Down Expand Up @@ -1604,11 +1605,13 @@ public function getAvailableShippingMethodOptions(): array
foreach ($methods as $method) {

$option = new ShippingMethodOption();
$option->setOrder($this);
foreach ($attributes as $attribute) {
$option->$attribute = $method->$attribute;
}

$option->setOrder($this);
$option->price = $method->getPriceForOrder($this);

$options[$option->handle] = $option;
}

Expand Down
1 change: 1 addition & 0 deletions src/elements/Product.php
Expand Up @@ -685,6 +685,7 @@ public function afterSave(bool $isNew)
$record->taxCategoryId = $this->taxCategoryId;
$record->shippingCategoryId = $this->shippingCategoryId;

$record->defaultVariantId = $this->getDefaultVariant()->id ?? null;
$record->defaultSku = $this->getDefaultVariant()->sku ?? '';
$record->defaultPrice = $this->getDefaultVariant()->price ?? 0;
$record->defaultHeight = $this->getDefaultVariant()->height ?? 0;
Expand Down
5 changes: 3 additions & 2 deletions src/elements/Variant.php
Expand Up @@ -220,7 +220,7 @@ class Variant extends Purchasable
public $stock;

/**
* @var int $hasUnlimitedStock
* @var bool $hasUnlimitedStock
*/
public $hasUnlimitedStock;

Expand Down Expand Up @@ -475,6 +475,7 @@ public function attributeLabels(): array

/**
* @return bool
* @throws InvalidConfigException
*/
public function getIsEditable(): bool
{
Expand Down Expand Up @@ -1196,7 +1197,7 @@ protected function tableAttributeHtml(string $attribute): string
}
case 'product':
{
return $this->product->title;
return '<span class="status '. $this->product->getStatus().'"></span>' . $this->product->title;
}
case 'price':
{
Expand Down
29 changes: 21 additions & 8 deletions src/elements/db/VariantQuery.php
Expand Up @@ -504,24 +504,37 @@ protected function beforePrepare(): bool
'sales.categoryRelationshipType',
])
->from(Table::SALES . ' sales')
->where(['enabled' => true])
->andWhere([
->where([
'or',
// Only a from date
[
'or',
['not', ['dateTo' => null]],
['>=', 'dateTo', Db::prepareDateForDb($now)],
],
[
'or',
'and',
['dateTo' => null],
['not', ['dateFrom' => null]],
['<=', 'dateFrom', Db::prepareDateForDb($now)],
],
// Only a to date
[
'and',
['dateFrom' => null],
['not', ['dateTo' => null]],
['>=', 'dateTo', Db::prepareDateForDb($now)],
],
// no dates
[
'dateFrom' => null,
'dateTo' => null,
],
// to and from dates
[
'and',
['not', ['dateFrom' => null]],
['not', ['dateTo' => null]],
['<=', 'dateFrom', Db::prepareDateForDb($now)],
['>=', 'dateTo', Db::prepareDateForDb($now)],
]
])
->andWhere(['enabled' => true])
->orderBy('sortOrder asc')
->all();

Expand Down
13 changes: 12 additions & 1 deletion src/events/ModifyCartInfoEvent.php
Expand Up @@ -7,6 +7,7 @@

namespace craft\commerce\events;

use craft\commerce\elements\Order;
use yii\base\Event;

/**
Expand All @@ -18,7 +19,17 @@
class ModifyCartInfoEvent extends Event
{
/**
* @var array The cart as an array
* @var array The cart info that is allowed to be modified
*/
public $cartInfo = [];


/**
* The cart object that can be used to modify the cart info.
* Do not mutate this object.
*
* @var Order|null
* @since 3.x
*/
public $cart;
}

0 comments on commit 268eddf

Please sign in to comment.