Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magento2
Browse files Browse the repository at this point in the history
 into 2.4-develop
  • Loading branch information
mage-os-ci committed Jul 8, 2023
2 parents da0c042 + 13e54e1 commit 6e4f533
Show file tree
Hide file tree
Showing 21 changed files with 909 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,13 @@ protected function prepareCatalogInventory(array $productIds)
if ($stockItemRow['use_config_max_sale_qty']) {
$stockItemRow['max_sale_qty'] = $this->stockConfiguration->getMaxSaleQty();
}

if ($stockItemRow['use_config_min_sale_qty']) {
$stockItemRow['min_sale_qty'] = $this->stockConfiguration->getMinSaleQty();
}
if ($stockItemRow['use_config_manage_stock']) {
$stockItemRow['manage_stock'] = $this->stockConfiguration->getManageStock();
}

$stockItemRows[$productId] = $stockItemRow;
}
return $stockItemRows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,44 @@

namespace Magento\Customer\Observer\Visitor;

use Magento\Customer\Model\Visitor;
use Magento\Framework\Event\Observer;
use Magento\Framework\Session\SessionManagerInterface;

/**
* Visitor Observer
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class InitByRequestObserver extends AbstractVisitorObserver
{
/**
* initByRequest
* @var SessionManagerInterface
*/
private $sessionManager;

/**
* @param Visitor $visitor
* @param SessionManagerInterface $sessionManager
*/
public function __construct(
Visitor $visitor,
SessionManagerInterface $sessionManager
) {
parent::__construct($visitor);
$this->sessionManager = $sessionManager;
}

/**
* Init visitor by request
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
if ($observer->getRequest()->getFullActionName() === 'customer_account_loginPost') {
$this->sessionManager->setVisitorData(['do_customer_login' => true]);
}
$this->visitor->initByRequest($observer);
}
}
14 changes: 11 additions & 3 deletions app/code/Magento/NewRelicReporting/Model/Apm/Deployments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laminas\Http\Request;
use Magento\Framework\HTTP\LaminasClient;
use Magento\Framework\HTTP\LaminasClientFactory;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\NewRelicReporting\Model\Config;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -37,21 +38,29 @@ class Deployments
*/
protected $clientFactory;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* Constructor
*
* @param Config $config
* @param LoggerInterface $logger
* @param LaminasClientFactory $clientFactory
* @param SerializerInterface $serializer
*/
public function __construct(
Config $config,
LoggerInterface $logger,
LaminasClientFactory $clientFactory
LaminasClientFactory $clientFactory,
SerializerInterface $serializer
) {
$this->config = $config;
$this->logger = $logger;
$this->clientFactory = $clientFactory;
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -97,8 +106,7 @@ public function setDeployment($description, $change = false, $user = false, $rev
'revision' => $revision
]
];

$client->setParameterPost($params);
$client->setRawBody($this->serializer->serialize($params));

