/** * @param ShippingInterface $shipping * @param CartInterface $quote * @return void */ public function save(ShippingInterface $shipping, CartInterface $quote) { $this->shippingAddressManagement->assign($quote->getId(), $shipping->getAddress()); if (!empty($shipping->getMethod()) && $quote->getItemsCount() > 0) { $nameComponents = explode('_', $shipping->getMethod()); $carrierCode = array_shift($nameComponents); // carrier method code can contains more one name component $methodCode = implode('_', $nameComponents); $this->shippingMethodManagement->apply($quote->getId(), $carrierCode, $methodCode); } }
/** * {@inheritdoc} */ public function delete(\Magento\Quote\Api\Data\CartInterface $quote) { $quoteId = $quote->getId(); $customerId = $quote->getCustomerId(); $quote->delete(); unset($this->quotesById[$quoteId]); unset($this->quotesByCustomerId[$customerId]); }
/** * Delete partial payment registry data before quote deletion. * * @param $subject * @param \Magento\Quote\Api\Data\CartInterface $quote * @return array * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDelete($subject, \Magento\Quote\Api\Data\CartInterface $quote) { $quoteId = $quote->getId(); $this->_repoPartialQuote->deleteById($quoteId); return [$quote]; }
/** * Returns order id * * @return int */ public function getId() { return $this->quote->getId(); }
/** * Return customer code according to the admin configured format * * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $data * @return string */ protected function getCustomerCode($data) { switch ($this->config->getCustomerCodeFormat($data->getStoreId())) { case Config::CUSTOMER_FORMAT_OPTION_EMAIL: $email = $data->getCustomerEmail(); return $email ?: Config::CUSTOMER_MISSING_EMAIL; break; case Config::CUSTOMER_FORMAT_OPTION_NAME_ID: $customer = $this->getCustomerById($data->getCustomerId()); if ($customer && $customer->getId()) { $name = $customer->getFirstname() . ' ' . $customer->getLastname(); $id = $customer->getId(); } else { if (!$data->getIsVirtual()) { $address = $data->getShippingAddress(); } else { $address = $data->getBillingAddress(); } $name = $address->getFirstname() . ' ' . $address->getLastname(); if (!trim($name)) { $name = Config::CUSTOMER_MISSING_NAME; } $id = Config::CUSTOMER_GUEST_ID; } return sprintf(Config::CUSTOMER_FORMAT_NAME_ID, $name, $id); break; case Config::CUSTOMER_FORMAT_OPTION_ID: default: return $data->getCustomerId() ?: strtolower(Config::CUSTOMER_GUEST_ID) . '-' . $data->getId(); break; } }