|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / SendCloud / SendCloud / Observer / |
Filename | /home/dev2.destoffenstraat.com/app/code/SendCloud/SendCloud/Observer/SetMultishippingAttributes.php |
Size | 2.52 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 11-Feb-2023 11:04 |
Last accessed | 23-Aug-2025 07:53 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace SendCloud\SendCloud\Observer;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Serialize\Serializer\Json;
/**
* Class SetOrderAttributes
*/
class SetMultishippingAttributes implements ObserverInterface
{
/**
* @var Json
*/
private $serializer;
public function __construct(Json $serializer)
{
$this->serializer = $serializer;
}
/**
* @param Observer $observer
* @return $this
*/
public function execute(Observer $observer)
{
$request = $observer->getData('request');
$quote = $observer->getData('quote');
$shippingMethods = $request->getPost('shipping_method');
$shippingMethodsData = $request->getPost('sc_delivery_method_data');
$multishippingExtensionData = null;
if ($shippingMethods === null) {
return $this;
}
foreach ($shippingMethods as $key => $value) {
if (strpos($value, 'sendcloud_checkout') !== false) {
if (!$shippingMethodsData[$key]) {
throw new LocalizedException(__('Sendcloud checkout data missing'));
}
$shippingMethodData = $this->serializer->unserialize($shippingMethodsData[$key]);
$this->velidateData($shippingMethodData);
$multishippingExtensionData[$key] = $shippingMethodData;
}
}
$quote->setSendcloudMultishippingData($this->serializer->serialize($multishippingExtensionData));
return $this;
}
/**
* @param $shippingMethodData
* @return void
*/
private function velidateData($shippingMethodData): void
{
if ($shippingMethodData['delivery_method_type'] === 'nominated_day_delivery' &&
(!$shippingMethodData['delivery_method_data'] || !$shippingMethodData['delivery_method_data']['delivery_date'])
) {
throw new LocalizedException(__('Delivery day must be selected before order purchase. Please return to shipping and select delivery date.'));
}
if ($shippingMethodData['delivery_method_type'] === 'service_point_delivery' &&
(!$shippingMethodData['delivery_method_data'] || !$shippingMethodData['delivery_method_data']['service_point_id'])
) {
throw new LocalizedException(__('Service Point must be selected before order purchase. Please return to shipping and select service point.'));
}
}
}
namespace SendCloud\SendCloud\Observer;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Serialize\Serializer\Json;
/**
* Class SetOrderAttributes
*/
class SetMultishippingAttributes implements ObserverInterface
{
/**
* @var Json
*/
private $serializer;
public function __construct(Json $serializer)
{
$this->serializer = $serializer;
}
/**
* @param Observer $observer
* @return $this
*/
public function execute(Observer $observer)
{
$request = $observer->getData('request');
$quote = $observer->getData('quote');
$shippingMethods = $request->getPost('shipping_method');
$shippingMethodsData = $request->getPost('sc_delivery_method_data');
$multishippingExtensionData = null;
if ($shippingMethods === null) {
return $this;
}
foreach ($shippingMethods as $key => $value) {
if (strpos($value, 'sendcloud_checkout') !== false) {
if (!$shippingMethodsData[$key]) {
throw new LocalizedException(__('Sendcloud checkout data missing'));
}
$shippingMethodData = $this->serializer->unserialize($shippingMethodsData[$key]);
$this->velidateData($shippingMethodData);
$multishippingExtensionData[$key] = $shippingMethodData;
}
}
$quote->setSendcloudMultishippingData($this->serializer->serialize($multishippingExtensionData));
return $this;
}
/**
* @param $shippingMethodData
* @return void
*/
private function velidateData($shippingMethodData): void
{
if ($shippingMethodData['delivery_method_type'] === 'nominated_day_delivery' &&
(!$shippingMethodData['delivery_method_data'] || !$shippingMethodData['delivery_method_data']['delivery_date'])
) {
throw new LocalizedException(__('Delivery day must be selected before order purchase. Please return to shipping and select delivery date.'));
}
if ($shippingMethodData['delivery_method_type'] === 'service_point_delivery' &&
(!$shippingMethodData['delivery_method_data'] || !$shippingMethodData['delivery_method_data']['service_point_id'])
) {
throw new LocalizedException(__('Service Point must be selected before order purchase. Please return to shipping and select service point.'));
}
}
}