/** * Update stock data of multiple products at once * * @param array $itemData * @return array */ public function inventoryPush($itemData) { if (isset($itemData['records'])) { $itemData = $itemData['records']; } $response = array(); $response['records'] = array(); $orderItemsCollection = Mage::getResourceModel('retailops_api/api')->getRetailopsReadyOrderItems(); $orderItems = $this->filterOrderItems($orderItemsCollection); $productIds = $this->getProductIds($itemData); foreach ($itemData as $item) { try { $itemObj = new Varien_Object($item); Mage::dispatchEvent('retailops_inventory_push_record', array('record' => $itemObj)); $result = array(); $result['sku'] = $itemObj->getSku(); $itemObj->setQty($itemObj->getQuantity()); // api update accepts qty not quantity parameter $qty = $itemObj->getQty(); if (isset($orderItems[$itemObj->getSku()])) { $qty = $itemObj->getQty() - $orderItems[$itemObj->getSku()]; } $itemObj->setQty($qty); Mage::dispatchEvent('retailops_inventory_push_record_qty_processed', array('record' => $itemObj)); $this->update($productIds[$itemObj->getSku()], $itemObj->getData()); $result['status'] = RetailOps_Api_Helper_Data::API_STATUS_SUCCESS; } catch (Mage_Core_Exception $e) { $result['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $result['error'] = array('code' => $e->getCode(), 'message' => $e->getMessage()); } $response['records'][] = $result; } return $response; }
protected function _beforeSave(Varien_Object $object) { if (!$object->getId() && $object->getSku()) { $object->setId($this->getIdBySku($object->getSku())); } if (is_array($object->getData('category_ids'))) { $object->setData('category_ids', implode(',', $object->getData('category_ids'))); } return parent::_beforeSave($object); }
public function validate(Varien_Object $object) { // for optimization if we no conditions if (!$this->getConditions()) { return true; } $origProduct = null; if ($object->getHasChildren() && $object->getProductType() == 'configurable') { //remember original product $origProduct = $object->getProduct(); $origSku = $object->getSku(); foreach ($object->getChildren() as $child) { // only one itereation. $categoryIds = array_merge($child->getProduct()->getCategoryIds(), $origProduct->getCategoryIds()); $categoryIds = array_unique($categoryIds); $object->setProduct($child->getProduct()); $object->setSku($child->getSku()); $object->getProduct()->setCategoryIds($categoryIds); } } $result = @Mage_Rule_Model_Condition_Combine::validate($object); if ($origProduct) { // restore original product $object->setProduct($origProduct); $object->setSku($origSku); } return $result; }
public function validate(Varien_Object $object) { $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal())->setQuoteItemSku($object->getSku()); return parent::validate($product); }
/** * Validate Product Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemSku($object->getSku()); //$newObject = new Varien_Object(); $object->setProduct($product); return parent::validate($object); }
protected function _beforeSave(Varien_Object $object) { if ($object->hasCategoryIds()) { $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds($object->getCategoryIds()); $object->setCategoryIds($categoryIds); } if (!$object->getSku() && Mage::getStoreConfigFlag('udprod/general/auto_sku')) { $adapter = $this->_getReadAdapter(); $pidSuffix = $adapter->fetchOne($adapter->select()->from($this->getEntityTable(), 'max(entity_id)')); do { $object->setSku($object->getUdropshipVendor() . '-' . ++$pidSuffix); } while (Mage::helper('udropship/catalog')->getPidBySku($object->getSku(), $object->getId())); } $vId = Mage::getSingleton('udropship/session')->getVendorId(); if (!$vId && Mage::app()->getStore()->isAdmin() && Mage::helper('udropship')->isModuleActive('umicrosite') && ($v = Mage::helper('umicrosite')->getAdminhtmlVendor())) { $vId = $v->getId(); } else { $vId = $object->getData('udropship_vendor'); } if (Mage::getStoreConfigFlag('udprod/general/prefix_sku_vid') && $vId && 0 !== strpos($object->getSku(), $vId . '-')) { $object->setSku($vId . '-' . $object->getSku()); } if (Mage::getStoreConfigFlag('udprod/general/unique_vendor_sku') && $vId && !Mage::helper('udropship')->isUdmultiActive()) { $vSkuAttr = Mage::getStoreConfig('udropship/vendor/vendor_sku_attribute'); if ($vSkuAttr && $vSkuAttr != 'sku') { if (!$object->getData($vSkuAttr)) { Mage::throwException('Vendor SKU attribute is empty'); } elseif (Mage::helper('udropship/catalog')->getPidByVendorSku($object->getData($vSkuAttr), $vId, $object->getId())) { Mage::throwException(Mage::helper('udropship')->__('Vendor SKU "%s" is already used', $object->getData($vSkuAttr))); } } } if (Mage::helper('udropship')->hasMageFeature('resource_1.6')) { return Mage_Catalog_Model_Resource_Abstract::_beforeSave($object); } else { return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract::_beforeSave($object); } }
public function validate(Varien_Object $object) { if ($this->getAttribute() == 'sku') { $sku = explode(',', $this->getValue()); foreach ($sku as $skuA) { foreach ($object->getSku() as $skuB) { if ($skuA == $skuB) { return true; } } } return false; } if ($this->getAttribute() == 'category') { return $this->validateAttribute($object->getCategories()); } return parent::validate($object); }
/** * Validate Product Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { /** @var Mage_Catalog_Model_Product $product */ $product = $object->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); // Allows attributes to take custom option SKU into consideration if ($this->getAttribute() === self::QUOTE_ITEM_SKU) { $product->setData($this->getAttribute(), $object->getSku()); $valid = Mage_Rule_Model_Condition_Product_Abstract::validate($product); } else { $valid = parent::validate($object); } if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $children = $object->getChildren(); $valid = $children && $this->validate($children[0]); } return $valid; }
/** * Prepare collection of errors * * @return Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Grid */ protected function _prepareCollection() { $collection = new Varien_Data_Collection(); $removeButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button', '', array('class' => 'delete', 'label' => '', 'onclick' => 'addBySku.removeFailedItem(this)', 'type' => 'button'))->toHtml(); /* @var $parentBlock Enterprise_Checkout_Block_Adminhtml_Sku_Errors_Abstract */ $parentBlock = $this->getParentBlock(); foreach ($parentBlock->getFailedItems() as $affectedItem) { // Escape user-submitted input if (isset($affectedItem['item']['qty'])) { $affectedItem['item']['qty'] = empty($affectedItem['item']['qty']) ? '' : (double) $affectedItem['item']['qty']; } $item = new Varien_Object(); $item->setCode($affectedItem['code']); if (isset($affectedItem['error'])) { $item->setError($affectedItem['error']); } $item->addData($affectedItem['item']); $item->setId($item->getSku()); /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); if (isset($affectedItem['item']['id'])) { $productId = $affectedItem['item']['id']; $item->setProductId($productId); $product->load($productId); /* @var $stockStatus Mage_CatalogInventory_Model_Stock_Status */ $stockStatus = Mage::getModel('cataloginventory/stock_status'); $status = $stockStatus->getProductStatus($productId, $this->getWebsiteId()); if (!empty($status[$productId])) { $product->setIsSalable($status[$productId]); } $item->setPrice(Mage::helper('core')->formatPrice($product->getPrice())); } $descriptionBlock = $this->getLayout()->createBlock('enterprise_checkout/adminhtml_sku_errors_grid_description', '', array('product' => $product, 'item' => $item)); $item->setDescription($descriptionBlock->toHtml()); $item->setRemoveButton($removeButtonHtml); $collection->addItem($item); } $this->setCollection($collection); return $this; }
/** * Validate Product Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } if (Mage::getStoreConfig('amrules/general/options_values')) { $options = $product->getTypeInstance(true)->getOrderOptions($product); $values = ''; if (isset($options['options'])) { foreach ($options['options'] as $option) { $values .= '|' . $option['value']; } } $product->setQuoteItemValue($values); } $product->setQuoteItemSku($object->getSku()); $object->setProduct($product); return parent::validate($object); }
/** * Process product data before save * * @param Varien_Object $object * @return Mage_Catalog_Model_Resource_Product */ protected function _beforeSave(Varien_Object $object) { /** * Try detect product id by sku if id is not declared */ if (!$object->getId() && $object->getSku()) { $object->setId($this->getIdBySku($object->getSku())); } /** * Check if declared category ids in object data. */ if ($object->hasCategoryIds()) { $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds($object->getCategoryIds()); $object->setCategoryIds($categoryIds); } return parent::_beforeSave($object); }
/** * Add a usual line item with amount and qty * * @param Varien_Object $salesItem * @return Varien_Object */ protected function _addRegularItem(Varien_Object $salesItem) { if ($this->_salesEntity instanceof Mage_Sales_Model_Order) { $qty = (int) $salesItem->getQtyOrdered(); $amount = (double) $salesItem->getBasePrice(); // TODO: nominal item for order } else { $qty = (int) $salesItem->getTotalQty(); $amount = $salesItem->isNominal() ? 0 : (double) $salesItem->getBaseCalculationPrice(); } // workaround in case if item subtotal precision is not compatible with PayPal (.2) $subAggregatedLabel = ''; if ($amount - round($amount, 2)) { $amount = $amount * $qty; $subAggregatedLabel = ' x' . $qty; $qty = 1; } // aggregate item price if item qty * price does not match row total if ($amount * $qty != $salesItem->getBaseRowTotal()) { $amount = (double) $salesItem->getBaseRowTotal(); $subAggregatedLabel = ' x' . $qty; $qty = 1; } return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku()); }
/** * Get the item id for an item based on the item's sku, client id * and catalog id. * @param Varien_Object $item * @return string */ protected function _getItemId(Varien_Object $item) { return $this->_formatId($item->getSku(), $item->getClientId(), $item->getCatalogId()); }
public function getOptionValues() { $data = array(); $optionsArr = ''; $session = Mage::getSingleton('adminhtml/session'); if ($data = $session->getData('customoptions_data')) { if (isset($data['general']['hash_options'])) { $optionsArr = $data['general']['hash_options']; } } elseif (Mage::registry('customoptions_data')) { $data = Mage::registry('customoptions_data')->getData(); if (isset($data['hash_options'])) { $optionsArr = $data['hash_options']; } } $groupId = (int) $this->getRequest()->getParam('group_id'); if ($optionsArr) { $optionsArr = unserialize($optionsArr); } $storeOptionsArr = array(); $groupStore = Mage::getSingleton('customoptions/group_store')->loadByGroupAndStore($groupId, $this->getStoreId()); if ($groupStore->getHashOptions()) { $storeOptionsArr = unserialize($groupStore->getHashOptions()); } $product = Mage::getSingleton('catalog/product_option'); if (!$this->_values && $optionsArr) { $values = array(); $sortOrder = array(); $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); $optionItemCount = count($optionsArr); foreach ($optionsArr as $optionId => $option) { $option = new Varien_Object($option); $value = array(); if ($option->getIsDelete() != '1') { $value['id'] = $option->getOptionId(); $value['item_count'] = $optionItemCount; $value['option_id'] = $option->getOptionId(); $value['title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['title']) ? $storeOptionsArr[$optionId]['title'] : $option->getTitle()); $value['type'] = $option->getType(); $value['is_require'] = $option->getIsRequire(); $value['is_enabled'] = $option->getIsEnabled(); $value['is_dependent'] = $option->getIsDependent(); $value['code'] = $this->htmlEscape($option->getCode()); $value['option_code'] = $option->getOptionCode(); $value['customoptions_is_onetime'] = $option->getCustomoptionsIsOnetime(); $value['qnty_input'] = $option->getQntyInput() ? 'checked' : ''; $value['qnty_input_disabled'] = $option->getType() == 'drop_down' || $option->getType() == 'radio' || $option->getType() == 'checkbox' ? '' : 'disabled'; $value['description'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['description']) ? $storeOptionsArr[$optionId]['description'] : $option->getDescription()); $value['block_title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['block_title']) ? $storeOptionsArr[$optionId]['block_title'] : $option->getBlockTitle()); if (Mage::helper('customoptions')->isCustomerGroupsEnabled() && $option->getCustomerGroups() != null) { $value['customer_groups'] = implode(',', $option->getCustomerGroups()); } $value['in_group_id'] = $option->getInGroupId(); $value['in_group_id_view'] = $option->getInGroupId(); $value['sort_order'] = $this->_getSortOrder($option); if ($this->getStoreId() != '0') { $value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['title'])); $value['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['title']) ? 'disabled' : null; $value['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['description'])); $value['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['description']) ? 'disabled' : null; $value['checkboxScopeBlockTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'block_title', !isset($storeOptionsArr[$optionId]['block_title'])); $value['scopeBlockTitleDisabled'] = !isset($storeOptionsArr[$optionId]['block_title']) ? 'disabled' : null; } if ($product->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) { $countValues = count($option->getValues()); if ($countValues > 0) { foreach ($option->getValues() as $key => $_value) { $_value = new Varien_Object($_value); $_value->setOptionTypeId($key); if ($_value->getIsDelete() != '1') { $defaultArray = $option->getDefault() !== null ? $option->getDefault() : array(); $value['optionValues'][$key] = array('item_count' => $countValues, 'option_id' => $option->getOptionId(), 'option_type_id' => $_value->getOptionTypeId(), 'title' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title'] : $_value->getTitle()), 'price' => $this->getPriceValue(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'] : $_value->getPrice(), $_value->getPriceType()), 'price_type' => isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type'] : $_value->getPriceType(), 'sku' => $this->htmlEscape($_value->getSku()), 'code' => $this->htmlEscape($_value->getCode()), 'tier' => $_value->getTier(), 'sort_order' => $this->_getSortOrder($_value), 'customoptions_qty' => $_value->getCustomoptionsQty(), 'checked' => array_search($_value->getOptionTypeId(), $defaultArray) !== false ? 'checked' : '', 'default_type' => $option->getType() == 'checkbox' || $option->getType() == 'multiple' ? 'checkbox' : 'radio', 'in_group_id' => $_value->getInGroupId(), 'in_group_id_view' => $_value->getInGroupId(), 'dependent_ids' => $_value->getDependentIds()); $value['optionValues'][$key]['image_button_label'] = Mage::helper('customoptions')->__('Add Image'); $imgHtml = Mage::helper('customoptions')->getImgHtml($_value->getImagePath(), $option->getId(), $_value->getOptionTypeId()); if ($imgHtml) { $value['optionValues'][$key]['image'] = $imgHtml; $value['optionValues'][$key]['image_button_label'] = Mage::helper('customoptions')->__('Change Image'); } if ($this->getStoreId() != '0') { $value['optionValues'][$key]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']), $_value->getOptionTypeId()); $value['optionValues'][$key]['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? 'disabled' : null; if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { $value['optionValues'][$key]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($_value->getstorePrice()), $_value->getOptionTypeId()); $value['optionValues'][$key]['scopePriceDisabled'] = is_null($_value->getStorePrice()) ? 'disabled' : null; } } } } $value['optionValues'] = array_values($value['optionValues']); } } else { $value['price'] = $this->getPriceValue(isset($storeOptionsArr[$optionId]['price']) ? $storeOptionsArr[$optionId]['price'] : $option->getPrice(), $option->getPriceType()); $value['price_type'] = isset($storeOptionsArr[$optionId]['price_type']) ? $storeOptionsArr[$optionId]['price_type'] : $option->getPriceType(); $value['sku'] = $this->htmlEscape($option->getSku()); $value['code'] = $this->htmlEscape($option->getCode()); $value['max_characters'] = $option->getMaxCharacters(); $value['file_extension'] = $option->getFileExtension(); $value['image_size_x'] = $option->getImageSizeX(); $value['image_size_y'] = $option->getImageSizeY(); $value['image_button_label'] = Mage::helper('customoptions')->__('Add Image'); $imgHtml = Mage::helper('customoptions')->getImgHtml($option->getImagePath(), $option->getId()); if ($imgHtml) { $value['image'] = $imgHtml; $value['image_button_label'] = Mage::helper('customoptions')->__('Change Image'); } if ($this->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { $value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($option->getStorePrice())); $value['scopePriceDisabled'] = is_null($option->getStorePrice()) ? 'disabled' : null; } } $values[] = new Varien_Object($value); } } $this->_values = $values; } return $this->_values ? $this->_values : array(); }
/** * Substitute the product sku for entity_id as all products processed from the * feeds will have a sku. This makes looking up a product by SKU more * reasonable and allows for newly created items to be looked up after being * added to the collection but before the collection has been saved. * @param Varien_Object $item * @return string */ protected function _getItemId(Varien_Object $item) { return $item->getSku(); }
/** * Get one line item key-value array * * @param Mage_Core_Model_Abstract $salesEntity * @param Varien_Object $item * @return array */ protected function _prepareLineItemFields(Mage_Core_Model_Abstract $salesEntity, Varien_Object $item) { if ($salesEntity instanceof Mage_Sales_Model_Order) { $qty = $item->getQtyOrdered(); $amount = $item->getBasePrice(); // TODO: nominal item for order } else { $qty = $item->getTotalQty(); $amount = $item->isNominal() ? 0 : $item->getBaseCalculationPrice(); } // workaround in case if item subtotal precision is not compatible with PayPal (.2) $subAggregatedLabel = ''; if ((double) $amount - round((double) $amount, 2)) { $amount = $amount * $qty; $subAggregatedLabel = ' x' . $qty; $qty = 1; } return array('id' => $item->getSku(), 'name' => $item->getName() . $subAggregatedLabel, 'qty' => $qty, 'amount' => (double) $amount); }
/** * Process product data before save * * @param Varien_Object $object * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product */ protected function _beforeSave(Varien_Object $object) { if (!$object->getId() && $object->getSku()) { $object->setId($this->getIdBySku($object->getSku())); } $categoryIds = $object->getCategoryIds(); if ($categoryIds) { $categoryIds = AO::getModel('catalog/category')->verifyIds($categoryIds); } $object->setData('category_ids', implode(',', $categoryIds)); return parent::_beforeSave($object); }
/** * charge money for recurring item */ protected function _checkoutRecurring() { /** @var Mage_Sales_Model_Order $order */ $order = Mage::getModel('sales/order'); $item = new Varien_Object($this->_recurringProfile->getOrderItemInfo()); $this->_price = $item->getBasePrice() * $item->getQty(); $additionalInfo = $this->_recurringProfile->getAdditionalInfo(); // check isset TrialBilling // Trial Billing Frequency <= 0 or isn't numeric => failure if ($this->_recurringProfile->getTrialBillingAmount() && $this->_recurringProfile->getTrialPeriodFrequency() && $this->_recurringProfile->getTrialPeriodMaxCycles() && $this->_recurringProfile->getTrialPeriodUnit() && (string) (int) $this->_recurringProfile->getTrialPeriodFrequency() === ltrim($this->_recurringProfile->getTrialPeriodFrequency(), '0') && (int) $this->_recurringProfile->getTrialPeriodFrequency() > 0) { $trialPeriodMaxCycles = (int) $this->_recurringProfile->getTrialPeriodMaxCycles(); if (!isset($additionalInfo['trialPeriodMaxCycles'])) { $additionalInfo['trialPeriodMaxCycles'] = $trialPeriodMaxCycles; $this->_recurringProfile->setAdditionalInfo($additionalInfo); $this->_price = $this->_recurringProfile->getTrialBillingAmount(); $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL; } elseif (isset($additionalInfo['trialPeriodMaxCycles']) && $additionalInfo['trialPeriodMaxCycles'] > 0) { $this->_price = $this->_recurringProfile->getTrialBillingAmount(); $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL; } } // calculate total amount $this->_shippingAmount = $item->getBaseShippingAmount(); $this->_taxAmount = $item->getBaseTaxAmount(); $this->_amount = $this->_price + $this->_shippingAmount + $this->_taxAmount; // init order /** @var Mage_Sales_Model_Order_Item $orderItem */ $orderItem = Mage::getModel('sales/order_item')->setName($item->getName())->setSku($item->getSku())->setDescription($item->getDescription())->setQtyOrdered($item->getQty())->setBasePrice($item->getBasePrice())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax()); $order->addItem($orderItem); $shippingInfo = $this->_recurringProfile->getShippingAddressInfo(); $shippingAddress = Mage::getModel('sales/order_address')->setData($shippingInfo)->setId(null); // get base currency code $orderInfo = new Varien_Object($this->_recurringProfile->getOrderInfo()); $currencyCode = $orderInfo->getBaseCurrencyCode(); $order->setShippingAddress($shippingAddress); $order->setBaseCurrencyCode($currencyCode); /** @var Mage_Sales_Model_Order_Payment $payment */ $payment = Mage::getModel('sales/order_payment'); $payment->setOrder($order); $payment->setIsRecurring(true); $payment->setIsInitialFee(true); $customerId = $this->_recurringProfile->getCustomerId(); $payment->setCustomerId($customerId); $tokenId = $additionalInfo['token']['saved_token']; $payment->setTokenId($tokenId); /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */ $ewaySave = Mage::getModel('ewayrapid/method_saved'); $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action'); if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) { $ewaySave->authorize($payment, $this->_amount); } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) { $ewaySave->capture($payment, $this->_amount); } if (!$payment->getTransactionId()) { throw new Exception('Transaction is not available'); } else { $this->_txdId = $payment->getTransactionId(); } /** @todo: change status of order = "eWAY Authorised" * now status order = "processing" */ }