try {
$response = $client->send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Laminas\Http\Response;
use Magento\Framework\HTTP\LaminasClient;
use Magento\Framework\HTTP\LaminasClientFactory;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\NewRelicReporting\Model\Apm\Deployments;
use Magento\NewRelicReporting\Model\Config;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -45,31 +46,24 @@ class DeploymentsTest extends TestCase
*/
protected $loggerMock;

/**
* @var SerializerInterface|MockObject
*/
private $serializerMock;

protected function setUp(): void
{
$this->httpClientFactoryMock = $this->getMockBuilder(LaminasClientFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();

$this->httpClientMock = $this->getMockBuilder(LaminasClient::class)
->setMethods(['send', 'setUri', 'setMethod', 'setHeaders', 'setParameterPost'])
->disableOriginalConstructor()
->getMock();

$this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->configMock = $this->getMockBuilder(Config::class)
->setMethods(['getNewRelicApiUrl', 'getNewRelicApiKey', 'getNewRelicAppId'])
->disableOriginalConstructor()
->getMock();
$this->httpClientFactoryMock = $this->createMock(LaminasClientFactory::class);
$this->httpClientMock = $this->createMock(LaminasClient::class);
$this->loggerMock = $this->createMock(LoggerInterface::class);
$this->configMock = $this->createMock(Config::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);

$this->model = new Deployments(
$this->configMock,
$this->loggerMock,
$this->httpClientFactoryMock
$this->httpClientFactoryMock,
$this->serializerMock
);
}

Expand Down Expand Up @@ -97,9 +91,13 @@ public function testSetDeploymentRequestOk()
->with($data['headers'])
->willReturnSelf();

$this->httpClientMock->expects($this->once())
->method('setParameterPost')
$this->serializerMock->expects($this->once())
->method('serialize')
->with($data['params'])
->willReturn(json_encode($data['params']));
$this->httpClientMock->expects($this->once())
->method('setRawBody')
->with(json_encode($data['params']))
->willReturnSelf();

$this->configMock->expects($this->once())
Expand Down Expand Up @@ -163,9 +161,13 @@ public function testSetDeploymentBadStatus()
->with($data['headers'])
->willReturnSelf();

$this->httpClientMock->expects($this->once())
->method('setParameterPost')
$this->serializerMock->expects($this->once())
->method('serialize')
->with($data['params'])
->willReturn(json_encode($data['params']));
$this->httpClientMock->expects($this->once())
->method('setRawBody')
->with(json_encode($data['params']))
->willReturnSelf();

$this->configMock->expects($this->once())
Expand Down Expand Up @@ -225,9 +227,13 @@ public function testSetDeploymentRequestFail()
->with($data['headers'])
->willReturnSelf();

$this->httpClientMock->expects($this->once())
->method('setParameterPost')
$this->serializerMock->expects($this->once())
->method('serialize')
->with($data['params'])
->willReturn(json_encode($data['params']));
$this->httpClientMock->expects($this->once())
->method('setRawBody')
->with(json_encode($data['params']))
->willReturnSelf();

$this->configMock->expects($this->once())
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/NewRelicReporting/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
</argument>
</arguments>
</type>
<type name="Magento\NewRelicReporting\Model\Apm\Deployments">
<arguments>
<argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Json</argument>
</arguments>
</type>
</config>
31 changes: 17 additions & 14 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/Discounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
class Discounts implements ResolverInterface
{
public const TYPE_SHIPPING = "SHIPPING";
public const TYPE_ITEM = "ITEM";
/**
* @inheritdoc
*/
Expand All @@ -41,21 +43,22 @@ private function getDiscountValues(Quote $quote)
{
$discountValues=[];
$address = $quote->getShippingAddress();
$totals = $address->getTotals();
if ($totals && is_array($totals)) {
foreach ($totals as $total) {
if (stripos($total->getCode(), 'total') === false && $total->getValue() < 0.00) {
$discount = [];
$amount = [];
$discount['label'] = $total->getTitle() ?: __('Discount');
$amount['value'] = $total->getValue() * -1;
$amount['currency'] = $quote->getQuoteCurrencyCode();
$discount['amount'] = $amount;
$discountValues[] = $discount;
}
$totalDiscounts = $address->getExtensionAttributes()->getDiscounts();

if ($totalDiscounts && is_array($totalDiscounts)) {
foreach ($totalDiscounts as $value) {
$discount = [];
$amount = [];
$discount['label'] = $value->getRuleLabel() ?: __('Discount');
/* @var \Magento\SalesRule\Api\Data\DiscountDataInterface $discountData */
$discountData = $value->getDiscountData();
$discount['applied_to'] = $discountData->getAppliedTo();
$amount['value'] = $discountData->getAmount();
$amount['currency'] = $quote->getQuoteCurrencyCode();
$discount['amount'] = $amount;
$discountValues[] = $discount;
}
return $discountValues;
}
return null;
return $discountValues ?: null;
}
}
8 changes: 7 additions & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,17 @@ enum CartItemErrorType {
ITEM_INCREMENTS
}

type Discount @doc(description:"Defines an individual discount. A discount can be applied to the cart as a whole or to an item.") {
type Discount @doc(description:"Defines an individual discount. A discount can be applied to the cart as a whole or to an item, shipping.") {
amount: Money! @doc(description:"The amount of the discount.")
applied_to: CartDiscountType! @doc(description:"The type of the entity the discount is applied to.")
label: String! @doc(description:"A description of the discount.")
}

enum CartDiscountType {
ITEM
SHIPPING
}

type CartItemPrices @doc(description: "Contains details about the price of the item, including taxes and discounts.") {
price: Money! @doc(description: "The price of the item before any discounts were applied. The price that might include tax, depending on the configured display settings for cart.")
price_including_tax: Money! @doc(description: "The price of the item before any discounts were applied. The price that might include tax, depending on the configured display settings for cart.")
Expand Down
Loading

0 comments on commit 6e4f533

Please sign in to comment.