Untitled diff

Erstellt Diff läuft nie ab
30 Entfernungen
281 Zeilen
9 Hinzufügungen
260 Zeilen
<?php
<?php
class Pricebinc_App_Model_OrderCreate extends Mage_Core_Model_Abstract
class NameApp_App_Model_OrderCreate extends Mage_Core_Model_Abstract
{
{
const CUSTOMER_RANDOM = null;
const CUSTOMER_RANDOM = null;
protected $_shippingMethod = 'freeshipping_freeshipping';
protected $_shippingMethod = 'freeshipping_freeshipping';
protected $_paymentMethod = 'cashondelivery';
protected $_paymentMethod = 'cashondelivery';
protected $_customer = self::CUSTOMER_RANDOM;
protected $_subTotal = 0;
protected $_subTotal = 0;
protected $_order;
protected $_order;
protected $_storeId;
protected $_storeId = '0';

public function _construct()
{
parent::_construct();
$this->_init('app/ordercreate');
}


public function setShippingMethod($methodName)
public function setShippingMethod($methodName)
{
{
$this->_shippingMethod = $methodName;
$this->_shippingMethod = $methodName;
}
}

public function setPaymentMethod($methodName)
public function setPaymentMethod($methodName)
{
{
$this->_paymentMethod = $methodName;
$this->_paymentMethod = $methodName;
}
}


public function setCustomer($customer)
{
if ($customer instanceof Mage_Customer_Model_Customer) {
$this->_customer = $customer;
}
if (is_numeric($customer)) {
$this->_customer = Mage::getModel('customer/customer')->load($customer);
} else if ($customer === self::CUSTOMER_RANDOM) {
$customers = Mage::getResourceModel('customer/customer_collection');

$customers
->getSelect()
->limit(1)
->order('RAND()');

$id = $customers->getFirstItem()->getId();

$this->_customer = Mage::getModel('customer/customer')->load($id);
}
}

public function createOrder($products)
public function createOrder($products)
{
{
if (!($this->_customer instanceof Mage_Customer_Model_Customer)) {
$this->setCustomer(self::CUSTOMER_RANDOM);
}

$transaction = Mage::getModel('core/resource_transaction');
$transaction = Mage::getModel('core/resource_transaction');
$this->_storeId = Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$this->_storeId = Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$this->_customer = Mage::getSingleton('customer/session')->getCustomer();
$reservedOrderId = Mage::getSingleton('eav/config')
$reservedOrderId = Mage::getSingleton('eav/config')
->getEntityType('order')
->getEntityType('order')
->fetchNewIncrementId($this->_storeId);
->fetchNewIncrementId($this->_storeId);


$currencyCode = Mage::app()->getBaseCurrencyCode();
$currencyCode = Mage::app()->getBaseCurrencyCode();
$this->_order = Mage::getModel('sales/order')
$this->_order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setIncrementId($reservedOrderId)
->setStoreId($this->_storeId)
->setStoreId($this->_storeId)
->setQuoteId(0)
->setQuoteId(0)
->setGlobalCurrencyCode($currencyCode)
->setGlobalCurrencyCode($currencyCode)
->setBaseCurrencyCode($currencyCode)
->setBaseCurrencyCode($currencyCode)
->setStoreCurrencyCode($currencyCode)
->setStoreCurrencyCode($currencyCode)
->setOrderCurrencyCode($currencyCode);
->setOrderCurrencyCode($currencyCode);




$this->_order->setCustomerEmail($this->_customer->getEmail())
$this->_order->setCustomerEmail($this->_customer->getEmail())
->setCustomerFirstname($this->_customer->getFirstname())
->setCustomerFirstname($this->_customer->getFirstname())
->setCustomerLastname($this->_customer->getLastname())
->setCustomerLastname($this->_customer->getLastname())
->setCustomerGroupId($this->_customer->getGroupId())
->setCustomerGroupId($this->_customer->getGroupId())
->setCustomerIsGuest(0)
->setCustomerIsGuest(0)
->setCustomer($this->_customer);
->setCustomer($this->_customer);




$billing = $this->_customer->getDefaultBillingAddress();
$billing = $this->_customer->getDefaultBillingAddress();
$billingAddress = Mage::getModel('sales/order_address')
$billingAddress = Mage::getModel('sales/order_address')
->setStoreId($this->_storeId)
->setStoreId($this->_storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setCustomerId($this->_customer->getId())
->setCustomerId($this->_customer->getId())
->setCustomerAddressId($this->_customer->getDefaultBilling())
->setCustomerAddressId($this->_customer->getDefaultBilling())
->setCustomerAddress_id($billing->getEntityId())
->setCustomerAddress_id($billing->getEntityId())
->setPrefix($billing->getPrefix())
->setPrefix($billing->getPrefix())
->setFirstname($billing->getFirstname())
->setFirstname($billing->getFirstname())
->setMiddlename($billing->getMiddlename())
->setMiddlename($billing->getMiddlename())
->setLastname($billing->getLastname())
->setLastname($billing->getLastname())
->setSuffix($billing->getSuffix())
->setSuffix($billing->getSuffix())
->setCompany($billing->getCompany())
->setCompany($billing->getCompany())
->setStreet($billing->getStreet())
->setStreet($billing->getStreet())
->setCity($billing->getCity())
->setCity($billing->getCity())
->setCountry_id($billing->getCountryId())
->setCountry_id($billing->getCountryId())
->setRegion($billing->getRegion())
->setRegion($billing->getRegion())
->setRegion_id($billing->getRegionId())
->setRegion_id($billing->getRegionId())
->setPostcode($billing->getPostcode())
->setPostcode($billing->getPostcode())
->setTelephone($billing->getTelephone())
->setTelephone($billing->getTelephone())
->setFax($billing->getFax());
->setFax($billing->getFax());
$this->_order->setBillingAddress($billingAddress);
$this->_order->setBillingAddress($billingAddress);


$shipping = $this->_customer->getDefaultShippingAddress();
$shipping = $this->_customer->getDefaultShippingAddress();
$shippingAddress = Mage::getModel('sales/order_address')
$shippingAddress = Mage::getModel('sales/order_address')
->setStoreId($this->_storeId)
->setStoreId($this->_storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setCustomerId($this->_customer->getId())
->setCustomerId($this->_customer->getId())
->setCustomerAddressId($this->_customer->getDefaultShipping())
->setCustomerAddressId($this->_customer->getDefaultShipping())
->setCustomer_address_id($shipping->getEntityId())
->setCustomer_address_id($shipping->getEntityId())
->setPrefix($shipping->getPrefix())
->setPrefix($shipping->getPrefix())
->setFirstname($shipping->getFirstname())
->setFirstname($shipping->getFirstname())
->setMiddlename($shipping->getMiddlename())
->setMiddlename($shipping->getMiddlename())
->setLastname($shipping->getLastname())
->setLastname($shipping->getLastname())
->setSuffix($shipping->getSuffix())
->setSuffix($shipping->getSuffix())
->setCompany($shipping->getCompany())
->setCompany($shipping->getCompany())
->setStreet($shipping->getStreet())
->setStreet($shipping->getStreet())
->setCity($shipping->getCity())
->setCity($shipping->getCity())
->setCountry_id($shipping->getCountryId())
->setCountry_id($shipping->getCountryId())
->setRegion($shipping->getRegion())
->setRegion($shipping->getRegion())
->setRegion_id($shipping->getRegionId())
->setRegion_id($shipping->getRegionId())
->setPostcode($shipping->getPostcode())
->setPostcode($shipping->getPostcode())
->setTelephone($shipping->getTelephone())
->setTelephone($shipping->getTelephone())
->setFax($shipping->getFax());
->setFax($shipping->getFax());


$this->_order->setShippingAddress($shippingAddress)
$this->_order->setShippingAddress($shippingAddress)
->setShippingMethod($this->_shippingMethod);
->setShippingMethod($this->_shippingMethod);


$orderPayment = Mage::getModel('sales/order_payment')
$orderPayment = Mage::getModel('sales/order_payment')