PHP code example of fixstacks / module-zero-checkout
1. Go to this page and download the library: Download fixstacks/module-zero-checkout library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class GiftWrapValidator implements \Zero\Checkout\Api\PlaceOrderValidatorInterface
{
public function validate(\Magento\Quote\Model\Quote $quote, array $request): void
{
if (!empty($request['acme_gift_wrap']) && $quote->getIsVirtual()) {
throw new \Magento\Framework\Exception\LocalizedException(__('Virtual items can\'t be gift-wrapped.'));
}
}
}
class SaveGiftWrap implements \Zero\Checkout\Api\AfterPlaceOrderInterface
{
public function execute(\Magento\Sales\Api\Data\OrderInterface $order, array $request): void
{
if (!empty($request['acme_gift_wrap'])) {
$order->addCommentToStatusHistory('Gift wrap requested.');
$this->orderRepository->save($order);
}
}
}