I am not very familiar with Magento, but I am learning.
Basically, when a order is made with a "subscription" product, the subscription has several options.
I store the selected options out to a data table.
On subscription renewal, I get a notification from a third party payment provider.
Using that data, I can pull up the data from my custom table to identify the customer, the product id, the order id (from the initial order), and the product options the customer selected on the initial order. (The initial order has other products on it as well).
When I get the product custom options I am using:
//$item is the order item on the initial order $productOptions = $item->getData('product_options');
This is the option data that I am storing for the product.
When I attempt to create the new order upon notification I am using:
$customer = Mage::getModel('customer/customer')->load($MyCustomModule->getMagentocustomerId()); $productId = $MyCustomModule->getProductId(); $websiteId = Mage::app()->getWebsite()->getId(); $store = Mage::app()->getStore(); $customerBillingAddress = $customer->getDefaultBillingAddress(); $customerShippingAddress = $customer->getDefaultShippingAddress(); $quote = Mage::getModel('sales/quote')->setStoreId($store->getId()); $quote->assignCustomer($customer); $addressBillingData = array( 'firstname' => $customerBillingAddress->getFirstName(), 'lastname' => $customerBillingAddress->getLastName, 'street' => $customerBillingAddress->getStreet, 'city' => $customerBillingAddress->getCity, 'postcode'=>$customerBillingAddress->getPostCode, 'telephone' => $customerBillingAddress->getPhoneNumber, 'country_id' => $customerBillingAddress->getCountryId, 'region_id' => $customerBillingAddress->getRegionId ); $addressShippingData = array( 'firstname' => $customerShippingAddress->getFirstName(), 'lastname' => $customerShippingAddress->getLastName, 'street' => $customerShippingAddress->getStreet, 'city' => $customerShippingAddress->getCity, 'postcode'=>$customerShippingAddress->getPostCode, 'telephone' => $customerShippingAddress->getPhoneNumber, 'country_id' => $customerShippingAddress->getCountryId, 'region_id' => $customerShippingAddress->getRegionId ); $billingAddress = $quote->getBillingAddress()->addData($addressBillingData); $shippingAddress = $quote->getShippingAddress()->addData($addressShippingData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod('freeshipping_freeshipping')->setPaymentMethod('checkmo'); $quote->getPayment()->importData(array('method' => 'checkmo')); /// Need to add the product with the custom options to the quote. $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); $order->setStatus('processing'); $order->save();
I am not sure how I would add the product to the quote with the custom options. In addition, I am not sure how to set the payment method other than checkmo. The third party billing system is billing and in most cases, the payment is already completed when I get the notification.
I plan to have a separate function that is close to this one for when a payment fails. I plan to set that order status as onhold so that we can query onhold orders to contact customers to get new payment data.
Shipping will always be free with orders created here.
Can someone help point me in the right direction to add the custom product options to the product? And do I need to do this on the quote or wait and do it on the order?
The custom options data looks like this:
$productOptions = $item->getData('product_options'); $productOptions = print_r($productOptions, true);
And was able to get a better stored value. When I add the product to the quote that is being created I use the following:
// options is the $productOptions value from above. $quote->addProduct($product,new Varien_Object($options));
However, I keep getting the error "Please add Shipping Method" on the quote creation.
I try to set the Shipping Method this way:
$quote->getShippingAddress() ->setShippingMethod('tablerate_bestway') ->setPaymentMethod('purchaseorder');
I have tried several ways, and have been searching for the answer for this. Once I get the Shipping Method taken care of, perhaps I can see if the way I am loading the options is working.