Public Member Functions | |
__construct () | |
render () | |
save () | |
Protected Member Functions | |
_getStores () | |
_getCustomers () | |
_getProducts () | |
_getCustomer () | |
_getRandomProduct () | |
_getStore () | |
_getRandomDate () | |
Protected Attributes | |
$_quote | |
$_order | |
$_store | |
$_customer | |
$_productCollection | |
Static Protected Attributes | |
static | $_storeCollection |
static | $_customerCollection |
Definition at line 32 of file Random.php.
__construct | ( | ) |
Definition at line 54 of file Random.php.
00055 { 00056 $this->_quote = Mage::getModel('sales/quote')->save(); 00057 $this->_order = Mage::getModel('sales/order'); 00058 }
_getCustomer | ( | ) | [protected] |
Retrieve customer model
Definition at line 100 of file Random.php.
00101 { 00102 if (!$this->_customer) { 00103 $items = $this->_getCustomers(); 00104 $randKey = array_rand($items); 00105 $this->_customer = $items[$randKey]; 00106 } 00107 return $this->_customer; 00108 }
_getCustomers | ( | ) | [protected] |
Definition at line 69 of file Random.php.
00070 { 00071 if (!self::$_customerCollection) { 00072 self::$_customerCollection = Mage::getResourceModel('customer/customer_collection') 00073 ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'inner') 00074 ->joinAttribute('shipping_country_id', 'customer_address/country_id', 'default_shipping', null, 'inner') 00075 ->load(); 00076 } 00077 return self::$_customerCollection->getItems(); 00078 }
_getProducts | ( | ) | [protected] |
Definition at line 80 of file Random.php.
00081 { 00082 if (!$this->_productCollection) { 00083 $this->_productCollection= Mage::getResourceModel('catalog/product_collection'); 00084 //$this->_productCollection->getEntity()->setStore($this->_getStore()); 00085 Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection); 00086 Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection); 00087 $this->_productCollection->addAttributeToSelect('name') 00088 ->addAttributeToSelect('sku') 00089 ->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) 00090 ->load(); 00091 } 00092 return $this->_productCollection->getItems(); 00093 }
_getRandomDate | ( | ) | [protected] |
Definition at line 153 of file Random.php.
00154 { 00155 $timestamp = mktime(rand(0,23), rand(0,59), 0, rand(1,11), rand(1,28), rand(2006, 2007)); 00156 return date('Y-m-d H:i:s', $timestamp); 00157 }
_getRandomProduct | ( | ) | [protected] |
Definition at line 110 of file Random.php.
00111 { 00112 $items = $this->_getProducts(); 00113 $randKey = array_rand($items); 00114 return isset($items[$randKey]) ? $items[$randKey] : false; 00115 }
_getStore | ( | ) | [protected] |
Definition at line 117 of file Random.php.
00118 { 00119 if (!$this->_store) { 00120 $items = $this->_getStores(); 00121 $randKey = array_rand($items); 00122 $this->_store = $items[$randKey]; 00123 } 00124 return $this->_store; 00125 }
_getStores | ( | ) | [protected] |
Definition at line 60 of file Random.php.
00061 { 00062 if (!self::$_storeCollection) { 00063 self::$_storeCollection = Mage::getResourceModel('core/store_collection') 00064 ->load(); 00065 } 00066 return self::$_storeCollection->getItems(); 00067 }
render | ( | ) |
Definition at line 127 of file Random.php.
00128 { 00129 $customer = $this->_getCustomer(); 00130 $this->_quote->setStore($this->_getStore()) 00131 ->setCustomer($customer); 00132 $this->_quote->getBillingAddress()->importCustomerAddress($customer->getDefaultBillingAddress()); 00133 $this->_quote->getShippingAddress()->importCustomerAddress($customer->getDefaultShippingAddress()); 00134 00135 $productCount = rand(3, 10); 00136 for ($i=0; $i<$productCount; $i++){ 00137 $product = $this->_getRandomProduct(); 00138 if ($product) { 00139 $product->setQuoteQty(1); 00140 $this->_quote->addCatalogProduct($product); 00141 } 00142 } 00143 $this->_quote->getPayment()->setMethod('checkmo'); 00144 00145 $this->_quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping');//->collectTotals()->save(); 00146 $this->_quote->getShippingAddress()->setCollectShippingRates(true); 00147 $this->_quote->collectTotals() 00148 ->save(); 00149 $this->_quote->save(); 00150 return $this; 00151 }
save | ( | ) |
Definition at line 159 of file Random.php.
00160 { 00161 $this->_order->setStoreId($this->_getStore()->getId()); 00162 $this->_order->createFromQuoteAddress($this->_quote->getShippingAddress()); 00163 $this->_order->validate(); 00164 $this->_order->setInitialStatus(); 00165 $this->_order->save(); 00166 $this->_order->setCreatedAt($this->_getRandomDate()); 00167 $this->_order->save(); 00168 00169 $this->_quote->setIsActive(false); 00170 $this->_quote->save(); 00171 return $this; 00172 }
$_customer [protected] |
Definition at line 48 of file Random.php.
$_customerCollection [static, protected] |
Definition at line 52 of file Random.php.
$_order [protected] |
Definition at line 46 of file Random.php.
$_productCollection [protected] |
Definition at line 49 of file Random.php.
$_quote [protected] |
Definition at line 39 of file Random.php.
$_store [protected] |
Definition at line 47 of file Random.php.
$_storeCollection [static, protected] |
Definition at line 51 of file Random.php.