Background
I've built a custom shipping method. It follows almost an identical pattern to the magento shipping method classes. It works as expected. Then I added a plugin to check if a coupon code was entered the field would appear. This works as well.
The Issue
I want to attach the coupon name to the shipping method title. So instead of saying "Event Pickup FREE" it says "EVENT LOCATION - Event Pickup - FREE". Making an afterCollectRates
function I would assume I would need to alter the $result
variable.
I can't seem to figure out how to:
Properly alter $result to override the data.
Debug or log $result to see the structure of the object. In hopes to alter it.
Shipping Method Function
public function collectRates(RateRequest $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
/** @var \Magento\Shipping\Model\Rate\Result $result */
$result = $this->_rateResultFactory->create();
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
$method = $this->_rateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name')); //<--This is what the plugin should change
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
return $result;
}
Plugin for Shipping Method
public function afterCollectRates(\Base\Model\Carrier\EventPickup $subject, $result)
{
if (!$this->checkCouponCode()) {
return false;
}
$couponCode = $this->_coupon->getCouponCode()
$this->_logger->debug($couponCode); //<--This works and shows up on log
return $result;
}
I've attempted to use the logger, debug, var_dump, echo, print_r, var_export and any other combinations. All seem to be no use. The result is usually the same, the magento loader spins forever and nothing regarding $result comes to the log. Thanks for the help!