Helps reset the billing & shipping objects for guests

@see https://shopgate.atlassian.net/browse/MAGENTO-429

@param MageQuote $quote
15487
public function resetGuest(MageQuote $quote)
    {
        if ($this->sgBase->isGuest()) {
            $quote->getBillingAddress()->isObjectNew(false);
            $quote->getShippingAddress()->isObjectNew(false);
        }
    }
1327943
private function getCheckoutMethod(Quote $quote) {
        if ($this->customerSession->isLoggedIn()) {
            return Onepage::METHOD_CUSTOMER;
        }

        if (!$quote->getCheckoutMethod()) {
            if ($this->checkoutHelper->isAllowedGuestCheckout($quote)) {
                $quote->setCheckoutMethod(Onepage::METHOD_GUEST);
            } else {
                $quote->setCheckoutMethod(Onepage::METHOD_REGISTER);
            }
        }

        return $quote->getCheckoutMethod();
    }
678426
private function setPaymentMethod($quote)
    {
        $quote->setPaymentMethod(Payment::METHOD_CODE);
        // Set Sales Order Payment
        $quote->getPayment()->importData(['method' => Payment::METHOD_CODE])->save();
    }
555911
public function set($column, $value, $quote = true)
    {
        $value = str_replace("'", "''", $value);
        $this->sets[] = $quote ? " $column = '$value'" : " $column = $value";

        return $this;
    }
1307123
public function send($quote, $storeId)
    {
        $store = $this->storeManager->getStore($storeId);
        $client = $this->helper->getWebsiteApiClient($store->getWebsiteId());

        $payload = $this->getPayload($quote, $store);
        $client->postAbandonedCartCartInsight($payload);
    }
863400
private function setShippingMethod($quote, $transaction)
    {
        if ($quote->isVirtual()) {
            return;
        }

        $shippingAddress = $quote->getShippingAddress();
        $shippingAddress->setCollectShippingRates(true);

        $shippingMethod = $transaction->order->cart->shipments[0]->reference;

        $shippingAddress->setShippingMethod($shippingMethod)->save();
    }
1243436
public function cloneAmastyGiftCards($sourceQuoteId, $destinationQuoteId)
    {
        if (! $this->isAmastyGiftCardAvailable()) {
            return;
        }
        $connection = $this->resource->getConnection();
        $connection->beginTransaction();
        try {
            $giftCardTable = $this->resource->getTableName('amasty_amgiftcard_quote');

            // Clear previously applied gift cart codes from the immutable quote
            $sql = "DELETE FROM {$giftCardTable} WHERE quote_id = :destination_quote_id";
            $connection->query($sql, ['destination_quote_id' => $destinationQuoteId]);

            // Copy all gift cart codes applied to the parent quote to the immutable quote
            $sql = "INSERT INTO {$giftCardTable} (quote_id, code_id, account_id, base_gift_amount, code) 
                    SELECT :destination_quote_id, code_id, account_id, base_gift_amount, code
                    FROM {$giftCardTable} WHERE quote_id = :source_quote_id";
            $connection->query($sql, ['destination_quote_id' => $destinationQuoteId, 'source_quote_id' => $sourceQuoteId]);

            $connection->commit();
        } catch (\Zend_Db_Statement_Exception $e) {
            $connection->rollBack();
            $this->bugsnag->notifyException($e);
        }
    }
399264
public function putQuoteId($data)
    {
        if ($this->registry->registry(self::QUOTE_ID)) {
            $this->registry->unregister(self::QUOTE_ID);
        }
        $this->registry->register(self::QUOTE_ID, $data);
    }
297631
private function deleteRedundantQuotes($quote)
    {
        $connection = $this->resourceConnection->getConnection();

        // get table name with prefix
        $tableName = $this->resourceConnection->getTableName('quote');

        $sql = "DELETE FROM {$tableName} WHERE bolt_parent_quote_id = :bolt_parent_quote_id AND entity_id != :entity_id";
        $bind = [
            'bolt_parent_quote_id' => $quote->getBoltParentQuoteId(),
            'entity_id' => $quote->getBoltParentQuoteId()
        ];

        $connection->query($sql, $bind);
    }
224103
function quote($method = '') {
    global $order, $shipping_weight, $shipping_num_boxes, $total_count;

    // shipping adjustment
    switch (MODULE_SHIPPING_TABLE_MODE) {
      case ('price'):
        $order_total = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ;
        break;
      case ('weight'):
        $order_total = $shipping_weight;
        break;
      case ('item'):
        $order_total = $total_count - $_SESSION['cart']->free_shipping_items();
        break;
    }

    $order_total_amount = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ;

    $table_cost = preg_split("/[:,]/" , MODULE_SHIPPING_TABLE_COST);
    $size = sizeof($table_cost);
    for ($i=0, $n=$size; $i<$n; $i+=2) {
      if (round($order_total,9) <= $table_cost[$i]) {
        if (strstr($table_cost[$i+1], '%')) {
          $shipping = ($table_cost[$i+1]/100) * $order_total_amount;
        } else {
          $shipping = $table_cost[$i+1];
        }
        break;
      }
    }

    if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
      $shipping = $shipping * $shipping_num_boxes;
      // show boxes if weight
      switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
        case (0):
        $show_box_weight = '';
        break;
        case (1):
        $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
        break;
        case (2):
        $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')';
        break;
        default:
        $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
        break;
      }
    }

    $this->quotes = array('id' => $this->code,
    'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE . $show_box_weight,
    'methods' => array(array('id' => $this->code,
    'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
    'cost' => $shipping + (MODULE_SHIPPING_TABLE_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_TABLE_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_TABLE_HANDLING) ) ));

    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
1041171
public function getHydratedQuote(
        QuoteTransfer $quoteTransfer,
        PayonePaypalExpressCheckoutGenericPaymentResponseTransfer $details
    ) {
        $quoteTransfer = $this->hydrateQuoteWithPayment($quoteTransfer);
        $quoteTransfer = $this->hydrateQuoteWithShipment($quoteTransfer);
        $quoteTransfer = $this->hydrateQuoteWithAddresses($quoteTransfer, $details);
        if (!$this->customerClient->isLoggedIn()) {
            $quoteTransfer = $this->hydrateQuoteWithCustomer($quoteTransfer, $details);
            $quoteTransfer->setIsGuestExpressCheckout(true);
        }
        return $this->calculationClient->recalculate($quoteTransfer);
    }
865139
public function setEntity(MageQuote $quote)
    {
        $id    = $this->sgBase->getExternalCustomerId();
        $email = $this->sgBase->getMail();

        try {
            $customer = $id ? $this->customerHelper->getById($id) : $this->customerHelper->getByEmail($email);
        } catch (NoSuchEntityException $e) {
            $customer = new DataObject();
            $this->log->debug('Could not load customer by id or mail.');
        }
        $quote->setCustomerEmail($email)
            ->setRemoteIp($this->sgBase->getCustomerIp());
        if ($this->sgBase->isGuest()) {
            $quote->setCustomerIsGuest(true);
        } elseif ($customer->getId()) {
            $this->session->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());

            $quote->setCustomer($customer)
                ->setCustomerIsGuest(false);
        } else {
            throw new \ShopgateLibraryException(
                \ShopgateLibraryException::UNKNOWN_ERROR_CODE,
                __('Customer with external id "%1" or email "%2" does not exist', $id, $email)->render()
            );
        }
    }
544258
public function replicateQuoteData($source, $destination)
    {
        // Skip the replication if source and destination point to the same quote
        // E.g. delayed Save Order - immutable quote is cleared by cron and we use the parent instead
        if ($source->getId() == $destination->getId()) return;

        $destinationId = $destination->getId();
        $destinationActive = (bool)$destination->getIsActive();

        $destination->removeAllItems();

        $destination->merge($source);

        $destination->getBillingAddress()->setShouldIgnoreValidation(true);
        $this->transferData($source->getBillingAddress(), $destination->getBillingAddress());

        $destination->getShippingAddress()->setShouldIgnoreValidation(true);
        $this->transferData($source->getShippingAddress(), $destination->getShippingAddress());

        $this->transferData($source, $destination, false);

        $destination->setId($destinationId);
        $destination->setIsActive($destinationActive);

        $this->quoteResourceSave($destination);

        // If Amasty Gif Cart Extension is present clone applied gift cards
        $this->discountHelper->cloneAmastyGiftCards($source->getId(), $destination->getId());
    }
889347
protected function hydrateQuoteWithAddresses(
        QuoteTransfer $quoteTransfer,
        PayonePaypalExpressCheckoutGenericPaymentResponseTransfer $details
    ) {
        $address = new AddressTransfer();

        if ($this->customerClient->isLoggedIn()) {
            $address->setEmail($quoteTransfer->getCustomer()->getEmail());
        } else {
            $address->setEmail($details->getEmail());
        }

        $address->setFirstName($details->getShippingFirstName());
        $address->setLastName($details->getShippingLastName());
        $address->setCompany($details->getShippingCompany());
        $address->setAddress1($details->getShippingStreet());
        $address->setAddress2($details->getShippingAddressAdition());
        $address->setCity($details->getShippingCity());
        $address->setState($details->getShippingState());
        $address->setIso2Code($details->getShippingCountry());
        $address->setZipCode($details->getShippingZip());
        $quoteTransfer->setBillingAddress($address);
        $quoteTransfer->setShippingAddress($address);
        $quoteTransfer->setBillingSameAsShipping(true);

        return $quoteTransfer;
    }
737780
private function setBillingAddress($quote, $transaction)
    {
        $address = @$transaction->order->cart->billing_address;
        if ($address) {
            $this->setAddress($quote->getBillingAddress(), $address);
        }
    }
9714
public function setDiskQuote(int $diskQuote)
    {
        $this->diskQuote = $diskQuote;

        $this->hostConfig = array_merge($this->hostConfig, ['DiskQuota ' => $diskQuote]);

        return $this;
    }
331587
public function isAvailable($quote = null)
    {
        $isAvailable = parent::isAvailable($quote);
        // check if ip range is enabled
        $ipFilter = $this->_getConfigData('ip_filter', 'adyen_pos_cloud');

        if ($isAvailable && $ipFilter != 0) {
            $ip = Mage::helper('adyen')->getClientIp();
            switch ($ipFilter) {
                case '1':
                    // check if ip in in list
                    $_list = $this->_getConfigData('ip_filter_ips', 'adyen_pos_cloud');
                    $_list = str_replace(' ', '', $_list);
                    $_list = explode(',', $_list);
                    $isAvailable = in_array($ip, $_list);
                    break;
                case '2':
                default:
                    // check if ip is in range
                    $from = $this->_getConfigData('ip_filter_from', 'adyen_pos_cloud');
                    $to = $this->_getConfigData('ip_filter_to', 'adyen_pos_cloud');
                    $isAvailable = Mage::helper('adyen')->ipInRange($ip, $from, $to);
                    break;
            }
        }

        return $isAvailable;
    }