本文整理汇总了PHP中Mage_Sales_Model_Quote::getAllItems方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Quote::getAllItems方法的具体用法?PHP Mage_Sales_Model_Quote::getAllItems怎么用?PHP Mage_Sales_Model_Quote::getAllItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Quote
的用法示例。
在下文中一共展示了Mage_Sales_Model_Quote::getAllItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNewOrder
/**
* @param Mage_Sales_Model_Quote $quote
* @return Mage_Sales_Model_Order
* @throws Exception
*/
public function createNewOrder($quote)
{
$convert = Mage::getModel('sales/convert_quote');
if ($quote->isVirtual()) {
$this->setOrder($convert->addressToOrder($quote->getBillingAddress()));
} else {
$this->setOrder($convert->addressToOrder($quote->getShippingAddress()));
}
$this->getOrder()->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress()));
if ($quote->getBillingAddress()->getCustomerAddress()) {
$this->getOrder()->getBillingAddress()->setCustomerAddress($quote->getBillingAddress()->getCustomerAddress());
}
if (!$quote->isVirtual()) {
$this->getOrder()->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress()));
if ($quote->getShippingAddress()->getCustomerAddress()) {
$this->getOrder()->getShippingAddress()->setCustomerAddress($quote->getShippingAddress()->getCustomerAddress());
}
}
$this->getOrder()->setPayment($convert->paymentToOrderPayment($quote->getPayment()));
$this->getOrder()->getPayment()->setTransactionId($quote->getPayment()->getTransactionId());
foreach ($quote->getAllItems() as $item) {
/** @var Mage_Sales_Model_Order_Item $item */
$orderItem = $convert->itemToOrderItem($item);
if ($item->getParentItem()) {
$orderItem->setParentItem($this->getOrder()->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$this->getOrder()->addItem($orderItem);
}
$this->getOrder()->setQuote($quote);
$this->getOrder()->setExtOrderId($quote->getPayment()->getTransactionId());
$this->getOrder()->setCanSendNewEmailFlag(false);
$this->_initTransaction($quote);
return $this->getOrder();
}
示例2: _getItemByProduct
/**
* Get QuoteItem that matches Product.
*
* @param Mage_Sales_Model_Quote $quote
* @param Mage_Catalog_Model_Product $product
* @return Mage_Sales_Model_Quote_Item | NULL
*/
protected function _getItemByProduct(Mage_Sales_Model_Quote $quote, Mage_Catalog_Model_Product $product)
{
foreach ($quote->getAllItems() as $item) {
if ($item->getProduct()->getId() == $product->getId()) {
return $item;
}
}
return Mage::getModel("sales/quote_item")->setProduct($product)->setQuote($quote);
}
示例3: getInitAmount
protected function getInitAmount(Mage_Sales_Model_Quote $quote)
{
$initAmount = 0;
if ($quote->getSubscriptionPlan() != null) {
$initAmount = (double) $quote->getSubscriptionPlan()->getInitAmount();
} else {
foreach ($quote->getAllItems() as $item) {
$product = $item->getProduct();
$product->load($product->getId());
if ($item->isSubscription() && $product->getInitAmount()) {
$initAmount += $product->getInitAmount() * $item->getQty();
}
}
}
return $initAmount;
}
示例4: isQuoteAdyenSubscription
/**
* @param Mage_Sales_Model_Quote $quote
*
* @return mixed|Varien_Object
*/
public function isQuoteAdyenSubscription(Mage_Sales_Model_Quote $quote)
{
if (!$quote->hasData('_is_adyen_subscription')) {
foreach ($quote->getAllItems() as $quoteItem) {
/** @var Mage_Sales_Model_Quote_Item $quoteItem */
$additionalOptions = $quoteItem->getOptionByCode('additional_options');
if (!$additionalOptions) {
continue;
}
$options = unserialize($additionalOptions->getValue());
foreach ($options as $option) {
if ($option['code'] == 'adyen_subscription' && $option['option_value'] != 'none') {
$quote->setData('_is_adyen_subscription', true);
$quoteItem->setData('_adyen_subscription', $option['option_value']);
return $quote->getData('_is_adyen_subscription');
}
}
}
$quote->setData('_is_adyen_subscription', false);
}
return $quote->getData('_is_adyen_subscription');
}
示例5: _getQuoteItemIdByProductId
/**
* Gets Mage_Sales_Model_Quote_Item from Mage_Sales_Model_Quote by product id
*
* @param Mage_Sales_Model_Quote $quote
* @param $productId
* @return Mage_Sales_Model_Quote_Item|null
*/
private function _getQuoteItemIdByProductId($quote, $productId)
{
/** @var $quoteItems Mage_Sales_Model_Quote_Item[] */
$quoteItems = $quote->getAllItems();
foreach ($quoteItems as $quoteItem) {
if ($productId == $quoteItem->getProductId()) {
return $quoteItem;
}
}
return null;
}
示例6: checkQuoteInventory
/**
* Check the inventory status of each item in the quote. Will add errors
* to the quote and items if any are not currently available at the
* requested quantity. Will throw an exception if any item not yet added
* to the quote should be prevented from being added.
*
* @param Mage_Sales_Model_Quote
* @return self
* @throws EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception If any items should not be added to the quote.
*/
public function checkQuoteInventory(Mage_Sales_Model_Quote $quote)
{
$inventoryItems = $this->_inventoryItemSelection->selectFrom($quote->getAllItems());
if (empty($inventoryItems)) {
$this->_logger->debug('no items to check, clearing collected quantities', $this->_logContext->getMetaData(__CLASS__));
$this->_quantityCollector->clearResults();
}
foreach ($inventoryItems as $item) {
if (!$this->isItemAvailable($item)) {
$this->_handleUnavailableItem($item);
} else {
$this->_notifyCustomerIfItemBackorderable($item);
}
}
return $this;
}
示例7: processLineItems
/**
* recursively process line items into payloads
*
* @param Mage_Sales_Model_Quote
* @param ILineItemIterable
* @param string
* @return self
*/
protected function processLineItems(Mage_Sales_Model_Quote $quote, ILineItemIterable $lineItems)
{
$items = $this->selectionHelper->selectFrom($quote->getAllItems());
foreach ($items as $item) {
$this->createLineItem($item, $lineItems, $quote->getQuoteCurrencyCode());
}
return $this;
}
示例8: updateItemCatalogPoints
/**
* Updates this quotes' item catalog points.
* @param TBT_Rewards_Model_Sales_Quote|Mage_Sales_Model_Quote $quote = null
* @return TBT_Rewards_Model_Sales_Quote
*
*/
public function updateItemCatalogPoints($quote = null)
{
if ($quote == null) {
$quote =& $this;
}
$quote_items = $quote->getAllItems();
foreach ($quote_items as &$item) {
if (!$item->getId()) {
continue;
}
if ($item->getParentItem()) {
continue;
}
$earned_point_totals = $this->_calculateItemCatalogEarnings($item, $quote);
$item->setEarnedPointsHash(Mage::helper('rewards')->hashIt($earned_point_totals));
}
return $quote;
}
示例9: _initPermissionsOnQuoteItems
/**
* Initialize permissions for quote items
*
* @param Mage_Sales_Model_Quote $quote
* @return Enterprise_CatalogPermissions_Model_Observer
*/
protected function _initPermissionsOnQuoteItems($quote)
{
$productIds = array();
foreach ($quote->getAllItems() as $item) {
if (!isset($this->_permissionsQuoteCache[$item->getProductId()]) && $item->getProductId()) {
$productIds[] = $item->getProductId();
}
}
if (!empty($productIds)) {
$this->_permissionsQuoteCache += $this->_getIndexModel()->getIndexForProduct($productIds, $this->_getCustomerGroupId(), $quote->getStoreId());
foreach ($productIds as $productId) {
if (!isset($this->_permissionsQuoteCache[$productId])) {
$this->_permissionsQuoteCache[$productId] = false;
}
}
}
$defaultGrants = array('grant_catalog_category_view' => $this->_helper->isAllowedCategoryView(), 'grant_catalog_product_price' => $this->_helper->isAllowedProductPrice(), 'grant_checkout_items' => $this->_helper->isAllowedCheckoutItems());
foreach ($quote->getAllItems() as $item) {
if ($item->getProductId()) {
$permission = $this->_permissionsQuoteCache[$item->getProductId()];
if (!$permission && in_array(false, $defaultGrants)) {
// If no permission found, and no one of default grant is disallowed
$item->setDisableAddToCart(true);
continue;
}
foreach ($defaultGrants as $grant => $defaultPermission) {
if ($permission[$grant] == -2 || $permission[$grant] != -1 && !$defaultPermission) {
$item->setDisableAddToCart(true);
break;
}
}
}
}
return $this;
}
示例10: checkQuoteInventory
/**
* Check the inventory status of each item in the quote. Will add errors
* to the quote and items if any are not currently available at the
* requested quantity. Will throw an exception if any item not yet added
* to the quote should be prevented from being added.
*
* @param Mage_Sales_Model_Quote
* @return self
* @throws EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception If any items should not be added to the quote.
*/
public function checkQuoteInventory(Mage_Sales_Model_Quote $quote)
{
$inventoryItems = $this->_inventoryItemSelection->selectFrom($quote->getAllItems());
if (empty($inventoryItems)) {
$this->_quantityCollector->clearResults();
}
foreach ($inventoryItems as $item) {
if (!$this->isItemAvailable($item)) {
$this->_handleUnavailableItem($item);
} else {
$this->_notifyCustomerIfItemBackorderable($item);
}
}
return $this;
}
示例11: getShoppingCartPoints
/**
* calculate earning point for order quote
*
* @param Mage_Sales_Model_Quote $quote
* @param int $customerGroupId
* @param int $websiteId
* @param string $date
* @return int
*/
public function getShoppingCartPoints($quote, $customerGroupId = null, $websiteId = null, $date = null)
{
if ($quote->isVirtual()) {
$address = $quote->getBillingAddress();
} else {
$address = $quote->getShippingAddress();
}
//webpos
$customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
if ($customerId) {
$customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
} else {
$customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
}
if (is_null($websiteId)) {
$websiteId = Mage::app()->getStore($quote->getStoreId())->getWebsiteId();
}
if (is_null($date)) {
$date = date('Y-m-d', strtotime($quote->getCreatedAt()));
}
$points = 0;
$rules = Mage::getResourceModel('rewardpointsrule/earning_sales_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
$items = $quote->getAllItems();
$this->setStoreId($quote->getStoreId());
foreach ($rules as $rule) {
$rule->afterLoad();
if (!$rule->validate($address)) {
continue;
}
$rowTotal = 0;
$qtyTotal = 0;
foreach ($items as $item) {
if ($item->getParentItemId()) {
continue;
}
if ($rule->getActions()->validate($item)) {
$rowTotal += max(0, $item->getBaseRowTotal() - $item->getBaseDiscountAmount() - $item->getRewardpointsBaseDiscount());
$qtyTotal += $item->getQty();
}
}
if (!$qtyTotal) {
continue;
}
if (Mage::getStoreConfigFlag(self::XML_PATH_EARNING_BY_SHIPPING, $quote->getStoreId())) {
$rowTotal += $address->getBaseShippingAmount();
}
$points += $this->calcSalesPoints($rule->getSimpleAction(), $rule->getPointsEarned(), $rule->getMoneyStep(), $rowTotal, $rule->getQtyStep(), $qtyTotal, $rule->getMaxPointsEarned());
if ($points && $rule->getStopRulesProcessing()) {
break;
}
}
return $points;
}
示例12: getCrosssellProducts
/**
* @param Mage_Sales_Model_Quote $quote
* @param bool $applyCollectionModifiers
*
* @return Mage_Catalog_Model_Product[]
*/
protected function getCrosssellProducts(Mage_Sales_Model_Quote $quote, $applyCollectionModifiers = true)
{
$cartProductIds = [];
foreach ($quote->getAllItems() as $item) {
/** @var Mage_Sales_Model_Quote_Item $item */
if ($product = $item->getProduct()) {
$cartProductIds[] = intval($product->getId());
}
}
if ($cartProductIds) {
/** @var Mage_Catalog_Model_Resource_Product_Link_Product_Collection $collection */
$collection = Mage::getModel('catalog/product_link')->useCrossSellLinks()->getProductCollection();
$collection->setStoreId($quote->getStoreId());
$collection->addStoreFilter();
//$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
$collection->addAttributeToSelect('*');
$collection->addUrlRewrite();
$collection->addAttributeToFilter('status', ['eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED]);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
$collection->applyFrontendPriceLimitations();
$collection->addProductFilter($cartProductIds);
$collection->addExcludeProductFilter($cartProductIds);
$collection->setGroupBy();
$collection->setPositionOrder();
if ($applyCollectionModifiers) {
$this->_applyCollectionModifiers($collection);
}
/** @var Mage_CatalogInventory_Model_Stock $stock */
$stock = Mage::getModel('cataloginventory/stock');
$stock->addItemsToProducts($collection);
return $collection->getItems();
} else {
return [];
}
}
示例13: getArticles
/**
* Article preparations for PAYMENT_REQUEST, PAYMENT_CHANGE, CONFIRMATION_DELIVER
*
* @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
* @return array
*/
public function getArticles($object)
{
$articles = array();
$articleDiscountAmount = 0;
$objectItems = $object->getAllItems();
foreach ($objectItems as $item) {
if ($item instanceof Mage_Sales_Model_Order_Item || $item instanceof Mage_Sales_Model_Quote_Item) {
$orderItem = $item;
} else {
$orderItem = Mage::getModel('sales/order_item')->load($item->getOrderItemId());
}
$shopProduct = Mage::getModel('catalog/product')->load($orderItem->getProductId());
if (($orderItem->getProductType() !== 'bundle' || $orderItem->getProductType() === 'bundle' && $shopProduct->getPrice() > 0) && $orderItem->getRowTotal() > 0) {
$article = array();
$article['articleNumber'] = $item->getSku();
$article['articleName'] = $item->getName();
$article['quantity'] = $object instanceof Mage_Sales_Model_Order ? $item->getQtyOrdered() : $item->getQty();
$article['unitPriceGross'] = $item->getPriceInclTax();
$article['taxPercent'] = $orderItem->getTaxPercent();
$article['discountId'] = '';
if ($item->getDiscountAmount() > 0) {
$discount = array();
$discount['articleNumber'] = 'DISCOUNT-' . $item->getSku();
$discount['articleName'] = 'DISCOUNT - ' . $item->getName();
$discount['quantity'] = $article['quantity'];
$discount['unitPriceGross'] = -1 * $item->getDiscountAmount() / $article['quantity'];
$discount['discountId'] = $item->getSku();
$articleDiscountAmount = $articleDiscountAmount + $item->getDiscountAmount();
}
$articles[] = $article;
if ($item->getDiscountAmount() > 0) {
// only for sort reason
$articles[] = $discount;
}
}
}
if ($object->getGwPrice() > 0) {
$article = array();
$article['articleNumber'] = 'orderwrapping';
$article['articleName'] = 'Wrapping Cost Order';
$article['quantity'] = '1';
$article['unitPriceGross'] = $object->getGwPrice();
$article['taxPercent'] = 100 / $object->getGwPrice() * $object->getGwTaxAmount();
$article['discountId'] = '';
$articles[] = $article;
}
if ($object->getGwItemsPrice() > 0) {
$article = array();
$article['articleNumber'] = 'itemswrapping';
$article['articleName'] = 'Wrapping Cost Items';
$article['quantity'] = '1';
$article['unitPriceGross'] = $object->getGwItemsPrice();
$article['taxPercent'] = 100 / $object->getGwItemsPrice() * $object->getGwItemsTaxAmount();
$article['discountId'] = '';
$articles[] = $article;
}
if ($object->getGwAddCard() > 0) {
$article = array();
$article['articleNumber'] = 'printed_card';
$article['articleName'] = 'Printed Card';
$article['quantity'] = '1';
$article['unitPriceGross'] = $object->getGwCardPrice();
$article['taxPercent'] = 100 / $object->getGwCardPrice() * $object->getGwCardTaxAmount();
$article['discountId'] = '';
$articles[] = $article;
}
if (Mage::getEdition() == 'Enterprise') {
$_cards = Mage::getBlockSingleton('enterprise_giftcardaccount/checkout_cart_total')->getQuoteGiftCards();
if ($_cards) {
foreach ($_cards as $card) {
$article = array();
$article['articleNumber'] = 'gift_card';
$article['articleName'] = $card['c'];
$article['quantity'] = '1';
$article['unitPriceGross'] = -round($card['ba'], 2);
$article['taxPercent'] = 0;
$article['discountId'] = '';
$articles[] = $article;
}
}
}
if ($object instanceof Mage_Sales_Model_Order || $object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
$shippingObject = $object;
if ($object instanceof Mage_Sales_Model_Order_Creditmemo) {
$articles = $this->addAdjustments($object, $articles);
}
} else {
$shippingObject = $object->getShippingAddress();
}
if ($shippingObject->getShippingAmount() > 0) {
if ($object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Shipment || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
$shippingDiscountAmount = $shippingObject->getDiscountAmount() - $articleDiscountAmount;
$shippingDescription = $object->getOrder()->getShippingDescription();
} else {
//.........这里部分代码省略.........
示例14: _processOrder
/**
* Place the order
*
* @return bool
*/
protected function _processOrder()
{
if (!$this->_auth()) {
return false;
}
if (!$this->_validateQuote()) {
return false;
}
// Push address to the quote, set totals,
// Convert quote to the order,
// Set rakuten_order attribute to "1"
try {
// To avoid duplicates look for order with the same Rakuten order no
$orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('ext_order_id', (string) $this->_request->order_no);
if (count($orders)) {
$this->_debugData['reason'] = 'The same order already placed';
return false;
}
// Import addresses and other data to quote
$this->_quote->setIsActive(true)->reserveOrderId();
$storeId = $this->_quote->getStoreId();
Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
if ($this->_quote->getQuoteCurrencyCode() != $this->_quote->getBaseCurrencyCode()) {
Mage::app()->getStore()->setCurrentCurrencyCode($this->_quote->getQuoteCurrencyCode());
}
$billing = $this->_convertAddress('client');
$this->_quote->setBillingAddress($billing);
$shipping = $this->_convertAddress('delivery_address');
$this->_quote->setShippingAddress($shipping);
$this->_convertTotals($this->_quote->getShippingAddress());
$this->_quote->getPayment()->importData(array('method' => 'rakuten'));
/**
* Convert quote to order
*
* @var $convertQuote Mage_Sales_Model_Convert_Quote
*/
$convertQuote = Mage::getSingleton('sales/convert_quote');
/* @var $order Mage_Sales_Model_Order */
$order = $convertQuote->toOrder($this->_quote);
if ($this->_quote->isVirtual()) {
$convertQuote->addressToOrder($this->_quote->getBillingAddress(), $order);
} else {
$convertQuote->addressToOrder($this->_quote->getShippingAddress(), $order);
}
$order->setExtOrderId((string) $this->_request->order_no);
$order->setExtCustomerId((string) $this->_request->client->client_id);
if (!$order->getCustomerEmail()) {
$order->setCustomerEmail($billing->getEmail())->setCustomerPrefix($billing->getPrefix())->setCustomerFirstname($billing->getFirstname())->setCustomerMiddlename($billing->getMiddlename())->setCustomerLastname($billing->getLastname())->setCustomerSuffix($billing->getSuffix())->setCustomerIsGuest(1);
}
$order->setBillingAddress($convertQuote->addressToOrderAddress($this->_quote->getBillingAddress()));
if (!$this->_quote->isVirtual()) {
$order->setShippingAddress($convertQuote->addressToOrderAddress($this->_quote->getShippingAddress()));
}
/** @var $item Mage_Sales_Model_Quote_Item */
foreach ($this->_quote->getAllItems() as $item) {
$orderItem = $convertQuote->itemToOrderItem($item);
if ($item->getParentItem()) {
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$order->addItem($orderItem);
}
/**
* Adding transaction for correct transaction information displaying on the order view in the admin.
* It has no influence on the API interaction logic.
*
* @var $payment Mage_Sales_Model_Order_Payment
*/
$payment = Mage::getModel('sales/order_payment');
$payment->setMethod('rakuten')->setTransactionId((string) $this->_request->order_no)->setIsTransactionClosed(false);
$order->setPayment($payment);
$payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
$order->setCanShipPartiallyItem(false);
$message = '';
if (trim((string) $this->_request->comment_client) != '') {
$message .= $this->__('Customer\'s Comment: %s', '<strong>' . trim((string) $this->_request->comment_client) . '</strong><br />');
}
$message .= $this->__('Rakuten Order No: %s', '<strong>' . (string) $this->_request->order_no . '</strong><br />') . $this->__('Rakuten Client ID: %s', '<strong>' . (string) $this->_request->client->client_id . '</strong><br />');
$order->addStatusHistoryComment($message);
$order->setRakutenOrder(1);
// Custom attribute for fast filtering of orders placed via Rakuten Checkout
$order->place();
$order->save();
// $order->sendNewOrderEmail();
$this->_quote->setIsActive(false)->save();
Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
} catch (Exception $e) {
$this->_debugData['exception'] = $e->getMessage();
Mage::logException($e);
return false;
}
return true;
}
示例15: createOrder
/**
* @param Mage_Sales_Model_Quote $quote
* @param Adyen_Subscription_Model_Subscription $subscription
*
* @return Mage_Sales_Model_Order
* @throws Adyen_Subscription_Exception|Exception
*/
public function createOrder(Mage_Sales_Model_Quote $quote, Adyen_Subscription_Model_Subscription $subscription)
{
Mage::dispatchEvent('adyen_subscription_quote_createorder_before', array('subscription' => $subscription, 'quote' => $quote));
try {
if (!$subscription->canCreateOrder()) {
Mage::helper('adyen_subscription')->logOrderCron("Not allowed to create order from quote");
Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__('Not allowed to create order from quote'));
}
foreach ($quote->getAllItems() as $item) {
/** @var Mage_Sales_Model_Quote_Item $item */
$item->getProduct()->setData('is_created_from_subscription_item', $item->getData('subscription_item_id'));
}
$quote->collectTotals();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
// Save order addresses at subscription when they're currently quote addresses
$subscriptionBillingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_BILLING);
if ($subscriptionBillingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
$subscriptionBillingAddress->initAddress($subscription, $order->getBillingAddress())->save();
}
$subscriptionShippingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_SHIPPING);
if ($subscriptionShippingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
$subscriptionShippingAddress->initAddress($subscription, $order->getShippingAddress())->save();
}
$orderAdditional = $subscription->getOrderAdditional($order, true)->save();
$quoteAdditional = $subscription->getActiveQuoteAdditional()->setOrder($order)->save();
$subscription->setErrorMessage(null);
$subscriptionHistory = null;
//Save history
if ($subscription->getStatus() == $subscription::STATUS_ORDER_ERROR || $subscription->getStatus() == $subscription::STATUS_PAYMENT_ERROR) {
$subscription->setStatus($subscription::STATUS_ACTIVE);
$subscriptionHistory = Mage::getModel('adyen_subscription/subscription_history');
$subscriptionHistory->createHistoryFromSubscription($subscription);
}
$subscription->setScheduledAt($subscription->calculateNextScheduleDate());
$transaction = Mage::getModel('core/resource_transaction');
$transaction->addObject($subscription)->addObject($orderAdditional)->addObject($quoteAdditional)->addObject($order);
if ($subscriptionHistory) {
$transaction->addObject($subscriptionHistory);
}
$transaction->save();
Mage::helper('adyen_subscription')->logOrderCron(sprintf("Successful created order (#%s) for subscription (#%s)", $order->getId(), $subscription->getId()));
$order = $service->getOrder();
Mage::dispatchEvent('adyen_subscription_quote_createorder_after', array('subscription' => $subscription, 'quote' => $quote, 'order' => $order));
return $order;
} catch (Mage_Payment_Exception $e) {
Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
if (isset($order)) {
$order->delete();
}
$subscription->setStatus($subscription::STATUS_PAYMENT_ERROR);
$subscription->setErrorMessage($e->getMessage());
$subscription->save();
Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription::STATUS_PAYMENT_ERROR, 'error' => $e->getMessage()));
throw $e;
} catch (Exception $e) {
Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
if (isset($order)) {
$order->delete();
}
$subscription->setStatus($subscription::STATUS_ORDER_ERROR);
$subscription->setErrorMessage($e->getMessage());
$subscription->save();
Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription->getStatus(), 'error' => $e->getMessage()));
throw $e;
}
}