Last active
January 10, 2018 09:58
-
-
Save lukeholder/bbff8caef82078fc76e4 to your computer and use it in GitHub Desktop.
Revisions
-
lukeholder revised this gist
Jul 26, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ $newProduct->promotable = true; $newProduct->freeShipping = 0; $newProduct->postDate = new DateTime(); $newProduct->taxCategoryId = craft()->commerce_taxCategories->getDefaultTaxCategory()->id; $newProduct->getContent()->title = "Cheese"; $newProduct->slug = StringHelper::toKebabCase("Cheese"); -
lukeholder revised this gist
Aug 28, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ $newProduct->slug = StringHelper::toKebabCase("Cheese"); // Product custom fields // $product->setContentFromPost(array('customFieldName'=>'value')); $variant = new Commerce_VariantModel(); $variant->setProduct($newProduct); -
lukeholder revised this gist
Jun 16, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ $newProduct = new Commerce_ProductModel(); $newProduct->typeId = 1; // Replace with product type ID; $newProduct->enabled = true; $newProduct->promotable = true; -
lukeholder created this gist
Dec 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ <?php namespace Craft; // This file could be placed into your public_html folder and visited to import a cheese product. $craft = require '../craft/app/bootstrap.php'; $craft->plugins->loadPlugins(); $newProduct = new Commerce_ProductModel(); $newProduct->authorId = craft()->userSession->id; $newProduct->typeId = 1; // Replace with product type ID; $newProduct->enabled = true; $newProduct->promotable = true; $newProduct->freeShipping = 0; $newProduct->postDate = new DateTime(); $newProduct->taxCategoryId = craft()->commerce_taxCategories->getDefaultTaxCategoryId(); $newProduct->getContent()->title = "Cheese"; $newProduct->slug = StringHelper::toKebabCase("Cheese"); // Product custom fields // $product->setContentFromPost(craft()->request->getPost(['fields'])); $variant = new Commerce_VariantModel(); $variant->setProduct($newProduct); $variant->sortOrder = 1; $variant->getContent()->title = "Cheese"; $variant->sku = "10101"; $variant->price = "10"; $variant->unlimitedStock = true; $newProduct->setVariants([$variant]); if(craft()->commerce_products->saveProduct($newProduct)){ echo "done"; }else{ $errors = $newProduct->getAllErrors(); foreach ($errors as $error) { echo $error; echo "<br>"; } foreach ($newProduct->getVariants() as $variant) { $errors = $variant->getAllErrors(); foreach ($errors as $error) { echo $error; echo "<br>"; } } }; $craft->end();