From 4864bf586f7927f79dd9c437ae7b4a86530f1e17 Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Sun, 23 Feb 2014 22:07:28 +1100 Subject: [PATCH 1/7] Added more options. Specifically guest orders, products, and orders for each customer. --- README.md | 6 +- bin/magefaker | 161 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 159 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9b425d6..fd3fc07 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Generate fake test data for Magento -MageFaker is a tool for creating a bunch of bogus customer accounts on a Magento installation using realistic, yet fake, customer data. +MageFaker is a tool for creating a bunch of bogus customer accounts, products and orders on a Magento installation using realistic, yet fake, customer data. ![image](http://up.nicksays.co.uk/image/0240281V1D1e/Screen%20Shot%202012-11-27%20at%2000.12.07.png) @@ -13,6 +13,6 @@ MageFaker is a tool for creating a bunch of bogus customer accounts on a Magento ### Usage -The following command will create 300 fake customer accounts for the Magento installation at `~/Sites/my/magento/root`. +Following command will create 1K fake products, 50K fake customer accounts, 3 fake orders (5 purchase items each) per customer & 20K fake guest orders for the Magento installation at `~/Sites/my/magento/root`. - magefaker --magento ~/Sites/my/magento/root 300 \ No newline at end of file + magefaker --magento ~/Sites/my/magento/root --products 1000 --customers 50000 3 5 --guestorders 20000 \ No newline at end of file diff --git a/bin/magefaker b/bin/magefaker index 1ddbf15..b21bcb8 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -1,5 +1,6 @@ #!/usr/bin/php option('magento') ->require() ->describedAs('The root directory of your Magento installation'); -$opts->argument() - ->require() +$opts->option('products') + ->describedAs("The number of products you'd like to create"); + +$opts->option('customers') ->describedAs("The number of customers you'd like to create"); +$opts->option('guestorders') + ->describedAs("The number of guest orders you'd like to create"); + $c = new \Colors\Color(); $magento_base_dir = $opts['magento']; -$customer_count = $opts[0]; +$product_count = intval($opts['products']); +$guest_order_count = intval($opts['guestorders']); +$customer_count = intval($opts['customers']); +$order_count = 0; +$purchase_item_count = 0; +if (count($opts->getArgumentValues()) == 2) { + $order_count = intval($opts->getArgumentValues()[0]); + $purchase_item_count = intval($opts->getArgumentValues()[1]); +} $app_file = $magento_base_dir . DIRECTORY_SEPARATOR . "app/Mage.php"; @@ -30,9 +44,11 @@ Mage::app(); class MageFaker { protected $_faker; + protected $productIds; public function __construct() { $this->_faker = \Faker\Factory::create(); + $this->productIds = array(); } public function createFakeCustomer() { @@ -81,15 +97,150 @@ class MageFaker { return $address; } + + public function createFakeProduct() { + Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); + $product = Mage::getModel('catalog/product'); + $product->setSku(uniqid('', true)); + $product->setName(uniqid('', true) . 'name'); + $product->setDescription("This widget will give you years of trouble-free widgeting."); + $product->setShortDescription("High-end widget."); + $product->setPrice(rand(1, 10000) + rand(0, 99)/10); + $product->setTypeId('simple'); + $product->setAttributeSetId(9); // need to look this up + $product->setCategoryIds(array(42)); // need to look these up + $product->setWeight(1.0); + $product->setTaxClassId(2); // taxable goods + $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); + $product->setStatus(1); // enabled + // assign product to the default website + $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); + $product->setCreatedAt(strtotime('now')); + $product->save(); + + array_push($this->productIds, $product->getId()); + + return $product; + } + + public function createFakeOrder($_customer=null, $_purchase_item_count=0) { + $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); + if (!empty($this->productIds)) { + for ($k = 0; $k < $_purchase_item_count; $k++) { + $index = array_rand($this->productIds, 1); // Randomly pick a productId + $product = Mage::getModel('catalog/product')->load($this->productIds[$index]); // Make sure it's a 'simple' item + $qtyInfo = array('qty' => 1); + $quote->addProduct($product, new Varien_Object($qtyInfo)); + } + + if (!isset($_customer)) { // Checks out as guest + $billingAddress = array( + 'firstname' => $this->_faker->firstName, + 'lastname' => $this->_faker->lastName, + 'company' => $this->_faker->company, + 'email' => $this->_faker->safeEmail, + 'street' => array( + $this->_faker->buildingNumber . ' ' . $this->_faker->streetName, + $this->_faker->secondaryAddress + ), + 'city' => $this->_faker->city, + 'region_id' => '', + 'region' => $this->_faker->city, + 'postcode' => $this->_faker->postcode, + 'country_id' => 'GB', + 'telephone' => $this->_faker->phoneNumber, + 'fax' => $this->_faker->phoneNumber, + 'customer_password' => '', + 'confirm_password' => '', + 'save_in_address_book' => '0', + 'use_for_shipping' => '1', + ); + $quote->getBillingAddress()->addData($billingAddress); + $quote->getShippingAddress()->addData($billingAddress); + + $quote->setCheckoutMethod('guest') + ->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroup(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + } else { // Check out as registered customer + $quote->assignCustomer($_customer); + + $customer = Mage::getModel('customer/customer')->load($_customer->getId()); + $billingAddress = $customer->getDefaultBillingAddress(); + $shippingAddress = $customer->getDefaultShippingAddress(); + + $addressForm = Mage::getModel('customer/form'); + $addressForm->setFormCode('customer_address_edit') + ->setEntityType('customer_address'); + + foreach ($addressForm->getAttributes() as $attribute) { + if (isset($shippingAddress[$attribute->getAttributeCode()])) { + $quote->getShippingAddress()->setData($attribute->getAttributeCode(), $shippingAddress[$attribute->getAttributeCode()]); + } + } + + foreach ($addressForm->getAttributes() as $attribute) { + if (isset($billingAddress[$attribute->getAttributeCode()])) { + $quote->getBillingAddress()->setData($attribute->getAttributeCode(), $billingAddress[$attribute->getAttributeCode()]); + } + } + } + + $quote->getShippingAddress()->setCollectShippingRates(true); + $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); //->setShippingMethod('tablerate_bestway') + $quote->getShippingAddress()->setPaymentMethod('checkmo'); + $quote->getPayment()->importData(array('method' => 'checkmo')); + $quote->collectTotals(); + + $quote->save(); + + $service = Mage::getModel('sales/service_quote', $quote); + $service->submitAll(); + + return $service->getOrder(); + } + + return null; + } } $magefaker = new MageFaker(); +// Create fake products +for ($i = 0; $i < $product_count; $i++) { + try { + $product = $magefaker->createFakeProduct(); + if (!isset($product)) throw new Exception("Error Creating Product", 1); + echo $c(sprintf("Introducing product.. %s\n", $product->getName()))->green; + } catch (Exception $e) { + echo $c(sprintf("An error occurred: %s\n", $e->getMessage()))->red; + } +} + +// Create fake customers -- assumption each fake customer has x-orders for ($i = 0; $i < $customer_count; $i++) { try { $customer = $magefaker->createFakeCustomer(); - echo $c(sprintf("Introducing.. %s\n", $customer->getName()))->green; + if (!isset($customer)) throw new Exception("Error Creating Customer", 1); + echo $c(sprintf("Introducing customer.. %s\n", $customer->getName()))->green; + for ($j = 0; $j < $order_count; $j++) { + $order = $magefaker->createFakeOrder($customer, $purchase_item_count); + if (!isset($order)) throw new Exception("Error Creating Order", 1); + echo $c(sprintf("Order .. %s for customer %s\n", $order->getRealOrderId(), $customer->getName()))->green; + } + } catch (Exception $e) { + echo $c(sprintf("An error occurred: %s\n", $e->getMessage()))->red; + } +} + +// Create fake guest orders +for ($i = 0; $i < $guest_order_count; $i++) { + try { + $guest_order = $magefaker->createFakeOrder(null, $purchase_item_count); + if (!isset($guest_order)) throw new Exception("Error Creating Guest Order", 1); + echo $c(sprintf("Introducing guest order.. %s\n", $guest_order->getRealOrderId()))->green; } catch (Exception $e) { echo $c(sprintf("An error occurred: %s\n", $e->getMessage()))->red; } -} \ No newline at end of file +} From dcfb9d7a1bfb3f026216a1d46884bb4af0128413 Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Mon, 24 Feb 2014 08:44:17 +1100 Subject: [PATCH 2/7] 1. Added more memory to deal with big data sets 2. Remove dependency of createFakeOrder() solely on createFakeProduct() --- bin/magefaker | 164 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 99 insertions(+), 65 deletions(-) diff --git a/bin/magefaker b/bin/magefaker index b21bcb8..6199c61 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -1,6 +1,7 @@ #!/usr/bin/php setStoreId(Mage::app()->getStore('default')->getId()); - if (!empty($this->productIds)) { - for ($k = 0; $k < $_purchase_item_count; $k++) { - $index = array_rand($this->productIds, 1); // Randomly pick a productId - $product = Mage::getModel('catalog/product')->load($this->productIds[$index]); // Make sure it's a 'simple' item - $qtyInfo = array('qty' => 1); - $quote->addProduct($product, new Varien_Object($qtyInfo)); + if (empty($this->productIds)) { + // Grab productIds from available items + $collection = Mage::getModel('catalog/product')->getCollection() + ->addAttributeToSelect('*') + ->addAttributeToFilter('visibility', $visibility) + ->addAttributeToFilter( + 'status', + array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED) + ) + ->joinField( + 'is_in_stock', + 'cataloginventory/stock_item', + 'is_in_stock', + 'product_id=entity_id', + '{{table}}.stock_id=1', + 'left' + ) + ->joinField( + 'qty', + 'cataloginventory/stock_item', + 'qty', + 'product_id=entity_id', + '{{table}}.stock_id=1', + 'left' + ) + ->addAttributeToFilter('is_in_stock', array('eq' => 1)) + ->setOrder('created_at', 'desc') + ->setPageSize(100); // limit to only 100 results + $products = $colleciton->load(); + + foreach ($products as $prod) { + array_push($this->productsIds, $prod->getId()); } + } + + for ($k = 0; $k < $_purchase_item_count; $k++) { + $index = array_rand($this->productIds, 1); // Randomly pick a productId + $product = Mage::getModel('catalog/product')->load($this->productIds[$index]); // Make sure it's a 'simple' item + $qtyInfo = array('qty' => 1); + $quote->addProduct($product, new Varien_Object($qtyInfo)); + } - if (!isset($_customer)) { // Checks out as guest - $billingAddress = array( - 'firstname' => $this->_faker->firstName, - 'lastname' => $this->_faker->lastName, - 'company' => $this->_faker->company, - 'email' => $this->_faker->safeEmail, - 'street' => array( - $this->_faker->buildingNumber . ' ' . $this->_faker->streetName, - $this->_faker->secondaryAddress - ), - 'city' => $this->_faker->city, - 'region_id' => '', - 'region' => $this->_faker->city, - 'postcode' => $this->_faker->postcode, - 'country_id' => 'GB', - 'telephone' => $this->_faker->phoneNumber, - 'fax' => $this->_faker->phoneNumber, - 'customer_password' => '', - 'confirm_password' => '', - 'save_in_address_book' => '0', - 'use_for_shipping' => '1', - ); - $quote->getBillingAddress()->addData($billingAddress); - $quote->getShippingAddress()->addData($billingAddress); - - $quote->setCheckoutMethod('guest') - ->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroup(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); - } else { // Check out as registered customer - $quote->assignCustomer($_customer); - - $customer = Mage::getModel('customer/customer')->load($_customer->getId()); - $billingAddress = $customer->getDefaultBillingAddress(); - $shippingAddress = $customer->getDefaultShippingAddress(); - - $addressForm = Mage::getModel('customer/form'); - $addressForm->setFormCode('customer_address_edit') - ->setEntityType('customer_address'); - - foreach ($addressForm->getAttributes() as $attribute) { - if (isset($shippingAddress[$attribute->getAttributeCode()])) { - $quote->getShippingAddress()->setData($attribute->getAttributeCode(), $shippingAddress[$attribute->getAttributeCode()]); - } + if (!isset($_customer)) { // Checks out as guest + $billingAddress = array( + 'firstname' => $this->_faker->firstName, + 'lastname' => $this->_faker->lastName, + 'company' => $this->_faker->company, + 'email' => $this->_faker->safeEmail, + 'street' => array( + $this->_faker->buildingNumber . ' ' . $this->_faker->streetName, + $this->_faker->secondaryAddress + ), + 'city' => $this->_faker->city, + 'region_id' => '', + 'region' => $this->_faker->city, + 'postcode' => $this->_faker->postcode, + 'country_id' => 'GB', + 'telephone' => $this->_faker->phoneNumber, + 'fax' => $this->_faker->phoneNumber, + 'customer_password' => '', + 'confirm_password' => '', + 'save_in_address_book' => '0', + 'use_for_shipping' => '1', + ); + $quote->getBillingAddress()->addData($billingAddress); + $quote->getShippingAddress()->addData($billingAddress); + + $quote->setCheckoutMethod('guest') + ->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroup(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); + } else { // Check out as registered customer + $quote->assignCustomer($_customer); + + $customer = Mage::getModel('customer/customer')->load($_customer->getId()); + $billingAddress = $customer->getDefaultBillingAddress(); + $shippingAddress = $customer->getDefaultShippingAddress(); + + $addressForm = Mage::getModel('customer/form'); + $addressForm->setFormCode('customer_address_edit') + ->setEntityType('customer_address'); + + foreach ($addressForm->getAttributes() as $attribute) { + if (isset($shippingAddress[$attribute->getAttributeCode()])) { + $quote->getShippingAddress()->setData($attribute->getAttributeCode(), $shippingAddress[$attribute->getAttributeCode()]); } + } - foreach ($addressForm->getAttributes() as $attribute) { - if (isset($billingAddress[$attribute->getAttributeCode()])) { - $quote->getBillingAddress()->setData($attribute->getAttributeCode(), $billingAddress[$attribute->getAttributeCode()]); - } + foreach ($addressForm->getAttributes() as $attribute) { + if (isset($billingAddress[$attribute->getAttributeCode()])) { + $quote->getBillingAddress()->setData($attribute->getAttributeCode(), $billingAddress[$attribute->getAttributeCode()]); } } + } - $quote->getShippingAddress()->setCollectShippingRates(true); - $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); //->setShippingMethod('tablerate_bestway') - $quote->getShippingAddress()->setPaymentMethod('checkmo'); - $quote->getPayment()->importData(array('method' => 'checkmo')); - $quote->collectTotals(); + $quote->getShippingAddress()->setCollectShippingRates(true); + $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); //->setShippingMethod('tablerate_bestway') + $quote->getShippingAddress()->setPaymentMethod('checkmo'); + $quote->getPayment()->importData(array('method' => 'checkmo')); + $quote->collectTotals(); - $quote->save(); + $quote->save(); - $service = Mage::getModel('sales/service_quote', $quote); - $service->submitAll(); + $service = Mage::getModel('sales/service_quote', $quote); + $service->submitAll(); - return $service->getOrder(); - } + return $service->getOrder(); return null; } From aa6c1f4663413f1b9c2eb68996511e1629079201 Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Mon, 24 Feb 2014 09:12:05 +1100 Subject: [PATCH 3/7] Added fixes so we can get the collection of products --- bin/magefaker | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/magefaker b/bin/magefaker index 6199c61..fbac9c8 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -128,7 +128,10 @@ class MageFaker { $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); if (empty($this->productIds)) { // Grab productIds from available items - $collection = Mage::getModel('catalog/product')->getCollection() + $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, + Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG + ); + $products = Mage::getModel('catalog/product')->getResourceCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('visibility', $visibility) ->addAttributeToFilter( @@ -154,7 +157,6 @@ class MageFaker { ->addAttributeToFilter('is_in_stock', array('eq' => 1)) ->setOrder('created_at', 'desc') ->setPageSize(100); // limit to only 100 results - $products = $colleciton->load(); foreach ($products as $prod) { array_push($this->productsIds, $prod->getId()); From 30c86332e61cf3204b26ff0ffb251cb796c855ba Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Mon, 24 Feb 2014 09:22:34 +1100 Subject: [PATCH 4/7] Added extra attribute filter for only simple product types. This should be adjustable though. --- bin/magefaker | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/magefaker b/bin/magefaker index fbac9c8..a9dd328 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -127,7 +127,7 @@ class MageFaker { public function createFakeOrder($_customer=null, $_purchase_item_count=0) { $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); if (empty($this->productIds)) { - // Grab productIds from available items + // Grab productIds from available items - of product type 'simple' $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG ); @@ -138,6 +138,7 @@ class MageFaker { 'status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED) ) + ->addAttributeToFilter('type_id', array('eq' => 'simple')) // REMOVE for all product types: configurable, grouped, bundle, virtual etc. ->joinField( 'is_in_stock', 'cataloginventory/stock_item', From 0943fd221dfc5c5241305d8c36c570c1c32574fd Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Tue, 25 Feb 2014 17:44:52 +1100 Subject: [PATCH 5/7] Added less dependency on hard-coded values for fake product generation. Made other changes as well based on feedback. --- README.md | 10 +++++++++- bin/magefaker | 55 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fd3fc07..5ed44b8 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,12 @@ MageFaker is a tool for creating a bunch of bogus customer accounts, products an Following command will create 1K fake products, 50K fake customer accounts, 3 fake orders (5 purchase items each) per customer & 20K fake guest orders for the Magento installation at `~/Sites/my/magento/root`. - magefaker --magento ~/Sites/my/magento/root --products 1000 --customers 50000 3 5 --guestorders 20000 \ No newline at end of file + magefaker --magento ~/Sites/my/magento/root --customers 50000 3 5 --guestorders 20000 --products 1000 + +### Note (Caveat) + +For fake products only 'simple' product-types are supported. Other product types like 'configurable' and 'grouped' aren't supported because of the dependencies between parent and child products. + +For fake orders, assumption is that there are 'simple' products already on Magento. If not run something like the following command first (creates 2 fake 'simple' products): + + magefaker --magento ~/Sites/my/magento/root --products 2 diff --git a/bin/magefaker b/bin/magefaker index a9dd328..8c6e371 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -1,7 +1,6 @@ #!/usr/bin/php _faker = \Faker\Factory::create(); - $this->productIds = array(); + $this->_productIds = array(); + $this->_defaultAttributeSetId = $this->getDefaultAttributeSetId(); + } + + private function getDefaultAttributeSetId() { + /** Assumes you have some 'simple' products in the system e.g.: http://www.magentocommerce.com/download */ + if (!isset($this->_defaultAttributeSetId)) + { + $productModel = Mage::getModel("catalog/product") + ->getResourceCollection() + ->addAttributeToFilter('type_id', array('eq' => 'simple')) // Change accordingly for other product types: configurable, grouped etc. + ->getFirstItem(); + $this->_defaultAttributeSetId = $productModel->getDefaultAttributeSetId(); + } + return $this->_defaultAttributeSetId; } public function createFakeCustomer() { @@ -100,33 +114,38 @@ class MageFaker { } public function createFakeProduct() { + /** Note: Only 'simple' product-types are supported */ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $product = Mage::getModel('catalog/product'); - $product->setSku(uniqid('', true)); - $product->setName(uniqid('', true) . 'name'); - $product->setDescription("This widget will give you years of trouble-free widgeting."); - $product->setShortDescription("High-end widget."); - $product->setPrice(rand(1, 10000) + rand(0, 99)/10); + $product->setSku($this->_faker->md5); + $product->setName($this->_faker->sentence); + $product->setDescription($this->_faker->text); + $product->setShortDescription($this->_faker->sentence); + $product->setPrice($this->_faker->randomNumber + rand(0, 99)/10); $product->setTypeId('simple'); - $product->setAttributeSetId(9); // need to look this up - $product->setCategoryIds(array(42)); // need to look these up + // $product->setAttributeSetId(intval($this->_defaultAttributeSetId)); + $product->setAttributeSetId(9); + $product->setCategoryIds(array(Mage::app()->getStore(true)->getRootCategoryId())); $product->setWeight(1.0); $product->setTaxClassId(2); // taxable goods $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); $product->setStatus(1); // enabled - // assign product to the default website + $product->setStockData(array( + 'is_in_stock' => 1, + 'qty' => $this->_faker->randomDigit + )); $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); $product->setCreatedAt(strtotime('now')); $product->save(); - array_push($this->productIds, $product->getId()); + array_push($this->_productIds, $product->getId()); return $product; } public function createFakeOrder($_customer=null, $_purchase_item_count=0) { $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); - if (empty($this->productIds)) { + if (empty($this->_productIds)) { // Grab productIds from available items - of product type 'simple' $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG @@ -165,8 +184,8 @@ class MageFaker { } for ($k = 0; $k < $_purchase_item_count; $k++) { - $index = array_rand($this->productIds, 1); // Randomly pick a productId - $product = Mage::getModel('catalog/product')->load($this->productIds[$index]); // Make sure it's a 'simple' item + $index = array_rand($this->_productIds, 1); // Randomly pick a productId + $product = Mage::getModel('catalog/product')->load($this->_productIds[$index]); // Make sure it's a 'simple' item $qtyInfo = array('qty' => 1); $quote->addProduct($product, new Varien_Object($qtyInfo)); } @@ -226,7 +245,7 @@ class MageFaker { } $quote->getShippingAddress()->setCollectShippingRates(true); - $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); //->setShippingMethod('tablerate_bestway') + $quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); $quote->getShippingAddress()->setPaymentMethod('checkmo'); $quote->getPayment()->importData(array('method' => 'checkmo')); $quote->collectTotals(); @@ -237,8 +256,6 @@ class MageFaker { $service->submitAll(); return $service->getOrder(); - - return null; } } From 232e78d04df79cca05a744fb89fd2345ee861013 Mon Sep 17 00:00:00 2001 From: Herbert Yeung Date: Tue, 25 Feb 2014 17:46:56 +1100 Subject: [PATCH 6/7] Removed mem dependency. Up to user to figure this out. --- bin/magefaker | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/magefaker b/bin/magefaker index 8c6e371..2b043c1 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -1,6 +1,5 @@ #!/usr/bin/php Date: Wed, 26 Feb 2014 07:45:43 +1100 Subject: [PATCH 7/7] Removed code that looked up the associated set id as this assumes you have an existing item in the catalog. This means you should be able to create 'simple' product type items on the fly with an empty catalog. --- bin/magefaker | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/bin/magefaker b/bin/magefaker index 2b043c1..d0f9660 100755 --- a/bin/magefaker +++ b/bin/magefaker @@ -44,25 +44,10 @@ Mage::app(); class MageFaker { protected $_faker; protected $_productIds; - protected $_defaultAttributeSetId; public function __construct() { $this->_faker = \Faker\Factory::create(); $this->_productIds = array(); - $this->_defaultAttributeSetId = $this->getDefaultAttributeSetId(); - } - - private function getDefaultAttributeSetId() { - /** Assumes you have some 'simple' products in the system e.g.: http://www.magentocommerce.com/download */ - if (!isset($this->_defaultAttributeSetId)) - { - $productModel = Mage::getModel("catalog/product") - ->getResourceCollection() - ->addAttributeToFilter('type_id', array('eq' => 'simple')) // Change accordingly for other product types: configurable, grouped etc. - ->getFirstItem(); - $this->_defaultAttributeSetId = $productModel->getDefaultAttributeSetId(); - } - return $this->_defaultAttributeSetId; } public function createFakeCustomer() { @@ -122,7 +107,6 @@ class MageFaker { $product->setShortDescription($this->_faker->sentence); $product->setPrice($this->_faker->randomNumber + rand(0, 99)/10); $product->setTypeId('simple'); - // $product->setAttributeSetId(intval($this->_defaultAttributeSetId)); $product->setAttributeSetId(9); $product->setCategoryIds(array(Mage::app()->getStore(true)->getRootCategoryId())); $product->setWeight(1.0);