CartCanonicalResource.php in Commerce Cart API 8
File
src/Plugin/rest/resource/CartCanonicalResource.php
View source
<?php
namespace Drupal\commerce_cart_api\Plugin\rest\resource;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\rest\ResourceResponse;
class CartCanonicalResource extends CartResourceBase {
public function get(OrderInterface $commerce_order) {
$response = new ResourceResponse($commerce_order);
$response
->addCacheableDependency($commerce_order);
return $response;
}
protected function getBaseRoute($canonical_path, $method) {
$route = parent::getBaseRoute($canonical_path, $method);
$parameters = $route
->getOption('parameters') ?: [];
$parameters['commerce_order']['type'] = 'entity:commerce_order';
$route
->setOption('parameters', $parameters);
return $route;
}
}