-
-
Save bhaveshpp/41ba207e993b0fa56f140fa4251e1ce1 to your computer and use it in GitHub Desktop.
Aheadworks\RewardPoints Adding transaction using root script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Upload your files</title> | |
</head> | |
<body> | |
<form enctype="multipart/form-data" action="transaction.php" method="POST"> | |
<p>Upload csv file</p> | |
<input type="file" name="csv"></input> | |
<input type="submit" value="Upload"></input> | |
</form> | |
<?php | |
$dir = "uploads"; | |
$files = scandir($dir); | |
if(count($files) > 2): | |
?> | |
<form action="transaction.php" method="POST"> | |
<p>import csv file</p> | |
<table border='1'> | |
<tr> | |
<th> # </th> | |
<th> File name </th> | |
</tr> | |
<?php for ($i=2; $i < count($files); $i++) : ?> | |
<tr> | |
<td> | |
<input type="radio" name="csv" value="<?= $files[$i]?>"></input> | |
</td> | |
<td> | |
<strong class="file-nmae"><?= $files[$i]?></strong> | |
</td> | |
</tr> | |
<?php endfor;?> | |
</table> | |
<input type="submit" name="import" value="Import"></input> | |
<input type="submit" name="delete" value="Delete"></input> | |
</form> | |
<?php endif;?> | |
</body> | |
</html> | |
<?PHP | |
define("PATH", "uploads/"); | |
if(!empty($_FILES['csv'])) | |
{ | |
$filepath = PATH . basename( $_FILES['csv']['name']); | |
if(file_exists($filepath)){ | |
$newPath = PATH . time() . basename( $_FILES['csv']['name']); | |
if(move_uploaded_file($_FILES['csv']['tmp_name'], $newPath)) { | |
echo "The file ". basename( $_FILES['csv']['name']). " has been uploaded"; | |
} else{ | |
echo "There was an error uploading the file, please try again!"; | |
} | |
}else{ | |
if(move_uploaded_file($_FILES['csv']['tmp_name'], $filepath)) { | |
echo "The file ". basename( $_FILES['csv']['name']). " has been uploaded"; | |
} else{ | |
echo "There was an error uploading the file, please try again!"; | |
} | |
} | |
header("Refresh:0; url=transaction.php"); | |
exit; | |
} | |
if ($_POST) { | |
if (!empty($_POST['delete'])) { | |
$csv = PATH.$_POST['csv']; | |
unlink($csv); | |
header("Refresh:0; url=transaction.php"); | |
exit; | |
} | |
if (!empty($_POST['import'])) { | |
$csv = PATH.$_POST['csv']; | |
} | |
} | |
?> | |
<?php | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
ini_set('memory_limit', -1); | |
error_reporting(E_ALL); | |
use Magento\Framework\App\Bootstrap; | |
use Magento\Framework\App\Config\ScopeConfigInterface; | |
use Magento\Store\Model\StoreManagerInterface; | |
use Magento\Framework\Exception\LocalizedException; | |
use Magento\UrlRewrite\Model\UrlFinderInterface; | |
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; | |
require __DIR__ . '../../../app/bootstrap.php'; | |
$bootstrap = Bootstrap::create(BP, $_SERVER); | |
$objectManager = $bootstrap->getObjectManager(); | |
$state = $objectManager->get('Magento\Framework\App\State'); | |
$state->setAreaCode('frontend'); | |
// $state->setAreaCode('adminhtml'); | |
$customerModel = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class); | |
if (isset($csv)){ | |
$file = $csv; | |
echo("<br/>"); | |
$row = 0; | |
$success = 0; | |
$newCustomer = 0; | |
$customerException = 0; | |
$somethingWrong = 0; | |
if (($handle = fopen($file, "r")) !== FALSE) { | |
while (($data = fgetcsv($handle)) !== FALSE) { | |
$row++; | |
try { | |
$transactionData = getTransactionData($data); | |
try { | |
$websiteId = 2; | |
// $transactionData['email'] = "devtecksky@gmail.com"; | |
$customer = $customerModel->get($transactionData['email'],$websiteId); | |
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) { | |
echo "<pre>"; | |
print_r($transactionData); | |
echo "<br/>"; | |
echo "</pre>"; | |
echo "<br/><b> customer not found </b> <br/> "; | |
$newCustomer++; | |
} catch (\Exception $e) { | |
echo $e; | |
$customerException++; | |
} | |
$transactionArray = array(); | |
$transactionArray['customer_id'] = $customer->getId(); | |
$transactionArray['customer_name'] = $customer->getPrefix()." ".$customer->getFirstName()." ".$customer->getLastName(); | |
$transactionArray['customer_email'] = $transactionData['email']; | |
$transactionArray['comment_to_customer'] = $transactionData['comment']; | |
$transactionArray['comment_to_admin'] = ""; | |
$transactionArray['balance'] = 0 - $transactionData['point']; | |
$transactionArray['expiration_date'] = ""; | |
$transactionArray['website_id'] = "2"; | |
echo "<pre>"; | |
print_r($transactionArray); | |
echo "<br/>"; | |
echo "</pre>"; | |
// continue; | |
// if ($transactionData['email'] == "test@hotmail.fr") { | |
// echo "<pre>"; | |
// print_r($transactionArray); | |
// echo "<br/>"; | |
// echo "<pre>";die(__METHOD__."::".__LINE__); | |
// } | |
$transaction = $objectManager->get(\Aheadworks\RewardPoints\Model\Service\CustomerRewardPointsService::class); | |
$transaction->resetCustomer(); | |
if ($transaction->saveAdminTransaction($transactionArray)) { | |
echo("<br/> Transaction added. <br/>"); | |
$success++; | |
}else{ | |
echo("<br/> Something wents wrong. <br/>"); | |
$somethingWrong++; | |
} | |
} catch (\Exception $e) { | |
echo $e; | |
} | |
} | |
fclose($handle); | |
echo("<b>"); | |
echo("<br/>"); | |
echo "<br/> Total Imported: ".$success; | |
echo("<br/>"); | |
echo "<br/> Total Rows: ".$row; | |
echo("<br/>"); | |
echo "<br/> Total new customer: ".$newCustomer; | |
echo("<br/>"); | |
echo "<br/> Something wents wrong: ".$somethingWrong ; | |
echo("</b>"); | |
} | |
} | |
function getTransactionData($data) | |
{ | |
return [ | |
'email' => $data[0], # Customer email | |
'comment' => utf8_encode($data[1]), # Customer comment | |
'point' => $data[2] # Balance Point | |
]; | |
} | |
?> | |
<?php | |
/* | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
ini_set('memory_limit', -1); | |
error_reporting(E_ALL); | |
use Magento\Framework\App\Bootstrap; | |
require '../app/bootstrap.php'; | |
$bootstrap = Bootstrap::create(BP, $_SERVER); | |
$objectManager = $bootstrap->getObjectManager(); | |
$state = $objectManager->get('Magento\Framework\App\State'); | |
// $state->setAreaCode('frontend'); | |
$state->setAreaCode('adminhtml'); | |
$transaction = $objectManager->get(\Aheadworks\RewardPoints\Model\Service\CustomerRewardPointsService::class); | |
$data = array(); | |
$data['customer_id'] = "34580"; | |
$data['customer_name'] = "M Dev Test"; | |
$data['customer_email'] = "test@gmail.com"; | |
$data['comment_to_customer'] = "this is test comment for customer"; | |
$data['comment_to_admin'] = ""; | |
$data['balance'] = "-10"; | |
$data['expiration_date'] = ""; | |
$data['website_id'] = "2"; | |
$transaction->resetCustomer(); | |
$transaction->saveAdminTransaction($data);*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment