313 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			313 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
| <?php
 | |
| require_once '../app/bootstrap.php';
 | |
| $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
 | |
| $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
 | |
| $obj = $bootstrap->getObjectManager();
 | |
| 
 | |
| $state = $obj->get('\Magento\Framework\App\State');
 | |
| $state->setAreaCode('global');
 | |
| 
 | |
| $productHelper = $obj->create('\IpSupply\Prology\Helper\ProductHelper');
 | |
| $categoryHelper = $obj->create('\IpSupply\Prology\Helper\CategoryHelper');
 | |
| 
 | |
| $a =  $productHelper->getTypesDropdown();
 | |
| // $options = $a->getAllOptions();
 | |
| // foreach ($options as $option) {
 | |
| //     $value = $option->getValue();  // Value
 | |
| //     echo $value." value\n";
 | |
| //     $label = $option->getLabel();  // Label
 | |
| //     echo $label." label\n";
 | |
| //     echo $option->getId()." Id\n";
 | |
| 
 | |
| // }
 | |
| echo json_encode($a[strtoupper("IP Phones")]);
 | |
| 
 | |
| 
 | |
| //echo json_encode($categoryHelper->getAllCategories());
 | |
| 
 | |
| // $data = array(
 | |
| //     "sku" => "huynh-test-1",
 | |
| //     "name" => "huynh-test-1",
 | |
| //     "visibility" => 0,
 | |
| //     "typeId" => "configurable",
 | |
| //     "price" => 10,
 | |
| //     "categories" => [1422],
 | |
| //     "qty" => 10,
 | |
| //     "chooseCondition" => "",
 | |
| //     "description" => "description",
 | |
| //     "shortDescription" => "shortDescription",
 | |
| //     "imageUrls" => [],
 | |
| //     "brands" => "CISCO",
 | |
| //     "types" => "ACCESSPOINT"
 | |
| // );
 | |
| 
 | |
| // $productData = array(
 | |
| //         "sku" => "huynh-test-1",
 | |
| //         "name" => "huynh-test-1",
 | |
| //         "categories" => [1422],
 | |
| //         "description" => "description",
 | |
| //         "shortDescription" => "shortDescription",
 | |
| //         "brands" => "CISCO",
 | |
| //         "types" => "ACCESSPOINT"
 | |
| // );
 | |
| 
 | |
| // $data = $productHelper->createProductData($productData, 10, 10, 0, "configurable", "", []);
 | |
| // echo  json_encode($data)."\n";
 | |
| // $product = $productHelper->createProduct($data);
 | |
| 
 | |
| // if ($product) {
 | |
| //     echo $product->getId();
 | |
| // } else {
 | |
| //     echo "null";
 | |
| // }
 | |
| 
 | |
| // $groupDataProduct = array(
 | |
| //     "sku" => "huynh-test-01",
 | |
| //     "name" => "huynh-test-01",
 | |
| //     "categories" => array(1422),
 | |
| //     "description" => "description",
 | |
| //     "shortDescription" => "short description",
 | |
| //     "imageUrls" => [
 | |
| //         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg",
 | |
| //     ],// images for group product
 | |
| //     "brands" => "CISCO", // one of them ["CISCO","JUPINER","INTEL","HP"]
 | |
| //     "types" => "ACCESSPOINT",//"ACCESSPOINT","ROUTER","SWITCH","SERVER"
 | |
| //     "condition" => array(
 | |
| //         "new" => array(
 | |
| //             "qty" => 10,
 | |
| //             "price" => 20.5,
 | |
| //             "imageUrls" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex2200-48t-4g-1_1.jpg"
 | |
| //             ]//images for group product new
 | |
| //         ),
 | |
| //         "refurbished" => array(
 | |
| //             "qty" => 15,
 | |
| //             "price" => 19.5,
 | |
| //             "imageUrls" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/m/a/mag4610-1_1.jpg"
 | |
| //             ]
 | |
| //         )
 | |
| //     ),
 | |
| //     "relatedProduct" => array(
 | |
| //         array(
 | |
| //             "sku" => "huynh-test-02",
 | |
| //             "name" => "huynh-test-02",
 | |
| //             "categories" => array(1422),
 | |
| //             "description" => "description",
 | |
| //             "shortDescription" => "short description",
 | |
| //             "imageUrls" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg",
 | |
| //             ],// images for group product
 | |
| //             "brands" => "CISCO", // one of them ["CISCO","JUPINER","INTEL","HP"]
 | |
| //             "types" => "ACCESSPOINT",//"ACCESSPOINT","ROUTER","SWITCH","SERVER"
 | |
| //             "condition" => array(
 | |
| //                 "new" => array(
 | |
| //                     "qty" => 5,
 | |
| //                     "price" => 15.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex2200-48t-4g-1_1.jpg"
 | |
| //                     ]//images for group product new
 | |
| //                 ),
 | |
| //                 "refurbished" => array(
 | |
| //                     "qty" => 3,
 | |
| //                     "price" => 13.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/m/a/mag4610-1_1.jpg"
 | |
| //                     ]
 | |
| //                 )
 | |
| //             )
 | |
| //         )
 | |
| //     ),
 | |
| //     "upsellProduct" => array(
 | |
| //         array(
 | |
| //             "sku" => "huynh-test-03",
 | |
| //             "name" => "huynh-test-03",
 | |
| //             "categories" => array(1422),
 | |
| //             "description" => "huynh-test-03",
 | |
| //             "shortDescription" => "short huynh-test-03",
 | |
| //             "imageUrls" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg",
 | |
| //             ],// images for group product
 | |
| //             "brands" => "CISCO", // one of them ["CISCO","JUPINER","INTEL","HP"]
 | |
| //             "types" => "ACCESSPOINT",//"ACCESSPOINT","ROUTER","SWITCH","SERVER"
 | |
| //             "condition" => array(
 | |
| //                 "new" => array(
 | |
| //                     "qty" => 5,
 | |
| //                     "price" => 12.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex2200-48t-4g-1_1.jpg"
 | |
| //                     ]//images for group product new
 | |
| //                 ),
 | |
| //                 "refurbished" => array(
 | |
| //                     "qty" => 3,
 | |
| //                     "price" => 13.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/m/a/mag4610-1_1.jpg"
 | |
| //                     ]
 | |
| //                 )
 | |
| //             )
 | |
| //         )
 | |
| //     ),
 | |
| 
 | |
| //     "crosssellProduct" => array(
 | |
| //         array(
 | |
| //             "sku" => "huynh-test-04",
 | |
| //             "name" => "huynh-test-04",
 | |
| //             "categories" => array(1422),
 | |
| //             "description" => "huynh-test-03",
 | |
| //             "shortDescription" => "short huynh-test-03",
 | |
| //             "imageUrls" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg",
 | |
| //             ],// images for group product
 | |
| //             "brands" => "CISCO", // one of them ["CISCO","JUPINER","INTEL","HP"]
 | |
| //             "types" => "ACCESSPOINT",//"ACCESSPOINT","ROUTER","SWITCH","SERVER"
 | |
| //             "condition" => array(
 | |
| //                 "new" => array(
 | |
| //                     "qty" => 5,
 | |
| //                     "price" => 50.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex2200-48t-4g-1_1.jpg"
 | |
| //                     ]//images for group product new
 | |
| //                 ),
 | |
| //                 "refurbished" => array(
 | |
| //                     "qty" => 3,
 | |
| //                     "price" => 55.5,
 | |
| //                     "imageUrls" => [
 | |
| //                         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/m/a/mag4610-1_1.jpg"
 | |
| //                     ]
 | |
| //                 )
 | |
| //             )
 | |
| //         )
 | |
| //     ),
 | |
| 
 | |
| 
 | |
| // );
 | |
| 
 | |
| //$productHelper->deleteImageMedia("huynh-test-1");
 | |
| //$productHelper->deleteImageMedia("huynh-test-01");
 | |
| //die;
 | |
| //$product = $productHelper->createConfigurableProduct($groupDataProduct);
 | |
| // $product = $productHelper->createProductFromErp($groupDataProduct);
 | |
| // if ($product) {
 | |
| //     echo $product->getId();
 | |
| // } else {
 | |
| //     echo "null";
 | |
| // }
 | |
| 
 | |
| // $product = $obj->create('\Magento\Catalog\Model\Product');
 | |
| // $product = $product->getCollection()
 | |
| // ->addFieldToSelect("*")
 | |
| // ->addAttributeToFilter('sku', 'huynh-test-1')
 | |
| // ->addMediaGalleryData()
 | |
| // ->getFirstItem();
 | |
| // $images = $product->getMediaGalleryImages();
 | |
| // echo count($images);
 | |
| 
 | |
| 
 | |
| //$src = "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg";
 | |
| //file_put_contents("/home/devnsw/mag2.nswteam.net/images/download/huynh-test.jpg", file_get_contents($src));
 | |
| //file_put_contents("/home/devnsw/mag2.nswteam.net/var/log/import/images/huynh-test.jpg", file_get_contents($url));
 | |
| // if (!mkdir("/home/devnsw/mag2.nswteam.net/cron/images", 0777, true)) {
 | |
| //     die('Failed to create directories...');
 | |
| // }
 | |
| // if (!mkdir("/home/devnsw/mag2.nswteam.net/var/log/import/images", 0777, true)) {
 | |
| //     die('Failed to create directories...');
 | |
| // }
 | |
| // if (!mkdir("/home/devnsw/mag2.nswteam.net/images/download", 0777, true)) {
 | |
| //     die('Failed to create directories...');
 | |
| // }
 | |
| // exit;
 | |
