Search

Jan 7, 2025

Backup and update table data via the csv file in magento 2

1. Backup data table to csv file (using datagrip)

catalog_product_entity.csv

entity_id,sku,quickbooks_entity,quickbooks_sync_token

86304,15100_SVBKB_9,30,0

86307,15100_SVBKB_8,31,0

86310,15100_SVBKB_7,32,0

86313,15100_SVBKB_6,33,0

86316,15100_SVBKB_12,34,0

86319,15100_SVBKB_11,35,0


2. Put catalog_product_entity.csv to magento/pub/catalog_product_entity.csv


3. Create file restore.php in magento/pub/restore.php

<?php
use \Magento\Framework\App\Bootstrap;

include('../app/bootstrap.php');

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

// Get connection
$host = '127.0.0.1';
$dbname = 'dddd';
$username = 'aaaa';
$password = 'ssss';

$tableName = 'catalog_product_entity';
$filePath = 'catalog_product_entity.csv';

// Connect to MariaDB
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Open the CSV file
$csvFile = fopen($filePath, 'r');
fgetcsv($csvFile);

$sql = "UPDATE $tableName SET quickbooks_entity = ?, quickbooks_sync_token = ? WHERE entity_id = ?";
$stmt = $conn->prepare($sql);

while (($data = fgetcsv($csvFile, null, ',')) !== FALSE) {
/**
* entity_id,sku,quickbooks_entity,quickbooks_sync_token
* 0: entity_id
* 2: quickbooks_entity
* 3: quickbooks_sync_token
*/
$entity_id = $data[0];
$quickbooks_entity = $data[2];
$quickbooks_sync_token = $data[3];

if ($entity_id && $quickbooks_entity) {
$stmt->execute([$quickbooks_entity, $quickbooks_sync_token, $entity_id]);
echo "Updated entity_id = $entity_id, quickbooks_entity = $quickbooks_entity, quickbooks_sync_token = $quickbooks_sync_token \n";
}
}

fclose($csvFile);

$conn = null;
echo "\n\n $filePath imported successfully!";



4. Run `php restore.php` in terminal



Sep 20, 2024

The Stripe card is not being saved for the user after placing an order in Admin Magento

Step by step:

1. Go to admin magento 2. Navigate to Sales > Orders. 

2. Click "Create new order" button. Select an existing customer.

3. Add products. Fill in the Shipping and Billing addresses.

4. Add a new payment method (credit card). Check "Save card on customer". 

5. Complete the order by submitting it.

6. On the frontend, log in as the customer from step 2.

7. Navigate to My Account > Stored Payment Methods.

8. Actual result: The new card is not saved in the "Stored Payment Methods" section.

9. Expected result: The new card should be saved in the "Stored Payment Methods" section. 

Environment: Magento EE 2.4.6-p3 + stripe/module-payments 4.0.10


FIXED: StripeIntegration/Payments/Helper/Generic.php

public function assignPaymentData($payment, $data)
{
$this->resetPaymentData($payment);

if ($this->isMultiShipping())
{
$payment->setAdditionalInformation("payment_location", "Multishipping checkout");
}
else if ($this->isAdmin())
{
$payment->setAdditionalInformation("payment_location", "Admin area");

/**
* The card is not being saved for the user after placing an order in Magento
* $data = {"payment_method":"pm_1Q0xfP2MVsduPvSkD8t4bjfw","save_payment_method":"on"}
*/
if (isset($data['save_payment_method'])) {
$payment->setAdditionalInformation("save_payment_method", $data['save_payment_method']);
}
}