├── .gitignore
├── DeleteProduct.php
├── Magicmenu.php
├── ProductReview.php
├── ProductReviewSummary.php
├── ProductSalableQuantity.php
├── ProductSortQuantity.php
├── ProductSynchronizeMSI.php
├── README.md
├── TemplateProcessor.php
├── TemplateProcessorBlock.php
├── TemplateProcessorPage.php
├── Topmenu.php
├── UpdateOrder.php
├── addAttribute.php
├── addAttributeFeatured.php
├── addAttributeOption.php
├── addCustomOptions.php
├── addInstallationOptions.php
├── addOrderComment.php
├── addRole.php
├── addSchema.php
├── addSchemaModule.php
├── addUserAdmin.php
├── adminCategoryTree.php
├── appLayoutCategpry.php
├── appLayoutPage.php
├── appTheme.php
├── apply_to_attribute.php
├── cacheflush.php
├── categoryProduct.php
├── consoleCLI.php
├── cronScheduleClean.php
├── customerRepository.php
├── deleteCategory.php
├── deleteCustomer.php
├── demo.php
├── emulateAreaCode.php
├── getSchedules.php
├── layerCategory.php
├── magento_cli.php
├── moveOrderToCustomer.php
├── removeAttribute.php
├── removeAttributeCategory.php
├── renameAttribute.php
├── renameAttributeCategory.php
├── rolesResources.php
├── salableQuantity.php
├── source_model.php
├── treeNode.php
├── unLockCustomer.php
├── updateConfig.php
├── updateNewSale.php
├── updateProduct.php
└── wysiwyg.php
/.gitignore:
--------------------------------------------------------------------------------
1 | # General
2 | .DS_Store
3 | .AppleDouble
4 | .LSOverride
5 |
6 | # Icon must end with two \r
7 | Icon
8 |
9 | # Thumbnails
10 | ._*
11 |
12 | # Files that might appear in the root of a volume
13 | .DocumentRevisions-V100
14 | .fseventsd
15 | .Spotlight-V100
16 | .TemporaryItems
17 | .Trashes
18 | .VolumeIcon.icns
19 | .com.apple.timemachine.donotpresent
20 |
21 | # Directories potentially created on remote AFP share
22 | .AppleDB
23 | .AppleDesktop
24 | Network Trash Folder
25 | Temporary Items
26 | .apdisk
--------------------------------------------------------------------------------
/DeleteProduct.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('DeleteProduct');
11 | $myClass->deleteProducts();
12 | return $this->_response;
13 | }
14 |
15 | }
16 |
17 |
18 | class DeleteProduct{
19 |
20 | protected $_objectManager;
21 | protected $_registry;
22 |
23 | /**
24 | * @var \Magento\Catalog\Model\ProductRepository
25 | */
26 | protected $productRepository;
27 |
28 | public function __construct(
29 | \Magento\Framework\Registry $registry,
30 | \Magento\Catalog\Model\ProductRepository $productRepository
31 | )
32 | {
33 | $this->_registry = $registry;
34 | $this->productRepository = $productRepository;
35 | $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
36 | }
37 |
38 | public function deleteProducts() {
39 |
40 | $this->_registry->register("isSecureArea", true);
41 |
42 | $productIds = ['400', '401'];
43 |
44 | $number = 0;
45 | foreach ($productIds as $id) {
46 | $this->productRepository->deleteById($id);
47 | $number++;
48 | }
49 |
50 | if ($number) {
51 | echo __('A total of %1 record(s) were deleted.', $number);
52 | }
53 | }
54 |
55 | }
56 |
57 | /** @var \Magento\Framework\App\Http $app */
58 | $app = $bootstrap->createApplication('Outslide');
59 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/Magicmenu.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
21 |
22 | $time_start = microtime(true);
23 |
24 | $menu = $this->_objectManager->create('\Magiccart\Magicmenu\Block\Menu');
25 | $menu->setTemplate('Magiccart_Magicmenu::aio-topmenu.phtml');
26 | $html = $menu->toHtml();
27 | echo $html;
28 |
29 | $time_end = microtime(true);
30 |
31 | //dividing with 60 will give the execution time in minutes otherwise seconds
32 | $execution_time = ($time_end - $time_start)/60;
33 | echo 'Execution time ' . $execution_time;
34 | return $this->_response;
35 | }
36 |
37 | }
38 |
39 | /** @var \Magento\Framework\App\Http $app */
40 | $app = $bootstrap->createApplication('MagentoCLI');
41 | $bootstrap->run($app);
42 |
--------------------------------------------------------------------------------
/ProductReview.php:
--------------------------------------------------------------------------------
1 | getReviewCollection();
19 |
20 | //the method must end with this line
21 | return $this->_response;
22 | }
23 |
24 | public function getReviewCollection()
25 | {
26 | $collections = $this->_objectManager->create('\Magento\Review\Model\ResourceModel\Review\Collection');
27 | $reviewProduct = $collections->addFieldToSelect('*')
28 | ->setPageSize(10) // only get 10 reviews
29 | ->setCurPage(1)
30 | ->setOrder('review_id', 'ASC');
31 |
32 | ?>
33 |
34 |
35 |
36 | review_id |
37 | entity_pk_value(Product ID) |
38 | title |
39 | detail |
40 | nickname |
41 | customer_id |
42 |
43 |
44 |
45 |
46 | ';
48 | // var_dump($review->toArray());
49 | echo '';
50 | ?>
51 |
52 | getData('review_id'); ?> |
53 | getData('entity_pk_value'); ?> |
54 | getData('title'); ?> |
55 | getData('detail'); ?> |
56 | getData('nickname'); ?> |
57 | getData('customer_id'); ?> |
58 |
59 |
60 |
61 |
62 | createApplication('reviewProduct');
69 | $bootstrap->run($app);
70 |
--------------------------------------------------------------------------------
/ProductReviewSummary.php:
--------------------------------------------------------------------------------
1 | getReviewCollection();
19 |
20 | //the method must end with this line
21 | return $this->_response;
22 | }
23 |
24 | public function getReviewCollection()
25 | {
26 | $collections = $this->_objectManager->create('\Magento\Review\Model\ResourceModel\Review\Summary\Collection');
27 | $reviewSummary = $collections->addFieldToSelect('entity_pk_value')
28 | ->setOrder('rating_summary', 'DESC')
29 | // ->setOrder('reviews_count', 'DESC')
30 | ->setPageSize(10) // only get 10 reviews
31 | ->setCurPage(1);
32 | // $reviewProduct = $reviewProduct->getSelect()->group('entity_pk_value');
33 | $reviewSummary->distinct(true);
34 | $productIds = [];
35 | foreach ($reviewSummary as $review){
36 | $productIds[] = $review->getData('entity_pk_value');
37 | }
38 | var_dump($productIds);
39 | ?>
40 |
41 |
42 |
43 | review_id |
44 | entity_pk_value(Product ID) |
45 | title |
46 | detail |
47 | nickname |
48 | customer_id |
49 |
50 |
51 |
52 |
53 | ';
55 | var_dump($review->toArray());
56 | echo '';
57 | ?>
58 |
59 |
60 |
61 |
62 | createApplication('reviewProduct');
69 | $bootstrap->run($app);
70 |
--------------------------------------------------------------------------------
/ProductSalableQuantity.php:
--------------------------------------------------------------------------------
1 | getObjectManager();
14 | $state = $objectManager->get('Magento\Framework\App\State');
15 | $state->setAreaCode('adminhtml');
16 | //Required for custom code ends
17 |
18 | setProductQty($objectManager);
19 |
20 | function setProductQty($objectManager)
21 | {
22 | $productCollection = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
23 | $productCollection->addAttributeToSelect(['name, sku']);
24 | $qty = 100;
25 | foreach ($productCollection as $product) {
26 | try {
27 | $productId = $product->getId();
28 | $stockModel = $objectManager->get('Magento\CatalogInventory\Model\Stock\ItemFactory')->create();
29 | $stockResource = $objectManager->get('Magento\CatalogInventory\Model\ResourceModel\Stock\Item');
30 | $stockResource->load($stockModel, $productId,"product_id");
31 | $stockModel->setQty($qty);
32 | $stockResource->save($stockModel);
33 | echo __("Successfully updated Qty for product SKU %1", $product->getSku()) . PHP_EOL;
34 | } catch (Exception $e) {
35 | echo $e->getMessage();
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/ProductSortQuantity.php:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 | Autoload error
23 |
24 | {$e->getMessage()}
25 |
26 | HTML;
27 | http_response_code(500);
28 | exit(1);
29 | }
30 |
31 |
32 | $bootstrap = Bootstrap::create(BP, $_SERVER);
33 | $objectManager = $bootstrap->getObjectManager();
34 | $state = $objectManager->get('Magento\Framework\App\State');
35 | $state->setAreaCode('frontend');
36 | //Required for custom code ends
37 |
38 | sortProductQty($objectManager);
39 |
40 | function sortProductQty($objectManager)
41 | {
42 | $stockFilter = $objectManager->create('\Magento\CatalogInventory\Helper\Stock');
43 |
44 | $collection = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create()
45 | ->addCategoriesFilter(['eq' => 26]);
46 | $collection->addAttributeToSelect('*');
47 | // $collection->setFlag('has_stock_status_filter', true);
48 | $collection = $collection->joinField('qty',
49 | 'cataloginventory_stock_item',
50 | 'qty',
51 | 'product_id=entity_id',
52 | '{{table}}.stock_id=1',
53 | 'left'
54 | )->joinTable('cataloginventory_stock_item', 'product_id = entity_id', ['stock_status' => 'is_in_stock'])
55 | ->addAttributeToSelect('stock_status')
56 | // ->addAttributeToSort('entity_id', 'DESC')
57 | ->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
58 | ->addAttributeToSort('qty', 'DESC')
59 | ->load();
60 |
61 |
62 | echo '';
63 | var_dump($collection->getData());
64 | echo '
';
65 | die;
66 | }
--------------------------------------------------------------------------------
/ProductSynchronizeMSI.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('Magento\Framework\App\State');
18 | $state->setAreaCode('adminhtml');
19 | $myClass = $this->_objectManager->create('ProductSalableQuantity');
20 | $myClass->updateSalableQuantity();
21 | return $this->_response;
22 | }
23 |
24 | }
25 |
26 |
27 | class ProductSalableQuantity
28 | {
29 |
30 |
31 | /**
32 | * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
33 | */
34 | protected $productCollectionFactory;
35 |
36 | /**
37 | * @var \Magento\InventoryCatalogApi\Model\SourceItemsProcessorInterface
38 | */
39 | protected $sourceItemsProcessor;
40 |
41 | public function __construct(
42 | \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
43 | \Magento\InventoryCatalogApi\Model\SourceItemsProcessorInterface $sourceItemsProcessor
44 | ) {
45 | $this->productCollectionFactory = $productCollectionFactory;
46 | $this->sourceItemsProcessor = $sourceItemsProcessor;
47 | }
48 |
49 | public function updateSalableQuantity() {
50 |
51 | $sourceData = [
52 | ['source_code'=>'default', 'status'=>1, 'quantity'=>50],
53 | ];
54 | $productsSKU = ['SRC081MASU'];
55 |
56 | $collection = $this->productCollectionFactory->create()
57 | ->joinField('qty',
58 | 'cataloginventory_stock_item',
59 | 'qty',
60 | 'product_id=entity_id',
61 | '{{table}}.stock_id=1',
62 | 'left'
63 | )->joinTable('cataloginventory_stock_item', 'product_id = entity_id', ['stock_status' => 'is_in_stock'])
64 | ->addAttributeToSelect('*')
65 | ->addAttributeToSelect('sku');
66 | if($productsSKU !== '*' && is_array($productsSKU)){
67 | $collection->addAttributeToFilter('sku', ['in' => $productsSKU]);
68 | }
69 | try {
70 | $total = 0;
71 | foreach ($collection as $product) {
72 | /* clone array */
73 | $data = array_merge($sourceData, []);
74 | foreach($data as $key => $source){
75 | $qty = (int) $product->getQty();
76 | $dataUpdate = [
77 | 'quantity' => $qty,
78 | 'status' => $qty ? 1: 0,
79 | ];
80 | $data[$key] = array_merge($source, $dataUpdate);
81 | }
82 | $sku = $product->getSku();
83 | $this->sourceItemsProcessor->execute(
84 | $sku,
85 | $data
86 | );
87 | $total++;
88 | }
89 |
90 | echo __("A total %1 product(s) synchronize salable quantity successfully.", $total) . PHP_EOL;
91 |
92 | } catch (Exception $e) {
93 | echo $e->getMessage();
94 | }
95 |
96 | }
97 |
98 | }
99 |
100 | /** @var \Magento\Framework\App\Http $app */
101 | $app = $bootstrap->createApplication('Outslide');
102 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [
](https://shopify.pxf.io/VyL446)
2 |
3 | ## Magento 2 programmatically
4 |
5 | Sometime you want run a simple task but don't want create an extension or add code or custom in source magento you can use a Magento 2 programmatically run outside.
6 |
7 | ### Highlight Features
8 | Add attribute, add attribute option, remove attribute product, remove attribute category, rename attribute, add cucstom option, add role, add schema, add user admin, apply layout category, apply layout page, apply to attribute, change type theme, flush cache, delete category, magento cli, get salable quantity, template processor update config, update product
9 |
10 |
11 | Visit our site [Magepow.com](https://magepow.com/)
12 |
13 | ### Detail User Guide
14 | * Copy code to root magento after go to your domain run this file exampe: domain.com/cacheflush.php
15 |
16 | ### Donation
17 |
18 | If this project help you reduce time to develop, you can give me a cup of coffee :)
19 |
20 | [](https://www.paypal.com/paypalme/alopay)
21 |
22 |
23 | **[Our Magento 2 Extensions](https://magepow.com/magento-2-extensions.html)**
24 |
25 | * [Magento 2 Recent Sales Notification](https://magepow.com/magento-2-recent-order-notification.html)
26 |
27 | * [Magento 2 Categories Extension](https://magepow.com/magento-categories-extension.html)
28 |
29 | * [Magento 2 Sticky Cart](https://magepow.com/magento-sticky-cart.html)
30 |
31 | * [Magento 2 Ajax Contact](https://magepow.com/magento-ajax-contact-form.html)
32 |
33 | * [Magento 2 Lazy Load](https://magepow.com/magento-lazy-load.html)
34 |
35 | * [Magento 2 Mutil Translate](https://magepow.com/magento-multi-translate.html)
36 |
37 | * [Magento 2 Instagram Integration](https://magepow.com/magento-2-instagram.html)
38 |
39 | * [Magento 2 Lookbook Pin Products](https://magepow.com/lookbook-pin-products.html)
40 |
41 | * [Magento 2 Product Slider](https://magepow.com/magento-product-slider.html)
42 |
43 | * [Magento 2 Product Banner](https://magepow.com/magento-2-banner-slider.html)
44 |
45 | **[Our Magento 2 services](https://magepow.com/magento-services.html)**
46 |
47 | * [PSD to Magento 2 Theme Conversion](https://alothemes.com/psd-to-magento-theme-conversion.html)
48 |
49 | * [Magento 2 Speed Optimization Service](https://magepow.com/magento-speed-optimization-service.html)
50 |
51 | * [Magento 2 Security Patch Installation](https://magepow.com/magento-security-patch-installation.html)
52 |
53 | * [Magento 2 Website Maintenance Service](https://magepow.com/website-maintenance-service.html)
54 |
55 | * [Magento 2 Professional Installation Service](https://magepow.com/professional-installation-service.html)
56 |
57 | * [Magento 2 Upgrade Service](https://magepow.com/magento-upgrade-service.html)
58 |
59 | * [Magento 2 Customization Service](https://magepow.com/customization-service.html)
60 |
61 | * [Hire Magento 2 Developer](https://magepow.com/hire-magento-developer.html)
62 |
63 | **[Our Magento 2 Themes](https://alothemes.com/)**
64 |
65 | * [Expert Multipurpose Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/expert-premium-responsive-magento-2-and-1-support-rtl-magento-2-/21667789)
66 |
67 | * [Gecko Premium Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/gecko-responsive-magento-2-theme-rtl-supported/24677410)
68 |
69 | * [Milano Fashion Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/milano-fashion-responsive-magento-1-2-theme/12141971)
70 |
71 | * [Electro 2 Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro2-premium-responsive-magento-2-rtl-supported/26875864)
72 |
73 | * [Electro Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro-responsive-magento-1-2-theme/17042067)
74 |
75 | * [Pizzaro Food responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/pizzaro-food-responsive-magento-1-2-theme/19438157)
76 |
77 | * [Biolife organic responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/biolife-organic-food-magento-2-theme-rtl-supported/25712510)
78 |
79 | * [Market responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/market-responsive-magento-2-theme/22997928)
80 |
81 | * [Kuteshop responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/kuteshop-multipurpose-responsive-magento-1-2-theme/12985435)
82 |
83 | * [Bencher - Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/bencher-responsive-magento-1-2-theme/15787772)
84 |
85 | * [Supermarket Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/supermarket-responsive-magento-1-2-theme/18447995)
86 |
87 | **[Our Shopify Themes](https://themeforest.net/user/alotheme)**
88 |
89 | * [Dukamarket - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/dukamarket-multipurpose-shopify-theme/36158349)
90 |
91 | * [Ohey - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/ohey-multipurpose-shopify-theme/34624195)
92 |
93 | * [Flexon - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/flexon-multipurpose-shopify-theme/33461048)
94 |
95 | **[Our Shopify App](https://apps.shopify.com/partners/maggicart)**
96 |
97 | * [Magepow Infinite Scroll](https://apps.shopify.com/magepow-infinite-scroll)
98 |
99 | * [Magepow Promotionbar](https://apps.shopify.com/magepow-promotionbar)
100 |
101 | * [Magepow Size Chart](https://apps.shopify.com/magepow-size-chart)
102 |
103 | **[Our WordPress Theme](https://themeforest.net/user/alotheme/portfolio)**
104 |
105 | * [SadesMarket - Multipurpose WordPress Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/sadesmarket-multipurpose-wordpress-theme/35369933)
106 |
--------------------------------------------------------------------------------
/TemplateProcessor.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
12 | // $this->_state->setAreaCode('adminhtml');
13 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
14 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
15 |
16 | $productRepository = $this->_objectManager->create('Magento\Catalog\Model\ProductRepository');
17 | $filterProvider = $this->_objectManager->create('Magento\Cms\Model\Template\FilterProvider');
18 | $storeManager = $this->_objectManager->create('Magento\Store\Model\StoreManagerInterface');
19 | // YOU WANT TO LOAD BY ID?
20 | $id = "YOUR ID HERE";
21 | // YOU WANT TO LOAD BY SKU?
22 | $sku = "YOUR SKU HERE";
23 |
24 | if($id) {
25 | $product = $productRepository->getById($id);
26 | }
27 | if($sku) {
28 | $product = $productRepository->get($sku);
29 | }
30 |
31 | $descriptionAttributeCode = "description";
32 | $storeId = $storeManager->getStore()->getId();
33 | $description = $product->setStoreId($storeId)->getData($descriptionAttributeCode);
34 | // echo $description;
35 | $html = $filterProvider->getBlockFilter()->setStoreId($storeId)->filter($description);
36 | echo $html;
37 | echo 'Done!';
38 | //the method must end with this line
39 | return $this->_response;
40 | }
41 | }
42 |
43 | /** @var \Magento\Framework\App\Http $app */
44 | $app = $bootstrap->createApplication('Outslide');
45 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/TemplateProcessorBlock.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
12 | // $this->_state->setAreaCode('adminhtml');
13 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
14 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
15 |
16 | $block = $this->_objectManager->create('\Magento\Cms\Model\Block');
17 | $filterProvider = $this->_objectManager->create('Magento\Cms\Model\Template\FilterProvider');
18 | $storeManager = $this->_objectManager->create('Magento\Store\Model\StoreManagerInterface');
19 |
20 | $blockId = 1; // Id of block you want get content
21 | $storeId = $storeManager->getStore()->getId();
22 | $block->setStoreId($storeId)->load($blockId);
23 | $content = $block->getContent();
24 | $html = $filterProvider->getBlockFilter()->setStoreId($storeId)->filter($content);
25 | echo $html;
26 | //the method must end with this line
27 | return $this->_response;
28 | }
29 | }
30 |
31 | /** @var \Magento\Framework\App\Http $app */
32 | $app = $bootstrap->createApplication('Outslide');
33 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/TemplateProcessorPage.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
12 | // $this->_state->setAreaCode('adminhtml');
13 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
14 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
15 |
16 | $page = $this->_objectManager->create('\Magento\Cms\Model\Page');
17 | $filterProvider = $this->_objectManager->create('Magento\Cms\Model\Template\FilterProvider');
18 | $storeManager = $this->_objectManager->create('Magento\Store\Model\StoreManagerInterface');
19 |
20 | $pageId = 1; // Id of Page you want get content
21 | $storeId = $storeManager->getStore()->getId();
22 | $page->setStoreId($storeId)->load($pageId);
23 | $content = $page->getContent();
24 | $html = $filterProvider->getBlockFilter()->setStoreId($storeId)->filter($content);
25 | echo $html;
26 | //the method must end with this line
27 | return $this->_response;
28 | }
29 | }
30 |
31 | /** @var \Magento\Framework\App\Http $app */
32 | $app = $bootstrap->createApplication('Outslide');
33 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/Topmenu.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
17 |
18 | $time_start = microtime(true);
19 |
20 |
21 | $menu = $this->_objectManager->create('\Magento\Theme\Block\Html\Topmenu');
22 | $menu->setTemplate('html/topmenu.phtml');
23 | $html = $menu->toHtml();
24 | echo $html;
25 |
26 | $time_end = microtime(true);
27 |
28 | //dividing with 60 will give the execution time in minutes otherwise seconds
29 | $execution_time = ($time_end - $time_start)/60;
30 |
31 | echo 'Execution time ' . $execution_time;
32 | return $this->_response;
33 | }
34 |
35 | }
36 |
37 | /** @var \Magento\Framework\App\Http $app */
38 | $app = $bootstrap->createApplication('MagentoCLI');
39 | $bootstrap->run($app);
40 |
--------------------------------------------------------------------------------
/UpdateOrder.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('adminhtml');
23 | $this->orderCollectionFactory = $this->_objectManager->get('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory');
24 | $this->orderRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderRepositoryInterface');
25 | $this->orderStatusRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderStatusHistoryRepositoryInterface');
26 | $this->logger = $this->_objectManager->create('\Psr\Log\LoggerInterface');
27 |
28 | $collection = $this->getOrderCollection();
29 | foreach ($collection as $order) {
30 | $this->updateOrder($order->getId());
31 | }
32 |
33 | echo __("Total update order update: %1 \n", $this->total);
34 |
35 | return $this->_response;
36 | }
37 |
38 | public function getOrderCollection()
39 | {
40 |
41 | $collection = $this->orderCollectionFactory->create()->addAttributeToSelect('*');
42 |
43 | return $collection;
44 | }
45 |
46 | public function updateOrder($orderId)
47 | {
48 | $order = null;
49 | try {
50 | $order = $this->orderRepository->get($orderId);
51 | } catch(NoSuchEntityException $exception) {
52 | $this->logger->error($exception->getMessage());
53 | }
54 |
55 | if ($order){
56 | $items = $order->getAllitems();
57 | foreach ($items as $item) {
58 | $options = $item->getProductOptions();
59 | if(!$options){
60 | // var_dump($options);
61 | // var_dump($item->getData('product_type'));
62 | $options = [
63 | "info_buyRequest" => [
64 | "uenc"=> "aHR0cHM6Ly9tZWRpY2FsLXRvb2xzLmNvbS9zaG9wL3ZldGVyaW5hcnktc3V0dXJlLWtpdC5odG1s",
65 | "id" => $item->getData('product_id'),
66 | "product" => $item->getData('product_id'),
67 | "selected_configurable_option" => '',
68 | "related_product" => '',
69 | "qty" => 1
70 | // "qty" => $item->getData('qty_ordered')
71 | ]
72 | ];
73 |
74 | $item->setProductOptions($options);
75 | // $item->save();
76 |
77 | }
78 | }
79 |
80 | try {
81 | $order->save();
82 | $this->total++;
83 | // echo __("Done update order Id: %1 \n", $order->getId());
84 | } catch(\Exception $exception){
85 | $this->logger->critical($exception->getMessage());
86 | }
87 | }
88 | }
89 |
90 | }
91 |
92 | /** @var \Magento\Framework\App\Http $app */
93 | $app = $bootstrap->createApplication('ZUpdateOrder');
94 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addAttribute.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
11 | $eavSetupFactory = $this->_objectManager->create('\Magento\Eav\Setup\EavSetupFactory');
12 | $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
13 |
14 | $eavSetup->addAttribute(
15 | \Magento\Catalog\Model\Product::ENTITY,
16 | 'test_attribute',
17 | [
18 | 'group' => 'General',
19 | 'type' => 'int',
20 | 'backend' => '',
21 | 'frontend' => '',
22 | 'label' => 'Test Attribute',
23 | 'input' => 'boolean',
24 | 'class' => '',
25 | 'source' => '',
26 | 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
27 | 'visible' => true,
28 | 'required' => false,
29 | 'user_defined' => true,
30 | 'default' => '',
31 | 'searchable' => false,
32 | 'filterable' => false,
33 | 'comparable' => false,
34 | 'visible_on_front' => false,
35 | 'used_in_product_listing' => true,
36 | 'unique' => false,
37 | 'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
38 | ]
39 | );
40 |
41 | echo 'Done!';
42 | //the method must end with this line
43 | return $this->_response;
44 | }
45 | }
46 |
47 | /** @var \Magento\Framework\App\Http $app */
48 | $app = $bootstrap->createApplication('Outslide');
49 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addAttributeFeatured.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
11 | $eavSetupFactory = $this->_objectManager->create('\Magento\Eav\Setup\EavSetupFactory');
12 | $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
13 |
14 | $eavSetup->addAttribute(
15 | \Magento\Catalog\Model\Product::ENTITY,
16 | 'featured',
17 | [
18 | 'group' => 'General',
19 | 'type' => 'int',
20 | 'backend' => '',
21 | 'frontend' => '',
22 | 'label' => 'Featured Product',
23 | 'input' => 'boolean',
24 | 'class' => '',
25 | 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
26 | 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
27 | 'visible' => true,
28 | 'required' => false,
29 | 'user_defined' => true,
30 | 'default' => '',
31 | 'searchable' => false,
32 | 'filterable' => false,
33 | 'comparable' => false,
34 | 'visible_on_front' => false,
35 | 'used_in_product_listing' => true,
36 | 'unique' => false,
37 | 'is_used_in_grid' => true,
38 | 'is_filterable_in_grid' => true,
39 | 'apply_to' => ''
40 | ]
41 | );
42 |
43 | echo 'Done!';
44 | //the method must end with this line
45 | return $this->_response;
46 | }
47 | }
48 |
49 | /** @var \Magento\Framework\App\Http $app */
50 | $app = $bootstrap->createApplication('Outslide');
51 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addAttributeOption.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
10 | $eavSetupFactory = $this->_objectManager->create('\Magento\Eav\Setup\EavSetupFactory');
11 | $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
12 |
13 | $attributeId = $eavSetup->getAttributeId('catalog_product', 'manufacturer');
14 | $options = [
15 | 'values' => [
16 | '1' => 'brand 1',
17 | '2' => 'brand 2',
18 | '3' => 'brand 3',
19 | ],
20 | 'attribute_id' => $attributeId ,
21 | ];
22 |
23 | $eavSetup->addAttributeOption($options);
24 |
25 | echo 'Done';
26 | //the method must end with this line
27 | return $this->_response;
28 | }
29 | }
30 |
31 | /** @var \Magento\Framework\App\Http $app */
32 | $app = $bootstrap->createApplication('Outslide');
33 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addCustomOptions.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('\Magento\Framework\App\State');
11 | $appState->setAreaCode('adminhtml');
12 |
13 | $productRepository = $this->_objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
14 | $optionFactory = $this->_objectManager->get('\Magento\Catalog\Model\Product\OptionFactory');
15 |
16 | $productIds = [
17 | 10,
18 | 25
19 | ];
20 |
21 | foreach ($productIds as $productId) {
22 | try{
23 | $_product = $productRepository->getById($productId);
24 | $optionsArray = [
25 | [
26 | 'title' => 'Select option',
27 | 'type' => 'drop_down',
28 | 'is_require' => 1,
29 | 'sort_order' => 1,
30 | 'values' => [
31 | [
32 | 'title' => 'Option 1',
33 | 'price' => 10,
34 | 'price_type' => 'fixed',
35 | 'sku' => 'Option 1 sku',
36 | 'sort_order' => 1,
37 | ],
38 | [
39 | 'title' => 'Option 2',
40 | 'price' => 10,
41 | 'price_type' => 'fixed',
42 | 'sku' => 'Option 2 sku',
43 | 'sort_order' => 2,
44 | ],
45 | [
46 | 'title' => 'Option 3',
47 | 'price' => 10,
48 | 'price_type' => 'fixed',
49 | 'sku' => 'Option 3 sku',
50 | 'sort_order' => 3,
51 | ],
52 | ],
53 | ]
54 | ];
55 |
56 | foreach ($optionsArray as $optionValue) {
57 | $option = $optionFactory->create()->setProductId($_product->getId())
58 | ->setStoreId($_product->getStoreId())
59 | ->addData($optionValue);
60 | $option->save();
61 | $_product->addOption($option);
62 | // must save product to add options in product
63 | $productRepository->save($_product);
64 | }
65 |
66 | } catch (\Exception $e) {
67 | echo $e->getMessage();
68 |
69 | }
70 |
71 | }
72 |
73 | echo 'Done!';
74 | //the method must end with this line
75 | return $this->_response;
76 | }
77 | }
78 |
79 | /** @var \Magento\Framework\App\Http $app */
80 | $app = $bootstrap->createApplication('Outslide');
81 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addInstallationOptions.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('\Magento\Framework\App\State');
11 | $appState->setAreaCode('adminhtml');
12 |
13 | $productRepository = $this->_objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
14 | $optionFactory = $this->_objectManager->get('\Magento\Catalog\Model\Product\OptionFactory');
15 |
16 | $productIds = [
17 | 10,
18 | 25
19 | ];
20 |
21 | foreach ($productIds as $productId) {
22 | try{
23 | $_product = $productRepository->getById($productId);
24 | $optionsArray = [
25 | [
26 | 'title' => 'Installation',
27 | 'type' => 'checkbox',
28 | 'is_require' => 0,
29 | 'sort_order' => 1,
30 | 'values' => [
31 | [
32 | 'title' => 'Yes',
33 | 'price' => 39,
34 | 'price_type' => 'fixed',
35 | 'sku' => 'installation',
36 | 'sort_order' => 1,
37 | ]
38 | ],
39 | ]
40 | ];
41 |
42 | foreach ($optionsArray as $optionValue) {
43 | $option = $optionFactory->create()->setProductId($_product->getId())
44 | ->setStoreId($_product->getStoreId())
45 | ->addData($optionValue);
46 | $option->save();
47 | $_product->addOption($option);
48 | // must save product to add options in product
49 | $productRepository->save($_product);
50 | }
51 |
52 | } catch (\Exception $e) {
53 | echo $e->getMessage();
54 |
55 | }
56 |
57 | }
58 |
59 | echo 'Done!';
60 | //the method must end with this line
61 | return $this->_response;
62 | }
63 | }
64 |
65 | /** @var \Magento\Framework\App\Http $app */
66 | $app = $bootstrap->createApplication('Outslide');
67 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addOrderComment.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('adminhtml');
24 | $this->orderRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderRepositoryInterface');
25 | $this->orderStatusRepository = $this->_objectManager->create('\Magento\Sales\Api\OrderStatusHistoryRepositoryInterface');
26 | $this->logger = $this->_objectManager->create('\Psr\Log\LoggerInterface');
27 |
28 | $order = null;
29 | $orderId = 10;
30 | try {
31 | $order = $this->orderRepository->get($orderId);
32 | } catch(NoSuchEntityException $exception) {
33 | $this->logger->error($exception->getMessage());
34 | }
35 |
36 | $orderHistory = null;
37 |
38 | if ($order){
39 | $comment = $order->addStatusHistoryComment('Comment for the order');
40 | try {
41 | $orderHistory = $this->orderStatusRepository->save($comment);
42 | } catch(\Exception $exception){
43 | $this->logger->critical($exception->getMessage());
44 | }
45 | }
46 |
47 | echo 'Done save order comment!';
48 | //the method must end with this line
49 | return $this->_response;
50 | }
51 |
52 | }
53 |
54 | /** @var \Magento\Framework\App\Http $app */
55 | $app = $bootstrap->createApplication('savComment');
56 | $bootstrap->run($app);
57 |
--------------------------------------------------------------------------------
/addRole.php:
--------------------------------------------------------------------------------
1 |
8 | * @@Create Date: 2018-03-20 21:14:06
9 | * @@Modify Date: 2018-05-31 10:17:23
10 | * @@Function:
11 | */
12 |
13 | //// Setup Base
14 | $folder = ''; //Folder Name
15 | $file = $folder ? "$folder/app/bootstrap.php" : "app/bootstrap.php";
16 |
17 | if(!file_exists ($file)) $file = "app/bootstrap.php";
18 | if(file_exists ($file)){
19 | require dirname(__FILE__) .'/' .$file;
20 | $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
21 | } else {die('Not found bootstrap.php');}
22 |
23 | /* For get RoleType and UserType for create Role */;
24 | use Magento\Authorization\Model\Acl\Role\Group as RoleGroup;
25 | use Magento\Authorization\Model\UserContextInterface;
26 |
27 | class createRole extends \Magento\Framework\App\Http
28 | implements \Magento\Framework\AppInterface {
29 |
30 | /**
31 | * userFactory
32 | *
33 | * @var userFactory
34 | */
35 | private $userFactory;
36 |
37 | /**
38 | * RoleFactory
39 | *
40 | * @var roleFactory
41 | */
42 | private $roleFactory;
43 |
44 | /**
45 | * RulesFactory
46 | *
47 | * @var rulesFactory
48 | */
49 | private $rulesFactory;
50 |
51 |
52 | public function launch()
53 | {
54 | $this->userFactory = $this->_objectManager->get('\Magento\User\Model\UserFactory');
55 | $this->roleFactory = $this->_objectManager->get('\Magento\Authorization\Model\RoleFactory');
56 | $this->rulesFactory = $this->_objectManager->get('\Magento\Authorization\Model\RulesFactory');
57 |
58 | /**
59 | * Create Warehouse role
60 | */
61 | $role = $this->roleFactory->create();
62 | $role->setName('Demo Rule') //Set Role Name Which you want to create
63 | ->setPid(0) //set parent role id of your role
64 | ->setRoleType(RoleGroup::ROLE_TYPE)
65 | ->setUserType(UserContextInterface::USER_TYPE_ADMIN);
66 | $role->save();
67 | /* Now we set that which resources we allow to this role */
68 | $resource=['Magento_Backend::admin',
69 | 'Magento_Sales::sales',
70 | 'Magento_Sales::create',
71 | 'Magento_Sales::actions_view', //you will use resource id which you want tp allow
72 | 'Magento_Sales::cancel'
73 | ];
74 | /* Array of resource ids which we want to allow this role*/
75 | $this->rulesFactory->create()->setRoleId($role->getId())->setResources($resource)->saveRel();
76 |
77 | $user = $this->userFactory->create()->loadByUsername('demo');
78 | $user->setRoleId($role->getId());
79 | $user->save();
80 |
81 | echo 'done';
82 | return $this->_response;
83 | }
84 |
85 | }
86 |
87 | /** @var \Magento\Framework\App\Http $app */
88 | $app = $bootstrap->createApplication('createRole');
89 | $bootstrap->run($app);
90 |
--------------------------------------------------------------------------------
/addSchema.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Setup\Module\Setup');
13 |
14 | $installer->startSetup();
15 |
16 | $table = $installer->getConnection()
17 | ->newTable($installer->getTable('magepow_comments'))
18 | ->addColumn(
19 | 'comment_id',
20 | Table::TYPE_INTEGER,
21 | null,
22 | ['identity' => true, 'nullable' => false, 'primary' => true],
23 | 'Comment ID'
24 | )
25 | ->addColumn('title', Table::TYPE_TEXT, 255, ['nullable' => true, 'default' => null], 'Title')
26 | ->addColumn('status', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '1'], 'Status')
27 | ->addColumn('store', Table::TYPE_TEXT, 255, ['nullable' => true, 'default' => '0'])
28 | ->addColumn('created_time', Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created Time')
29 | ->addColumn('update_time', Table::TYPE_DATETIME, null, ['nullable' => true, 'default' => null], 'Update Time')
30 | ->addIndex($installer->getIdxName('comment_id', ['comment_id']), ['comment_id'])
31 | ->setComment('Magepow Comments');
32 |
33 | $installer->getConnection()->createTable($table);
34 |
35 | $installer->endSetup();
36 |
37 | echo 'Done!';
38 | //the method must end with this line
39 | return $this->_response;
40 | }
41 | }
42 |
43 | /** @var \Magento\Framework\App\Http $app */
44 | $app = $bootstrap->createApplication('Outslide');
45 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addSchemaModule.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magepow\ModuleName\Setup\InstallSchema');
11 | $context = $this->_objectManager->create('\Magento\Setup\Model\ModuleContext', ['version' => '1.0.0']);
12 | $setup = $this->_objectManager->create('\Magento\Setup\Module\Setup');
13 | $installSchema->install($setup, $context);
14 |
15 | echo 'Done!';
16 | //the method must end with this line
17 | return $this->_response;
18 | }
19 | }
20 |
21 | /** @var \Magento\Framework\App\Http $app */
22 | $app = $bootstrap->createApplication('Outslide');
23 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/addUserAdmin.php:
--------------------------------------------------------------------------------
1 | _userFactory = $this->_objectManager->get('\Magento\User\Model\UserFactory');
36 |
37 | $adminInfo = [
38 | 'username' => 'hello',
39 | 'firstname' => 'Hello',
40 | 'lastname' => 'Mage',
41 | 'email' => 'hello@magepow.com',
42 | 'password' =>'hello@123',
43 | 'interface_locale' => 'en_US',
44 | 'is_active' => 1
45 | ];
46 |
47 | $userModel = $this->_userFactory->create();
48 | $userModel->setData($adminInfo);
49 | $userModel->setRoleId(1);
50 | try{
51 | $userModel->save();
52 | echo 'done';
53 | } catch (\Exception $ex) {
54 | $ex->getMessage();
55 | }
56 | return $this->_response;
57 | }
58 |
59 |
60 | }
61 |
62 | /** @var \Magento\Framework\App\Http $app */
63 | $app = $bootstrap->createApplication('createAdmin');
64 | $bootstrap->run($app);
65 |
--------------------------------------------------------------------------------
/adminCategoryTree.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
54 |
55 | $adminCategoryTree = $this->_objectManager->get('\Magento\Catalog\Block\Adminhtml\Category\Tree');
56 | echo '';
57 | var_dump($adminCategoryTree->getTree());
58 | echo '
';
59 |
60 | return $this->_response;
61 | }
62 |
63 |
64 |
65 |
66 | }
67 |
68 |
69 | /** @var \Magento\Framework\App\Http $app */
70 | $app = $bootstrap->createApplication('CategoryTree');
71 | $bootstrap->run($app);
72 |
--------------------------------------------------------------------------------
/appLayoutCategpry.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('\Magento\Framework\App\State');
16 |
17 | $appState->setAreaCode('frontend');
18 |
19 | $categoryCollection = $this->_objectManager->get('\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
20 |
21 | $categories = $categoryCollection->create();
22 |
23 | $categories->addAttributeToSelect('*');
24 |
25 | $categories->load();
26 |
27 | if (count($categories) > 0):
28 | foreach($categories as $category):
29 | $catId = $category->getId();
30 | $category = $this->_objectManager->create('Magento\Catalog\Model\CategoryFactory')->create()->setStoreId(0)->load($catId);
31 | $category->setData('custom_use_parent_settings', '0')->setData('custom_design', '');
32 | $category->save();
33 | echo 'Update ' . $category->getName() . '
';
34 | endforeach;
35 | else: echo "No Results";
36 | endif;
37 |
38 | echo 'Done update layout page';
39 |
40 | //the method must end with this line
41 | return $this->_response;
42 | }
43 |
44 | }
45 |
46 | /** @var \Magento\Framework\App\Http $app */
47 | $app = $bootstrap->createApplication('Outslide');
48 | $bootstrap->run($app);
49 |
--------------------------------------------------------------------------------
/appLayoutPage.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('Magento\Cms\Model\Page');
19 | $model->load($pageId); // Id of page
20 | $pageData = [
21 | // 'title' => "title page",
22 | // 'page_layout' => "page_layout type",
23 | // 'identifier' => "identifier",
24 | // 'content_heading' => "content_heading text",
25 | // 'content' => "Content Text",
26 | 'layout_update_xml' => '
27 |
28 |
29 |
30 | static-home-slide
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | static_sections_bottom
39 |
40 |
41 | ',
42 | 'is_active' => 1
43 | ];
44 | $model->addData( $pageData )->save();
45 |
46 | echo 'Done update layout page';
47 |
48 |
49 | //the method must end with this line
50 | return $this->_response;
51 | }
52 |
53 | }
54 |
55 | /** @var \Magento\Framework\App\Http $app */
56 | $app = $bootstrap->createApplication('Outslide');
57 | $bootstrap->run($app);
58 |
--------------------------------------------------------------------------------
/appTheme.php:
--------------------------------------------------------------------------------
1 | showTableTheme();
14 |
15 | $collections = $this->_objectManager->create('Magento\Theme\Model\Theme');
16 | $themes = $collections->getCollection()->addFieldToSelect('*');
17 | foreach ($themes as $theme) {
18 | $id = $theme->getData('theme_id');
19 | $this->setType($id);
20 | }
21 |
22 | // $this->setParent(5, 4);
23 | //
24 | // $themesCollections = $this->_objectManager->create('Magento\Theme\Model\Theme\Collection');
25 | // $themesCollections->addConstraint(Collection::CONSTRAINT_AREA, Area::AREA_FRONTEND);
26 | // $themes = [];
27 | // $themesCollections = $this->_objectManager->create('Magento\Framework\View\Design\Theme\ListInterface');
28 |
29 | //the method must end with this line
30 | return $this->_response;
31 | }
32 |
33 | public function showTableTheme()
34 | {
35 | $collections = $this->_objectManager->create('Magento\Theme\Model\Theme');
36 | $themes = $collections->getCollection()->addFieldToSelect('*');
37 |
38 | ?>
39 |
40 |
41 |
42 | theme_id |
43 | parent_id |
44 | theme_path |
45 | theme_title |
46 | preview_image |
47 | is_featured |
48 | area |
49 | type |
50 | code |
51 |
52 |
53 |
54 |
55 | toArray());
57 | ?>
58 |
59 | getData('theme_id'); ?> |
60 | getData('parent_id'); ?> |
61 | getData('theme_path'); ?> |
62 | getData('theme_title'); ?> |
63 | getData('preview_image'); ?> |
64 | getData('is_featured'); ?> |
65 | getData('area'); ?> |
66 | getData('type'); ?> |
67 | getData('code'); ?> |
68 |
69 |
70 |
71 |
72 |
73 | _objectManager->create('Magento\Theme\Model\Theme');
79 | try {
80 | $theme->load($id, 'theme_id');
81 | $theme->setType(0);
82 | $theme->save();
83 | echo 'done';
84 | } catch (\Exception $e) {
85 | $this->messageManager->addError(__('Can\'t create child theme error "%1"', $e->getMessage()));
86 | }
87 | }
88 |
89 | public function setParent($id, $parentId)
90 | {
91 | $theme = $this->_objectManager->create('Magento\Theme\Model\Theme');
92 | try {
93 | $theme->load($id, 'theme_id');
94 | $theme->setData('parent_id', $parentId);
95 | $theme->save();
96 | echo 'done';
97 | } catch (\Exception $e) {
98 | $this->messageManager->addError(__('Can\'t create child theme error "%1"', $e->getMessage()));
99 | }
100 | }
101 |
102 | }
103 |
104 | /** @var \Magento\Framework\App\Http $app */
105 | $app = $bootstrap->createApplication('Outslide');
106 | $bootstrap->run($app);
107 |
--------------------------------------------------------------------------------
/apply_to_attribute.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('Magento\Framework\App\ResourceConnection');
10 | $connection = $resource->getConnection();
11 | $eavAttribute = $resource->getTableName('eav_attribute'); //gives table name with prefix
12 |
13 | //Select Data from table
14 | $sql = "SELECT attribute_id FROM " . $eavAttribute . " WHERE attribute_code='manufacturer'";
15 |
16 | $manufacturerID = $connection->fetchOne($sql); // gives associated array, table fields as key in array.
17 | echo 'manufacturerID is: ' . $manufacturerID ;
18 |
19 | if($manufacturerID){
20 | $catalogEavAttribute = $resource->getTableName('catalog_eav_attribute'); //gives table name with prefix
21 |
22 | "UPDATE " . $catalogEavAttribute . " SET apply_to ='simple,virtual,bundle,downloadable,configurable' WHERE attribute_id ='" . $manufacturerID . "'";
23 | $connection->query($sql);
24 | }
25 |
26 | echo 'Update Done';
27 | //the method must end with this line
28 | return $this->_response;
29 | }
30 | }
31 |
32 | /** @var \Magento\Framework\App\Http $app */
33 | $app = $bootstrap->createApplication('Outslide');
34 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/cacheflush.php:
--------------------------------------------------------------------------------
1 | getObjectManager();
9 |
10 |
11 | try{
12 | $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
13 | $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
14 | $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
15 | foreach ($types as $type) {
16 | $_cacheTypeList->cleanType($type);
17 | }
18 | foreach ($_cacheFrontendPool as $cacheFrontend) {
19 | $cacheFrontend->getBackend()->clean();
20 | }
21 | }catch(Exception $e){
22 | echo $msg = 'Error : '.$e->getMessage();die();
23 | }
--------------------------------------------------------------------------------
/categoryProduct.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
15 | $category = $this->_objectManager->create('Magento\Catalog\Model\Category');
16 | $_coreRegistry = $this->_objectManager->get('Magento\Framework\Registry');
17 | $catalogConfig = $this->_objectManager->create('\Magento\Catalog\Model\Config');
18 | $productVisibility = $this->_objectManager->create('\Magento\Catalog\Model\Product\Visibility');
19 | $curentCategory = $_coreRegistry->registry('current_category');
20 | $categoryId = 256;
21 | if ($curentCategory){
22 | $categoryId = $curentCategory->getId();
23 | }else {
24 | $product = $_coreRegistry->registry('current_product');
25 | if($product){
26 | // get collection of categories this product is associated with
27 | $categories = $product->getCategoryCollection()->setPage(1, 1)->load();
28 | // if the product is associated with any category
29 | if ($categories->count()) {
30 | // show products from this category
31 | $categoryId = current($categories->getIterator())->getId();
32 | }
33 | }
34 | }
35 | if ($categoryId) {
36 | $category->load($categoryId);
37 | # Get _productCollection random
38 | $_productCollection = $category->getProductCollection()
39 | ->addAttributeToSelect($catalogConfig->getProductAttributes())
40 | ->addMinimalPrice()
41 | ->addFinalPrice()
42 | ->addTaxPercents()
43 | ->addUrlRewrite($categoryId)
44 | ->setVisibility($productVisibility->getVisibleInCatalogIds())
45 | ->addStoreFilter()
46 | ->setPageSize(10)
47 | ->setCurPage(1);
48 |
49 | $_productCollection->getSelect()->order('rand()');
50 | echo __('This category have %1 products!', $_productCollection->count());
51 | } else {
52 | echo __('This category not exist!');
53 | }
54 | //the method must end with this line
55 | return $this->_response;
56 | }
57 |
58 | }
59 |
60 | /** @var \Magento\Framework\App\Http $app */
61 | $app = $bootstrap->createApplication('Outside');
62 | $bootstrap->run($app);
63 |
--------------------------------------------------------------------------------
/consoleCLI.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('RunCLI');
17 | $myClass->execute();
18 | return $this->_response;
19 | }
20 |
21 | }
22 |
23 |
24 | class RunCLI
25 | {
26 |
27 | private $logger;
28 |
29 | public function __construct(LoggerInterface $logger)
30 | {
31 | $this->logger = $logger;
32 | }
33 |
34 | public function execute()
35 | {
36 | $application = new Cli('Magento CLI');
37 | $input = new ArrayInput([
38 | 'command' => 'cache:flush',
39 | ]);
40 | /* use NullOutput if don't want show output */
41 | $output = new NullOutput();
42 |
43 | /* use NullOutput if want show output in command line */
44 | $output = new ConsoleOutput();
45 |
46 | try {
47 | $application->run($input, $output);
48 | } catch (\Exception $exception) {
49 | $this->logger->critical('Cache Flush failed.', ['exception' => $exception]);
50 | }
51 | }
52 | }
53 |
54 |
55 | /** @var \Magento\Framework\App\Http $app */
56 | $app = $bootstrap->createApplication('Outslide');
57 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/cronScheduleClean.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('Magento\Framework\App\State');
11 | $appState->setAreaCode('adminhtml');
12 | $resource = $this->_objectManager->get('Magento\Framework\App\ResourceConnection');
13 | $connection = $resource->getConnection();
14 | $tableName = $resource->getTableName('cron_schedule');
15 |
16 | $sql = "DELETE FROM " . $tableName . " WHERE created_at < DATE_SUB(NOW(), INTERVAL 1 DAY)";
17 |
18 | try{
19 | $result = $connection->query($sql);
20 | }catch(Exception $ex){
21 | print_r($ex);
22 | }
23 |
24 | return $this->_response;
25 | }
26 | }
27 |
28 | /** @var \Magento\Framework\App\Http $app */
29 | $app = $bootstrap->createApplication('Outslide');
30 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/customerRepository.php:
--------------------------------------------------------------------------------
1 |
8 | * @@Create Date: 2018-03-20 21:14:06
9 | * @@Modify Date: 2018-05-31 10:17:23
10 | * @@Function:
11 | */
12 | ini_set('display_startup_errors', 1);ini_set('display_errors', 1); error_reporting(-1);
13 | //// Setup Base
14 | ini_set('max_execution_time', 900000000);
15 |
16 | $folder = 'orfarm'; //Folder Name
17 | $file = $folder ? dirname(__FILE__) . "/$folder/app/bootstrap.php" : "app/bootstrap.php";
18 | $file = str_replace('.com/', '.coms/', $file);
19 | $file = str_replace('/public_html/', '/public_htmls/', $file);
20 |
21 | if(!file_exists ($file)) $file = "app/bootstrap.php";
22 | if(file_exists ($file)){
23 | require $file;
24 | $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
25 | } else {die('Not found bootstrap.php');}
26 |
27 |
28 | use Magento\Customer\Model\CustomerRegistry;
29 |
30 | class AccountManagement extends \Magento\Framework\App\Http
31 | implements \Magento\Framework\AppInterface {
32 |
33 | /**
34 | * @var CustomerRepositoryInterface
35 | */
36 | private $customerRepository;
37 |
38 | /**
39 | * @param CustomerRegistry
40 | */
41 |
42 | private $customerRegistry;
43 |
44 | public function launch()
45 | {
46 |
47 | $this->customerRegistry = $this->_objectManager->get(
48 | \Magento\Customer\Model\CustomerRegistry::class
49 | );
50 |
51 | $this->customerRepository = $this->_objectManager->get(
52 | \Magento\Customer\Api\CustomerRepositoryInterface::class,
53 | ['customerRegistry' => $this->customerRegistry]
54 | );
55 |
56 | echo 'Create customerRepository with customerRegistry';
57 |
58 |
59 | return $this->_response;
60 | }
61 |
62 | }
63 |
64 | /** @var \Magento\Framework\App\Http $app */
65 | $app = $bootstrap->createApplication('AccountManagement');
66 | $bootstrap->run($app);
67 |
--------------------------------------------------------------------------------
/deleteCategory.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('Magento\Catalog\Model\CategoryFactory');
12 | $_MyClass = $this->_objectManager->create('DeleteCategory');
13 | $_MyClass->deleteCategories($ids);
14 | return $this->_response;
15 | }
16 | }
17 |
18 |
19 | class DeleteCategory{
20 |
21 | protected $_objectManager;
22 | protected $_registry;
23 |
24 | public function __construct(
25 | \Magento\Framework\Registry $registry
26 | )
27 | {
28 | $this->_registry = $registry;
29 | $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
30 | }
31 |
32 | public function deleteCategories($ids = array()) {
33 | $categoryFactory = $this->_objectManager->get('Magento\Catalog\Model\CategoryFactory');
34 | $categories = $categoryFactory->create();
35 | $collection = $categories->getCollection()->addAttributeToSelect('name');
36 | $this->_registry->register("isSecureArea", true);
37 | foreach($collection as $category) {
38 | if(is_array($ids) && in_array($category->getId(), $ids))
39 | {
40 | $category->delete();
41 | echo 'category ' . $category->getName() . ' deleted';
42 | } else if($category->getId() == $ids) {
43 | $category->delete();
44 | echo 'category ' . $category->getName() . ' deleted';
45 | }
46 | }
47 | }
48 |
49 | }
50 |
51 | /** @var \Magento\Framework\App\Http $app */
52 | $app = $bootstrap->createApplication('Outslide');
53 | $bootstrap->run($app);
54 |
--------------------------------------------------------------------------------
/deleteCustomer.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('DeleteCustomer');
14 | $myClass->deleteCustomers();
15 | return $this->_response;
16 | }
17 |
18 | }
19 |
20 |
21 | class DeleteCustomer{
22 |
23 | protected $_objectManager;
24 | protected $_registry;
25 |
26 | /**
27 | * @var CustomerRepositoryInterface
28 | */
29 | protected $customerRepository;
30 |
31 | public function __construct(
32 | \Magento\Framework\Registry $registry,
33 | CollectionFactory $collectionFactory,
34 | CustomerRepositoryInterface $customerRepository
35 | )
36 | {
37 | $this->_registry = $registry;
38 | $this->customerRepository = $customerRepository;
39 | $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
40 | }
41 |
42 | public function deleteCustomers() {
43 |
44 | $this->_registry->register("isSecureArea", true);
45 |
46 | $limit = 10000;
47 | $collection = $this->_objectManager->create('\Magento\Customer\Model\Customer');
48 | $customers = $collection->getCollection()
49 | ->addAttributeToFilter("email", ["like" => "%@qq.com"])
50 | ->addAttributeToSort('entity_id', 'DESC')
51 | // ->addAttributeToFilter("email", ["like" => "%@sina.com"])
52 | // ->addAttributeToFilter("email", ["like" => "%@yahoo.com.cn"])
53 | // ->addAttributeToFilter("email", ["like" => "%@163.com"])
54 | // ->addAttributeToFilter("email", ["like" => "%@139.com"])
55 | // ->addAttributeToFilter("email", ["like" => "%@126.com"])
56 | // ->addAttributeToFilter("firstname", ["like" => "%www.%"])
57 | // ->addAttributeToFilter("firstname", ["like" => "%http.%"])
58 | // ->addAttributeToFilter("lastname", ["like" => "%dkhdeiqknp%"])
59 | ->setPageSize($limit)->setCurPage(1);
60 |
61 | $customersDeleted = 0;
62 | foreach ($customers as $customer) {
63 | $this->customerRepository->deleteById($customer->getId());
64 | $customersDeleted++;
65 | }
66 |
67 | if ($customersDeleted) {
68 | echo __('A total of %1 record(s) were deleted.', $customersDeleted);
69 | }
70 | }
71 |
72 | }
73 |
74 | /** @var \Magento\Framework\App\Http $app */
75 | $app = $bootstrap->createApplication('Outslide');
76 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/demo.php:
--------------------------------------------------------------------------------
1 | _integrationData = $this->_objectManager->create('\Magento\Integration\Helper\Data');
81 | $this->_rootResource = $this->_objectManager->create('\Magento\Framework\Acl\RootResource');
82 | $this->_aclResourceProvider = $this->_objectManager->create('\Magento\Framework\Acl\AclResource\ProviderInterface');
83 | $this->_rulesCollectionFactory = $this->_objectManager->create('\Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory');
84 |
85 | $this->_roleFactory = $this->_objectManager->get('\Magento\Authorization\Model\RoleFactory');
86 | $this->_rulesFactory = $this->_objectManager->get('\Magento\Authorization\Model\RulesFactory');
87 | $this->_userFactory = $this->_objectManager->get('\Magento\User\Model\UserFactory');
88 |
89 | $role = $this->createRole('Demo Rule');
90 |
91 | $resources = $this->_aclResourceProvider->getAclResources();
92 |
93 |
94 | $denyResource = [
95 | 'Magento_Backend::myaccount',
96 | 'Magento_AdobeIms::login',
97 | 'Magento_Backup::rollback',
98 | 'Magento_User::acl',
99 | 'Magento_User::acl_roles',
100 | 'Magento_User::locks',
101 | 'Magento_Backup::backup',
102 | 'Magento_AdobeIms::actions',
103 | 'Magento_User::acl_users',
104 | 'Magento_AdobeIms::adobe_ims',
105 | 'Magento_Backend::all',
106 | 'Magento_AdobeIms::logout',
107 | 'Magento_AdobeIms::adobe_ims',
108 | // custom module
109 | 'Nans_AutoLogin::main',
110 | 'Nans_AutoLogin::config'
111 | ];
112 |
113 | $resourcesTree = $this->_aclResourceProvider->getAclResources();
114 | $resources = $this->getValueAclResources($resourcesTree);
115 | foreach ($resources as $key => $value) {
116 | if(in_array($value, $denyResource)) unset($resources[$key]);
117 | }
118 |
119 | /* Array of resources ids which we want to allow this role*/
120 | $this->_rulesFactory->create()->setRoleId($role->getId())->setResources($resources)->saveRel();
121 |
122 | $adminInfo = [
123 | 'username' => 'demo',
124 | 'firstname' => 'Demo',
125 | 'lastname' => 'Mage',
126 | 'email' => 'demo@example.com',
127 | 'password' =>'admin123',
128 | 'interface_locale' => 'en_US',
129 | 'is_active' => 1
130 | ];
131 |
132 | $user = $this->createUser($adminInfo, $role->getId());
133 | var_dump($user->getData());
134 | echo 'Run finished';
135 |
136 | return $this->_response;
137 | }
138 |
139 | public function createRole($name, $uniqueName=true)
140 | {
141 | $role = $this->_roleFactory->create();
142 | if($uniqueName){
143 | $collection = $role->getCollection()->addFieldToFilter('role_name', $name);
144 | if($collection->getSize()){
145 | return $collection->getFirstItem();
146 | }
147 | }
148 | $role->setName($name) //Set Role Name Which you want to create
149 | ->setPid(0) //set parent role id of your role
150 | ->setRoleType(RoleGroup::ROLE_TYPE)
151 | ->setUserType(UserContextInterface::USER_TYPE_ADMIN);
152 | $role->save();
153 | return $role;
154 | }
155 |
156 | public function createUser($userInfo, $roleId=1, $update=true)
157 | {
158 | $user = $this->_userFactory->create();
159 | if(!isset($userInfo['username'])) return __('The username is require.');
160 |
161 | $user->loadByUsername($userInfo['username']);
162 | if( $user->getId() ){
163 | if($update) $user->addData($userInfo)->save();
164 | } else {
165 | $user->setData($userInfo);
166 | $user->setRoleId($roleId);
167 | try{
168 | $user->save();
169 | } catch (\Exception $ex) {
170 | $ex->getMessage();
171 | }
172 | }
173 | return $user;
174 | }
175 |
176 | public function getUserAclResources($userId)
177 | {
178 |
179 | }
180 |
181 | public function getValueAclResources($resources, $dataArray=[])
182 | {
183 | foreach ($resources as $value) {
184 | if(!isset($value['id'])) continue;
185 | $dataArray[] = $value['id'];
186 | if(isset($value['children'])){
187 | /* Keep tree */
188 | // $dataArray[] = $this->getValueAclResources($value['children'], $dataArray);
189 | $dataArray = $this->getValueAclResources($value['children'], $dataArray);
190 |
191 | }
192 | }
193 | return $dataArray;
194 | }
195 |
196 | /**
197 | * Get Json Representation of Resource Tree
198 | *
199 | * @return array
200 | */
201 | public function getTree()
202 | {
203 | return $this->_integrationData->mapResources($this->getAclResources());
204 | }
205 |
206 | /**
207 | * Get lit of all ACL resources declared in the system.
208 | *
209 | * @return array
210 | */
211 | private function getAclResources()
212 | {
213 | $resources = $this->_aclResourceProvider->getAclResources();
214 | $configResource = array_filter(
215 | $resources,
216 | function ($node) {
217 | return isset($node['id'])
218 | && $node['id'] == 'Magento_Backend::admin';
219 | }
220 | );
221 | $configResource = reset($configResource);
222 | return isset($configResource['children']) ? $configResource['children'] : [];
223 | }
224 |
225 |
226 | }
227 |
228 | /** @var \Magento\Framework\App\Http $app */
229 | $app = $bootstrap->createApplication('createDemoAdmin');
230 | $bootstrap->run($app);
231 |
--------------------------------------------------------------------------------
/emulateAreaCode.php:
--------------------------------------------------------------------------------
1 | get('Magento\Framework\App\State');
16 | $field = $appState->emulateAreaCode('adminhtml', function($path){
17 | $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
18 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
19 | $appState = $objectManager->get('Magento\Framework\App\State');
20 | $appState->setAreaCode('adminhtml');
21 | $field = $objectManager->create('Magento\Config\Model\Config\Structure')
22 | ->getElementByConfigPath($path);
23 | return $field;
24 | }, ['customer/create_account/auto_group_assign']);
25 |
26 | echo $field->getData()['source_model'];
27 |
28 | return $this->_response;
29 | }
30 |
31 |
32 | }
33 |
34 | /** @var \Magento\Framework\App\Http $app */
35 | $app = $bootstrap->createApplication('changeConfig');
36 | $bootstrap->run($app);
37 |
--------------------------------------------------------------------------------
/getSchedules.php:
--------------------------------------------------------------------------------
1 | setTime;
44 | $dt = new DateTime();
45 | // $dt = new DateTime('2017-01-01');
46 | $this->todayStartOfDayDate = $dt->setTime(0, 0, 0)->format('Y-m-d H:i:s');
47 | $this->todayEndOfDayDate = $dt->setTime(23, 59, 59)->format('Y-m-d H:i:s');
48 |
49 |
50 | // $this->_state->setAreaCode('adminhtml');
51 |
52 | // $_storeManager = $this->_objectManager->create('\Magento\Store\Model\StoreManagerInterface');
53 | // $_storeManager->setCurrentStore(0);
54 |
55 | $this->searchResultFactory = $this->_objectManager->create('\Magento\Staging\Model\Entity\Upcoming\SearchResultFactory');
56 |
57 | $productId = 56;
58 |
59 | $schedules = [];
60 | try {
61 | $params = [
62 | 'entityRequestName' => 'id',
63 | 'entityTable' => 'catalog_product_entity',
64 | 'entityColumn' => 'entity_id'
65 | ];
66 | $this->_request->setParams( ['id' => $productId]);
67 | $schedules = $this->searchResultFactory->create($params);
68 | foreach ($schedules as $schedule) {
69 | echo 'Schedules "' . $schedule->getName() . '" start from ' . $schedule->getStartTime() . ' to ' . $schedule->getEndTime() . '
';
70 | }
71 | } catch (\Exception $e){
72 | echo $e->getMessage();
73 | }
74 |
75 |
76 | echo "schedules done !
";
77 |
78 | return $this->_response;
79 | }
80 |
81 | public function getSchedule($productId)
82 | {
83 | $schedules = [];
84 | try {
85 | $params = [
86 | 'entityRequestName' => 'id',
87 | 'entityTable' => 'catalog_product_entity',
88 | 'entityColumn' => 'entity_id'
89 | ];
90 | $this->request->setParams( ['id' => $productId]);
91 | $schedules = $this->searchResultFactory->create($params);
92 | foreach ($schedules as $schedule) {
93 | echo $schedule->getName();
94 | echo $schedule->getStartTime();
95 | // Get Other values
96 | }
97 | } catch (\Exception $e){
98 | echo $e->getMessage();
99 | }
100 |
101 | return $schedules;
102 | }
103 |
104 | }
105 |
106 | /** @var \Magento\Framework\App\Http $app */
107 | $app = $bootstrap->createApplication('Schedule');
108 | $bootstrap->run($app);
109 |
--------------------------------------------------------------------------------
/layerCategory.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
15 | $layerCategory = $this->_objectManager->create('Magento\Catalog\Model\Layer\Category');
16 | $_coreRegistry = $this->_objectManager->get('Magento\Framework\Registry');
17 | $curentCategory = $_coreRegistry->registry('current_category');
18 | $categoryId = 0;
19 | if ($curentCategory){
20 | $categoryId = $curentCategory->getId();
21 | }else {
22 | $product = $_coreRegistry->registry('current_product');
23 | if($product){
24 | // get collection of categories this product is associated with
25 | $categories = $product->getCategoryCollection()->setPage(1, 1)
26 | ->load();
27 | // if the product is associated with any category
28 | if ($categories->count()) {
29 | // show products from this category
30 | $categoryId = current($categories->getIterator())->getId();
31 | }
32 | }
33 | }
34 | if ($categoryId) {
35 | $layerCategory->setCurrentCategory($categoryId);
36 | }
37 | # Get _productCollection use layerCategory
38 | $_productCollection = $layerCategory->getProductCollection()
39 | ->addAttributeToSelect('*')
40 | ->addStoreFilter()->setPageSize(10)->setCurPage(1);
41 | echo __('This category have %1 products!', $_productCollection->count());
42 | //the method must end with this line
43 | return $this->_response;
44 | }
45 |
46 | }
47 |
48 | /** @var \Magento\Framework\App\Http $app */
49 | $app = $bootstrap->createApplication('Outside');
50 | $bootstrap->run($app);
51 |
--------------------------------------------------------------------------------
/magento_cli.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
15 | $k[0]='bin/magento';
16 | $k[1]='cache:flush'; // You can change command as you want like setup:static-content:deploy, cache:status etc.
17 | $_SERVER['argv']=$k;
18 | try {
19 | $handler = new \Magento\Framework\App\ErrorHandler();
20 | set_error_handler([$handler, 'handler']);
21 | $application = new Magento\Framework\Console\Cli('Magento CLI');
22 | $application->run();
23 | echo 'done Command';
24 | } catch (\Exception $e) {
25 | while ($e) {
26 | echo $e->getMessage();
27 | echo $e->getTraceAsString();
28 | echo "\n\n";
29 | $e = $e->getPrevious();
30 | }
31 | }
32 | //the method must end with this line
33 | return $this->_response;
34 | }
35 |
36 | }
37 |
38 | /** @var \Magento\Framework\App\Http $app */
39 | $app = $bootstrap->createApplication('MagentoCLI');
40 | $bootstrap->run($app);
41 |
--------------------------------------------------------------------------------
/moveOrderToCustomer.php:
--------------------------------------------------------------------------------
1 |
8 | * @@Create Date: 2018-03-20 21:14:06
9 | * @@Modify Date: 2018-05-31 10:17:23
10 | * @@Function:
11 | */
12 | ini_set('display_startup_errors', 1);ini_set('display_errors', 1); error_reporting(-1);
13 | //// Setup Base
14 | $folder = ''; //Folder Name
15 | $file = $folder ? "$folder/app/bootstrap.php" : "app/bootstrap.php";
16 |
17 | if(!file_exists ($file)) $file = "app/bootstrap.php";
18 | if(file_exists ($file)){
19 | require dirname(__FILE__) .'/' .$file;
20 | $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
21 | } else {die('Not found bootstrap.php');}
22 |
23 | class Outslide extends \Magento\Framework\App\Http
24 | implements \Magento\Framework\AppInterface {
25 |
26 | public function launch()
27 | {
28 |
29 |
30 |
31 | $this->_state->setAreaCode('adminhtml');
32 | // $_storeManager = $this->_objectManager->create('\Magento\Store\Model\StoreManagerInterface');
33 | // $_storeManager->setCurrentStore(0);
34 | $orderRepository = $this->_objectManager->create('Magento\Sales\Api\OrderRepositoryInterface');
35 | $searchCriteriaBuilder = $this->_objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder');
36 |
37 | $incrementId = 2000000222;
38 | $customerId = 999;
39 |
40 | $searchCriteria = $searchCriteriaBuilder->addFilter('increment_id', $incrementId, 'eq')->create();
41 | $order = $orderRepository->getList($searchCriteria)->getFirstItem();
42 | if ($order->getId() && !$order->getCustomerId())
43 | {
44 | $order->setCustomerId($customerId);
45 | $order->setCustomerIsGuest(0);
46 | $orderRepository->save($order);
47 |
48 |
49 | echo "Update order done!
";
50 | }
51 | echo 'done';
52 | return $this->_response;
53 | }
54 |
55 | }
56 |
57 | /** @var \Magento\Framework\App\Http $app */
58 | $app = $bootstrap->createApplication('Outslide');
59 | $bootstrap->run($app);
60 |
--------------------------------------------------------------------------------
/removeAttribute.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
11 | $eavSetupFactory = $this->_objectManager->create('\Magento\Eav\Setup\EavSetupFactory');
12 | $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
13 |
14 | $eavSetup->removeAttribute(
15 | \Magento\Catalog\Model\Product::ENTITY,
16 | 'test_attribute'
17 | );
18 |
19 | echo 'Done!';
20 | //the method must end with this line
21 | return $this->_response;
22 | }
23 | }
24 |
25 | /** @var \Magento\Framework\App\Http $app */
26 | $app = $bootstrap->createApplication('Outslide');
27 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/removeAttributeCategory.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
11 | $categorySetupFactory = $this->_objectManager->create('\Magento\Catalog\Setup\CategorySetupFactory');
12 | $categorySetup = $categorySetupFactory->create(['setup' => $setup]);
13 |
14 | $categorySetup->removeAttribute( \Magento\Catalog\Model\Category::ENTITY, 'extrafee');
15 |
16 | echo 'Done!';
17 | //the method must end with this line
18 | return $this->_response;
19 | }
20 | }
21 |
22 | /** @var \Magento\Framework\App\Http $app */
23 | $app = $bootstrap->createApplication('Outslide');
24 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/renameAttribute.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
12 |
13 | $eavSetup = $this->_objectManager->get('Magento\Eav\Setup\EavSetupFactory');
14 |
15 | $catalogSetup = $eavSetup->create(['setup' => $setup]);
16 | $catalogSetup->updateAttribute('catalog_product', 'demo_url', array('attribute_code' => 'demo_frontend'));
17 |
18 | echo 'Done!';
19 | //the method must end with this line
20 | return $this->_response;
21 | }
22 | }
23 |
24 | /** @var \Magento\Framework\App\Http $app */
25 | $app = $bootstrap->createApplication('Outslide');
26 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/renameAttributeCategory.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Framework\Setup\ModuleDataSetupInterface');
12 |
13 | $eavSetup = $this->_objectManager->get('\Magento\Catalog\Setup\CategorySetupFactory');
14 |
15 | $catalogSetup = $eavSetup->create(['setup' => $setup]);
16 | $catalogSetup->updateAttribute('catalog_category', 'xml_sitemap_exclude', array('attribute_code' => 'sitemap_exclude'));
17 |
18 | echo 'Done!';
19 | //the method must end with this line
20 | return $this->_response;
21 | }
22 | }
23 |
24 | /** @var \Magento\Framework\App\Http $app */
25 | $app = $bootstrap->createApplication('Outslide');
26 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/rolesResources.php:
--------------------------------------------------------------------------------
1 | _rootResource = $this->_objectManager->create('\Magento\Framework\Acl\RootResource');
55 | $this->_rulesCollectionFactory = $this->_objectManager->create('\Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory');
56 | $this->_aclResourceProvider = $this->_objectManager->create('\Magento\Framework\Acl\AclResource\ProviderInterface');
57 | $this->_integrationData = $this->_objectManager->create('\Magento\Integration\Helper\Data');
58 | echo '';
59 | $resources = $this->_aclResourceProvider->getAclResources();
60 | var_dump($this->getValueAclResources($resources));
61 | // var_dump($this->getTree());
62 | echo '
';
63 |
64 | echo 'done';
65 | return $this->_response;
66 | }
67 |
68 | public function getValueAclResources($resources, $dataArray=[])
69 | {
70 | foreach ($resources as $value) {
71 | if(!isset($value['id'])) continue;
72 | $dataArray[] = $value['id'];
73 | if(isset($value['children'])){
74 | /* Keep tree */
75 | // $dataArray[] = $this->getValueAclResources($value['children'], $dataArray);
76 | $dataArray = $this->getValueAclResources($value['children'], $dataArray);
77 |
78 | }
79 | }
80 | return $dataArray;
81 | }
82 |
83 | /**
84 | * Get Json Representation of Resource Tree
85 | *
86 | * @return array
87 | */
88 | public function getTree()
89 | {
90 | return $this->_integrationData->mapResources($this->getAclResources());
91 | }
92 |
93 | /**
94 | * Get lit of all ACL resources declared in the system.
95 | *
96 | * @return array
97 | */
98 | private function getAclResources()
99 | {
100 | $resources = $this->_aclResourceProvider->getAclResources();
101 | $configResource = array_filter(
102 | $resources,
103 | function ($node) {
104 | return isset($node['id'])
105 | && $node['id'] == 'Magento_Backend::admin';
106 | }
107 | );
108 | $configResource = reset($configResource);
109 | return isset($configResource['children']) ? $configResource['children'] : [];
110 | }
111 |
112 |
113 | }
114 |
115 | /** @var \Magento\Framework\App\Http $app */
116 | $app = $bootstrap->createApplication('getAclResourcesAdmin');
117 | $bootstrap->run($app);
118 |
--------------------------------------------------------------------------------
/salableQuantity.php:
--------------------------------------------------------------------------------
1 | _objectManager->get('Magento\Framework\App\State');
11 | $appState->setAreaCode('frontend');
12 | $stockState = $this->_objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');
13 | $productSku = 'WT09';
14 | $qty = $stockState->execute($productSku);
15 |
16 | echo 'Qty: ' . $qty[0]['qty'];
17 |
18 | return $this->_response;
19 | }
20 | }
21 |
22 | /** @var \Magento\Framework\App\Http $app */
23 | $app = $bootstrap->createApplication('Outslide');
24 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/source_model.php:
--------------------------------------------------------------------------------
1 | getObjectManager();
15 | $appState = $objectManager->get('Magento\Framework\App\State');
16 | $appState->setAreaCode('adminhtml');
17 | $field = $objectManager->create('Magento\Config\Model\Config\Structure')->getElementByConfigPath('customer/create_account/auto_group_assign');
18 | echo $field->getData()['source_model'];
19 | return $this->_response;
20 | }
21 |
22 |
23 | }
24 |
25 | /** @var \Magento\Framework\App\Http $app */
26 | $app = $bootstrap->createApplication('changeConfig');
27 | $bootstrap->run($app);
28 |
--------------------------------------------------------------------------------
/treeNode.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
57 |
58 | $this->nodeFactory = $this->_objectManager->get('\Magento\Framework\Data\Tree\NodeFactory');
59 | $this->treeFactory = $this->_objectManager->get('\Magento\Framework\Data\TreeFactory');
60 |
61 | $this->storeManager = $this->_objectManager->create('\Magento\Store\Model\StoreManagerInterface');
62 | $this->catalogCategory = $this->_objectManager->create('\Magento\Catalog\Helper\Category');
63 | $this->layerResolver = $this->_objectManager->create('\Magento\Catalog\Model\Layer\Resolver');
64 |
65 | $rootId = $this->storeManager->getStore()->getRootCategoryId();
66 | $storeId = $this->storeManager->getStore()->getId();
67 | echo "Root Id = $rootId and Store Id = $storeId";
68 | $menu = $this->getTreeMenu($storeId, $rootId);
69 | $rootLevel = 0;
70 | $this->removeChildrenWithoutActiveParent($menu, $rootLevel);
71 | $html = $this->getTreeCategories($menu, 'root-class');
72 | echo $html;
73 | //the method must end with this line
74 | return $this->_response;
75 | }
76 |
77 | public function getTreeMenu($storeId, $rootId)
78 | {
79 | $collection = $this->getCategoryTree($storeId, $rootId);
80 | $currentCategory = $this->getCurrentCategory();
81 | $mapping = [$rootId => $this->getMenu()]; // use nodes stack to avoid recursion
82 | foreach ($collection as $category) {
83 | $categoryParentId = $category->getParentId();
84 | if (!isset($mapping[$categoryParentId])) {
85 | $parentIds = $category->getParentIds();
86 | foreach ($parentIds as $parentId) {
87 | if (isset($mapping[$parentId])) {
88 | $categoryParentId = $parentId;
89 | }
90 | }
91 | }
92 |
93 | /** @var Node $parentCategoryNode */
94 | $parentCategoryNode = $mapping[$categoryParentId];
95 |
96 | $categoryNode = new Node(
97 | $this->getCategoryAsArray(
98 | $category,
99 | $currentCategory,
100 | $category->getParentId() == $categoryParentId
101 | ),
102 | 'id',
103 | $parentCategoryNode->getTree(),
104 | $parentCategoryNode
105 | );
106 | $parentCategoryNode->addChild($categoryNode);
107 |
108 | $mapping[$category->getId()] = $categoryNode; //add node in stack
109 | }
110 | $menu = isset($mapping[$rootId]) ? $mapping[$rootId]->getChildren() : [];
111 |
112 | return $menu;
113 | }
114 |
115 |
116 | public function getTreeCategories($categories, $itemPositionClassPrefix) // include Magic_Label and Maximal Depth
117 | {
118 | $html = '';
119 | $counter = 1;
120 | foreach($categories as $category) {
121 | $level = $category->getLevel();
122 | $catChild = $category->getChildren();
123 | $childLevel = $this->getChildLevel($level);
124 | $this->removeChildrenWithoutActiveParent($catChild, $childLevel);
125 |
126 | $childHtml = $this->getTreeCategories($catChild, $itemPositionClassPrefix);
127 | $childClass = $childHtml ? ' hasChild parent ' : ' ';
128 | $childClass .= $itemPositionClassPrefix . '-' .$counter;
129 | $childClass .= ' category-item ';
130 | $html .= '' . $category->getName() . "\n";
131 | $html .= $childHtml;
132 | $html .= '';
133 | $counter++;
134 | }
135 | if($html) $html = '';
136 | return $html;
137 | }
138 | /**
139 | * Get menu object.
140 | *
141 | * Creates Tree root node object.
142 | * The creation logic was moved from class constructor into separate method.
143 | *
144 | * @return Node
145 | * @since 100.1.0
146 | */
147 | public function getMenu()
148 | {
149 | if (!$this->_menu) {
150 | $this->_menu = $this->nodeFactory->create(
151 | [
152 | 'data' => [],
153 | 'idField' => 'root',
154 | 'tree' => $this->treeFactory->create()
155 | ]
156 | );
157 | }
158 | return $this->_menu;
159 | }
160 |
161 | protected function getCategoryTree($storeId, $rootId)
162 | {
163 | /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
164 | $collection = $this->_objectManager->create('\Magento\Catalog\Model\ResourceModel\Category\Collection');
165 | $collection->setStoreId($storeId);
166 | $collection->addAttributeToSelect('name');
167 | $collection->addFieldToFilter('path', ['like' => '1/' . $rootId . '/%']); //load only from store root
168 | $collection->addAttributeToFilter('include_in_menu', 1);
169 | $collection->addIsActiveFilter();
170 | $collection->addNavigationMaxDepthFilter();
171 | $collection->addUrlRewriteToResult();
172 | $collection->addOrder('level', 'ASC');
173 | $collection->addOrder('position', 'ASC');
174 | $collection->addOrder('parent_id', 'ASC');
175 | $collection->addOrder('entity_id', 'ASC');
176 | return $collection;
177 | }
178 |
179 | /**
180 | * Convert category to array
181 | *
182 | * @param \Magento\Catalog\Model\Category $category
183 | * @param \Magento\Catalog\Model\Category $currentCategory
184 | * @param bool $isParentActive
185 | * @return array
186 | */
187 | private function getCategoryAsArray($category, $currentCategory, $isParentActive)
188 | {
189 | $categoryId = $category->getId();
190 | return [
191 | 'name' => $category->getName(),
192 | 'id' => 'category-node-' . $categoryId,
193 | 'url' => $this->catalogCategory->getCategoryUrl($category),
194 | 'has_active' => in_array((string)$categoryId, explode('/', (string)$currentCategory->getPath()), true),
195 | 'is_active' => $categoryId == $currentCategory->getId(),
196 | 'is_category' => true,
197 | 'is_parent_active' => $isParentActive,
198 | 'entity_id' => $categoryId,
199 | 'level' => $category->getData('level')
200 | ];
201 | }
202 |
203 | /**
204 | * Get current Category from catalog layer
205 | *
206 | * @return \Magento\Catalog\Model\Category
207 | */
208 | private function getCurrentCategory()
209 | {
210 | $catalogLayer = $this->layerResolver->get();
211 |
212 | if (!$catalogLayer) {
213 | return null;
214 | }
215 |
216 | return $catalogLayer->getCurrentCategory();
217 | }
218 |
219 | /**
220 | * Remove children from collection when the parent is not active
221 | *
222 | * @param Collection $children
223 | * @param int $childLevel
224 | * @return void
225 | */
226 | private function removeChildrenWithoutActiveParent(Collection $children, int $childLevel): void
227 | {
228 | /** @var Node $child */
229 | foreach ($children as $child) {
230 | if ($childLevel === 0 && $child->getData('is_parent_active') === false) {
231 | $children->delete($child);
232 | }
233 | }
234 | }
235 |
236 | /**
237 | * Retrieve child level based on parent level
238 | *
239 | * @param int $parentLevel
240 | *
241 | * @return int
242 | */
243 | private function getChildLevel($parentLevel): int
244 | {
245 | return $parentLevel === null ? 0 : $parentLevel + 1;
246 | }
247 |
248 | }
249 |
250 |
251 | /** @var \Magento\Framework\App\Http $app */
252 | $app = $bootstrap->createApplication('CategoryTree');
253 | $bootstrap->run($app);
254 |
--------------------------------------------------------------------------------
/unLockCustomer.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('adminhtml');
28 | // $_storeManager = $this->_objectManager->create('\Magento\Store\Model\StoreManagerInterface');
29 | // $_storeManager->setCurrentStore(0);
30 | $customerId = '2272';
31 | $authentication = $this->_objectManager->create('Magento\Customer\Model\AuthenticationInterface');
32 | $customerRepository = $this->_objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface');
33 | // go to admin url domain.com/admin/customer/locks/unlock/customer_id/1
34 | if ($customerId) {
35 | $authentication->unlock($customerId);
36 | $customer = $customerRepository->getById($customerId);
37 | $customer->setConfirmation(null);
38 | $customerRepository->save($customer);
39 | echo 'done';
40 | }
41 |
42 | return $this->_response;
43 | }
44 |
45 | }
46 |
47 | /** @var \Magento\Framework\App\Http $app */
48 | $app = $bootstrap->createApplication('updateOrder');
49 | $bootstrap->run($app);
50 |
--------------------------------------------------------------------------------
/updateConfig.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Config\Model\ResourceModel\Config');
11 | $config->saveConfig('web/unsecure/base_url', 'http://magepow.com/',\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT,0);
12 |
13 | echo 'Done!';
14 | //the method must end with this line
15 | return $this->_response;
16 | }
17 | }
18 |
19 | /** @var \Magento\Framework\App\Http $app */
20 | $app = $bootstrap->createApplication('Outslide');
21 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/updateNewSale.php:
--------------------------------------------------------------------------------
1 | setTime;
25 | $dt = new DateTime();
26 | // $dt = new DateTime('2017-01-01');
27 | $this->todayStartOfDayDate = $dt->setTime(0, 0, 0)->format('Y-m-d H:i:s');
28 | $this->todayEndOfDayDate = $dt->setTime(23, 59, 59)->format('Y-m-d H:i:s');
29 | $discount=0.9;
30 | $attributeSet = 'Service';
31 | $attributeSetId = 9;
32 | // echo $this->todayStartOfDayDate;
33 | // echo '
';
34 | // echo $this->todayEndOfDayDate;
35 | // echo '
';
36 | // die;
37 |
38 | $this->_state->setAreaCode('adminhtml');
39 | // $_storeManager = $this->_objectManager->create('\Magento\Store\Model\StoreManagerInterface');
40 | // $_storeManager->setCurrentStore(0);
41 | $model = $this->_objectManager->get('Magento\Catalog\Model\Product\Action');
42 | // $productRepository = $this->_objectManager->create('Magento\Catalog\Model\ProductRepository');
43 | // $attributeSetRepository = $this->_objectManager->get('Magento\Eav\Api\AttributeSetRepositoryInterface');
44 | // $attributeSetCollection = $this->_objectManager->get('\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory');
45 | $newProducts = $this->getNewProducts();
46 | $num = 0;
47 | if( count($newProducts)){
48 | foreach ($newProducts as $product) {
49 | // $product->setStoreId(0)->setData('news_to_date', $setTime)->save();
50 | // $model->updateAttributes([$product->getId()], ['news_to_date' => $setTime], 0);
51 | $num++;
52 | }
53 | }
54 |
55 | echo "$num New products changed !
";
56 |
57 |
58 |
59 | $saleProducts = $this->getSaleProducts();
60 | $num = 0;
61 | foreach ($saleProducts as $product) {
62 | // echo $product->getName();
63 | if( $product->getAttributeSetId() != $attributeSetId) continue;
64 | echo $product->getName();
65 | // $product->setStoreId(0)->setData('special_to_date', $setTime)->save();
66 | $price = (int) $product->getData('price');
67 | $specialPrice = (int) ($price*$discount);
68 | echo $specialPrice;
69 | $model->updateAttributes([$product->getId()], ['special_to_date' => $setTime], 0);
70 | $model->updateAttributes([$product->getId()], ['special_price' => $specialPrice], 0);
71 | $num++;
72 | }
73 |
74 |
75 | echo "$num Sale products changed !
";
76 |
77 | return $this->_response;
78 | }
79 |
80 | public function getNewProducts() {
81 |
82 | // $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s');
83 | // $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
84 | $todayEndOfDayDate = $this->todayEndOfDayDate;
85 | $todayStartOfDayDate = $this->todayStartOfDayDate;
86 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
87 | /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $manager */
88 | $manager = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
89 | $collection = $manager->create();
90 |
91 | $collection->addStoreFilter()
92 | ->addAttributeToFilter(
93 | 'news_from_date',
94 | [
95 | 'or' => [
96 | 0 => ['date' => true, 'to' => $todayEndOfDayDate],
97 | 1 => ['is' => new \Zend_Db_Expr('null')],
98 | ]
99 | ],
100 | 'left'
101 | )
102 | // ->addAttributeToFilter(
103 | // 'news_to_date',
104 | // [
105 | // 'or' => [
106 | // 0 => ['date' => true, 'from' => $todayStartOfDayDate],
107 | // 1 => ['is' => new \Zend_Db_Expr('null')],
108 | // ]
109 | // ],
110 | // 'left'
111 | // )
112 | ->addAttributeToFilter(
113 | [
114 | ['attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')],
115 | ['attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null')],
116 | ]
117 | )->addAttributeToSort('news_from_date', 'desc');
118 |
119 | return $collection;
120 | }
121 |
122 | public function getSaleProducts(){
123 |
124 | // $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s');
125 | // $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
126 | $todayEndOfDayDate = $this->todayEndOfDayDate;
127 | $todayStartOfDayDate = $this->todayStartOfDayDate;
128 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
129 | /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $manager */
130 | $manager = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
131 | $collection = $manager->create();
132 |
133 | $collection->addStoreFilter()
134 | ->addAttributeToSelect('*')
135 | // ->addAttributeToFilter(
136 | // 'special_from_date',
137 | // [
138 | // 'or' => [
139 | // 0 => ['date' => true, 'to' => $todayEndOfDayDate],
140 | // 1 => ['is' => new \Zend_Db_Expr('null')],
141 | // ]
142 | // ],
143 | // 'left'
144 | // )
145 | // // ->addAttributeToFilter(
146 | // // 'special_to_date',
147 | // // [
148 | // // 'or' => [
149 | // // 0 => ['date' => true, 'from' => $todayStartOfDayDate],
150 | // // 1 => ['is' => new \Zend_Db_Expr('null')],
151 | // // ]
152 | // // ],
153 | // // 'left'
154 | // // )
155 | // ->addAttributeToFilter(
156 | // [
157 | // ['attribute' => 'special_from_date', 'is' => new \Zend_Db_Expr('not null')],
158 | // ['attribute' => 'special_to_date', 'is' => new \Zend_Db_Expr('not null')],
159 | // ]
160 | // )
161 | ->addAttributeToSort('special_to_date', 'desc');
162 |
163 | return $collection;
164 |
165 | }
166 |
167 | }
168 |
169 | /** @var \Magento\Framework\App\Http $app */
170 | $app = $bootstrap->createApplication('upToDate');
171 | $bootstrap->run($app);
172 |
--------------------------------------------------------------------------------
/updateProduct.php:
--------------------------------------------------------------------------------
1 | _state->setAreaCode('frontend');
12 | $this->_state->setAreaCode('adminhtml');
13 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
14 | // $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
15 |
16 | $productRepository = $this->_objectManager->create('Magento\Catalog\Model\ProductRepository');
17 |
18 | // YOU WANT TO LOAD BY ID?
19 | $id = "YOUR ID HERE";
20 | // YOU WANT TO LOAD BY SKU?
21 | $sku = "YOUR SKU HERE";
22 |
23 | if($id) {
24 | $product = $productRepository->getById($id);
25 | }
26 | if($sku) {
27 | $product = $productRepository->get($sku);
28 | }
29 |
30 | $shortDescriptionAttributeCode = "short_description";
31 | $descriptionAttributeCode = "description";
32 |
33 | $shortDescriptionAttributeValue = "YOUR NEW VALUE";
34 | $descriptionAttributeValue = "YOUR NEW VALUE";
35 |
36 |
37 | $product->addAttributeUpdate($shortDescriptionAttributeCode, $shortDescriptionAttributeValue, 0);
38 | $product->addAttributeUpdate($descriptionAttributeCode, $descriptionAttributeValue, 0);
39 |
40 | echo 'Done!';
41 | //the method must end with this line
42 | return $this->_response;
43 | }
44 | }
45 |
46 | /** @var \Magento\Framework\App\Http $app */
47 | $app = $bootstrap->createApplication('Outslide');
48 | $bootstrap->run($app);
--------------------------------------------------------------------------------
/wysiwyg.php:
--------------------------------------------------------------------------------
1 | _objectManager->create('\Magento\Cms\Model\ResourceModel\Block\Collection');
11 | $images = [];
12 | foreach ($blockCollection as $block) {
13 | echo 'Block Id: ' . $block->getId() . '
';
14 | echo 'Block Identifier: ' . $block->getIdentifier() . '
';
15 | $content = $block->getContent();
16 |
17 | preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
18 | if(!empty($matches)){
19 | echo '';
20 | var_dump($matches);
21 | echo '
';
22 | }
23 | echo '
';
24 |
25 | }
26 | //
27 | var_dump($images);
28 |
29 |
30 |
31 | $pageCollection = $this->_objectManager->create('\Magento\Cms\Model\ResourceModel\Page\Collection');
32 | $images = [];
33 | foreach ($pageCollection as $page) {
34 | echo 'Page Id: ' . $page->getId() . '
';
35 | echo 'Page Identifier: ' . $page->getIdentifier() . '
';
36 | $content = $page->getContent();
37 |
38 | preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches);
39 | if(!empty($matches)){
40 | echo '';
41 | var_dump($matches);
42 | echo '
';
43 | }
44 | echo '
';
45 |
46 | }
47 |
48 | var_dump($images);
49 |
50 |
51 | echo 'Done!';
52 | //the method must end with this line
53 | return $this->_response;
54 | }
55 | }
56 |
57 | /** @var \Magento\Framework\App\Http $app */
58 | $app = $bootstrap->createApplication('Outslide');
59 | $bootstrap->run($app);
--------------------------------------------------------------------------------