| // echo json_encode($productHelper->getCompanyDropdown())." \n";
 | |
| // echo json_encode($productHelper->getBrandsDropdown())." \n";
 | |
| // echo json_encode($productHelper->getTypesDropdown())." \n";
 | |
| //die;
 | |
| // $group_product = array(
 | |
| //     "sku" => "huynh-test",
 | |
| //     "name" => "name",
 | |
| //     "categories" => array(1422),
 | |
| //     "description" => "description",
 | |
| //     "shortDescription" => "short description",
 | |
| //     "imageUrls" => [
 | |
| //         "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex9214-base3-ac-1_1.jpg",
 | |
| //     ],// images for group product
 | |
| //     "brands" => "CISCO", // one of them ["CISCO","JUPINER","INTEL","HP"]
 | |
| //     "types" => "ACCESSPOINT",//"ACCESSPOINT","ROUTER","SWITCH","SERVER"
 | |
| //     "condition" => array(
 | |
| //         "new" => array(
 | |
| //             "qty" => 2,
 | |
| //             "price" => 12.5,
 | |
| //             "images" => [
 | |
| //                 "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/e/x/ex2200-48t-4g-1_1.jpg"
 | |
| //             ]//images for group product new
 | |
| //         ),
 | |
| //         "refurbished" => array(
 | |
| //             "qty" => 3,
 | |
| //             "price" => 13.5,
 | |
| //             "images" => [
 | |
| //               "https://ipsupply.com.au/media/catalog/product/cache/10cb21bf02aa6d27ecf18013a400d823/m/a/mag4610-1_1.jpg"
 | |
| //             ]
 | |
| //         )
 | |
| //     )
 | |
| 
 | |
| 
 | |
| // );
 | |
| 
 | |
| //
 | |
| 
 | |
| // $productObject = $obj->get('Magento\Catalog\Model\Product');
 | |
| // $product = $productObject->loadByAttribute("sku","huynh-test-2111");
 | |
| // if ($product) {
 | |
| //     echo "exist";
 | |
| // } else {
 | |
| //     echo "not exist";
 | |
| // }
 | |
| 
 | |
| // $obj = \Magento\Framework\App\ObjectManager::getInstance();
 | |
| 
 | |
| // /** @var \Magento\Catalog\Model\Product $product */
 | |
| // $productObject = $obj->get('Magento\Catalog\Model\Product');
 | |
| 
 | |
| // $product = $productObject->loadByAttribute('sku', 'Test Test');
 | |
| 
 | |
| // $linkDataAll = [];
 | |
| // $skuLinks = "0012365,test1233,789456";
 | |
| // $skuLinks = explode(",",$skuLinks);
 | |
| 
 | |
| // foreach($skuLinks as $skuLink) {
 | |
| //     //check first that the product exist
 | |
| //     $linkedProduct = $productObject->loadByAttribute("sku",$skuLink);
 | |
| //     if($linkedProduct) {
 | |
| //         /** @var  \Magento\Catalog\Api\Data\ProductLinkInterface $productLinks */
 | |
| //         $productLinks = $obj->create('Magento\Catalog\Api\Data\ProductLinkInterface');
 | |
| //         $linkData = $productLinks //Magento\Catalog\Api\Data\ProductLinkInterface
 | |
| //             ->setSku($product->getSku())
 | |
| //             ->setLinkedProductSku($skuLink)
 | |
| //             ->setLinkType("related");
 | |
| //         $linkDataAll[] = $linkData;
 | |
| //     }
 | |
| 
 | |
| // }
 | |
| // if($linkDataAll) {
 | |
| //     print(count($linkDataAll)); //gives 3
 | |
| //     $product->setProductLinks($linkDataAll);
 | |
| // }
 | |
| // $product->save();
 | |
| 
 | |
| // truncate catalog_product_entity_media_gallery_value;
 | |
| // truncate catalog_product_entity_media_gallery_value_to_entity;
 | |
| // delete from catalog_product_entity_media_gallery;  # 9 sec
 | |
| // delete from catalog_product_entity_varchar where attribute_id in ( select
 | |
| //      attribute_id from eav_attribute where attribute_code like "%image" and
 | |
| //      entity_type_id = 4 );
 | |
| 
 | |
| // UPDATE catalog_product_entity_decimal val
 | |
| // SET  val.value = (val.value)
 | |
| // WHERE  val.attribute_id = (
 | |
| //    SELECT attribute_id FROM eav_attribute eav
 | |
| //    WHERE eav.entity_type_id = 4
 | |
| //      AND eav.attribute_code = 'price'
 | |
| 
 | |
| // Update cataloginventory_stock_item SET qty = 0.0000,is_in_stock = 0,stock_status_changed_auto = 1,low_stock_date = NOW()
 | |
| 
 | |
| // Update cataloginventory_stock_status SET qty = 0.0000,stock_status = 0
 |