Code Monkey home page Code Monkey logo

datafeedr-product-sets's People

Contributors

ericbusch avatar growdev avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

datafeedr-product-sets's Issues

Update text domain

Currently the text domain uses a constant (DFRPS_DOMAIN), but this won't work for translations.

All instances of DFRPS_DOMAIN need to be changed to 'datafeedr-product-sets'.

Extract image_check to new function

This code should be extracted to a function:

	$image_check = intval( get_post_meta( $post->ID, '_dfrps_product_check_image', true ) );
	if ( 0 === $image_check ) {
		return false;
	}

It should also accept the meta_key to look up.

Product page 404 after first prouct import

Steps to recreate

  1. Setup Datafeedr API and Product Set plugins.
  2. Add a new Product Set and publish it.
  3. Wait for the import to finish.
  4. Go to front of the site and navigate to category page.
  5. Select a product to view. I clicked Page 50 > North Face Daypack Backpack

Screen Shot 2023-02-15 at 3 11 21 PM

  1. The single product page showed a 404

Screen Shot 2023-02-15 at 3 12 16 PM

  1. I went to the WP Dashboard > Settings > Permalinks. I made no edits then pressed Save
  2. I refreshed the single product page and there was no 404 error, the page loaded as expected.

@EricBusch Have you seen any reports of 404's on product pages? Are you able to recreate this issue?

Product Set update process for V2

Here's the outline for database tables and processing a Product Set update in order to prevent duplicate product entries (because of a race condition occurring).

Our main table with be datafeedr_productset_record_join

It will contain the following schema:

--
-- Table structure for table `datafeedr_productset_record_join`
--

CREATE TABLE `datafeedr_productset_record_join` (
  `id` int(20) UNSIGNED NOT NULL,
  `product_set_id` int(20) UNSIGNED NOT NULL,
  `record_id` bigint(20) UNSIGNED NOT NULL,
  `post_type` varchar(50) NOT NULL,
  `action` varchar(50) NOT NULL,
  `status` int(1) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `datafeedr_productset_record_join`
--

INSERT INTO `datafeedr_productset_record_join` 
(`id`, `product_set_id`, `record_id`, `post_type`, `action`, `status`) 
VALUES
(1, 123, 3273500000006527, 'product', 'update', 0),
(2, 123, 3273500000018502, 'product', 'update', 0),
(3, 123, 3273500000018503, 'product', 'create', 0),
(4, 123, 3273500000018504, 'product', 'create', 0);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `datafeedr_productset_record_join`
--
ALTER TABLE `datafeedr_productset_record_join`
  ADD PRIMARY KEY (`product_set_id`,`record_id`),
  ADD UNIQUE KEY `record_id` (`record_id`,`post_type`),
  ADD KEY `id` (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `datafeedr_productset_record_join`
--
ALTER TABLE `datafeedr_productset_record_join`
  MODIFY `id` int(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

In the table, action is what we need to do with the product and status indicates what we have done.

Example: action=create & status=0 This means we will be creating a new product in WordPress but we have not done so yet.

action=create, status=0 - A product should be created but has not yet been created.
action=create, status=1 - A product has been created.
action=update, status=0 - A product should be updated but has not yet been updated.
action=update, status=1 - A product has been updated.
action=delete, status=0 - A product should be deleted but has not yet been deleted.
action=delete, status=1 - A product has been deleted.

This will also allow accurate stats tracking for a Product Set update making it easy for us to capture how many products were added, updated and deleted.

Additionally, it will make it really easy to find all of the products which need to be deleted. Just a simple:

SELECT * 
FROM datafeedr_productset_record_join 
WHERE product_set_id = $this_product_set_id 
AND action = 'delete' 
AND status = 0

1. Start Update

When we start a Product Set update, first we will issue an UPDATE query on the datafeedr_productset_record_join table setting status equal to 0 for the current Product Set and if the action = update.

UPDATE datafeedr_productset_record_join 
SET 
	action = 'update', 
	status = 0 
WHERE product_set_id = $this_product_set_id

2. Add Datafeedr records to tables

Next, we'll query all of the products in the Product Set from the Datafeedr API and INSERT the products into the datafeedr_records table.

- `INSERT ... ON DUPLICATE KEY UPDATE` all products into the `datafeedr_products` table
- Then we'll do a query like this to add all NEW products into the 
INSERT IGNORE INTO datafeedr_productset_record_join 
	( product_set_id, record_id, post_type, action, status )
VALUES
	( 123, 3273500000006527, 'product', 'create', 0 ),
	( 123, 3273500000018502, 'product', 'create', 0 ),
	( 123, 3273500000018503, 'product', 'create', 0 ),
	( 123, 3273500000018504, 'product', 'create', 0 ),
	( 123, 3273500000018503, 'product', 'create', 0 )

3. Now we can perform quick queries to import the data like this:

Next we can issue this query in a loop to import products into WordPress:

// Get a row from productset_record_join to add to WordPress
// @link https://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
// @link https://dba.stackexchange.com/questions/46459/putting-a-select-statement-in-a-transaction
// @link https://dba.stackexchange.com/questions/182963/can-two-mysql-select-for-update-from-mytable-where-in-deadlock


START TRANSACTION;

SELECT @id := id FROM datafeedr_productset_record_join 
WHERE action IN ( 'create', 'update' )
AND status = 0
ORDER BY id ASC
LIMIT 1
FOR UPDATE;

// Get the record data
$record = SELECT data FROM datafeedr_records WHERE id = $row->id LIMIT 1;

// Insert or Update Post
if ( 'create' == $row->action ) {
	$post_id = 	wp_insert_post( $record data );
} else {
	$post_id = 	wp_update_post( $record data );
}

// Update datafeedr_productset_record_join 
UPDATE datafeedr_productset_record_join 
SET status = 1 
WHERE id = @id;

COMMIT;

Add Unit Tests

Overview

This issue includes adding a method for running unit tests on the code to make sure new functionality does not introduce bugs in existing functionality.

Description

Testing will be added using PHPUnit since it is the testing framework chosen by the core team.

A composer file will be added to handle managing required packages and defining scripts for testing.

Tasks

  • Add composer.json.
  • Add phpunit.xml.
  • Add setup script
  • Add bootstrap file.
  • Add tests for functions in #14.

Create new dfrps_is_registered_cpt() function

We need to move this code:

	$registered_cpts = get_option( 'dfrps_registered_cpts', array() );
	if ( ! array_key_exists( $post->post_type, $registered_cpts ) ) {
		return false;
	}

to its own function.

Then reference that function from dfrps_do_import_product_thumbnail().

Last Update shows incorrect datetime on first update

Steps to recreate

  1. Create a new Product Set.
  2. Add a product search query.
  3. Add a category to put products in.
  4. Add a Custom Update Schedule (This step might be optional).
  5. Publish the Product Set.

The Product Set will begin to be imported and the Dashboard meta box will show progress.
In the Last Update meta box the Started and Completed values are 0 in the database so are displayed as the start of the UNIX Epoch.
Edit Product Set “Minecraft Toys” ‹ Datafeedr Ecommerce — WordPress 2023-02-15 13-59-51

Suggested change

Change the template to change these datetime values to meaningful text.
@EricBusch Please suggest some text that would make sense in this situation.

Warning: Undefined array key "_dfrps_cpt_last_update_time_completed"

Getting the following error report from a customer:

After adding products to new product sets I get the following message:

Warning: Undefined array key "_dfrps_cpt_last_update_time_completed" in ~/wp-content/plugins/datafeedr-product-sets/classes/class-dfrps-cpt.php on line 1143 Warning: Trying to access array offset on value of type null in ~/wp-content/plugins/datafeedr-product-sets/classes/class-dfrps-cpt.php on line 1143 This Product Set has never been imported.

Not sure if it's related to 1.3.16 or goes back further. Can you have a look when you get a chance?

Update "_dfrps_product_check_image" if $url is empty during image import

In helper.php

	$url = dfrps_featured_image_url( $post->ID );

	if ( empty( $url ) ) {
		update_post_meta( $post->ID, '_dfrps_product_check_image', 0 );

		return new WP_Error(
			'dfrps_url_empty',
			__( '$url is empty.', 'datafeedr-product-sets' ),
			array( 'function' => __FUNCTION__, '$post' => $post, '$url' => $url )
		);
	}

Custom Product Set Update Schedule

Overview

This issue includes adding a feature to let customers set a custom update schedule for each Product Set.

Analysis

Currently there is a global setting for update interval at WordPress Dashboard > Product Sets > Configuration > Update Interval

When the dfrps_cron hook fires it will pull one PS post to process based on the _dfrps_cpt_next_update_time meta. The post is updated or deleted based on post status. Trashed posts have their products deleted and will not get a next update time. At the end of phase 5 of the update the next update meta is set by dfrps_get_next_update_time().

Proposed changes

  1. Add a meta box to the PS CPT to let store managers enable a custom schedule. The schedule will include the following configuration options:
Field Type Default Values
Enabled checkbox no yes, or no
Interval radio button Day of week 'Day of week' or 'Day of the month'
Days (if Day of week selected) multi select blank One line for each day of week. Value stored as 0-6.
Days (if Day of the) multi select blank One line for day of month 1 to 28.
Time (HH:MM) select 00:00 First select will have 0-24 for hour, 0-60 for minutes.
  1. Update dfrps_get_next_update_time() to check the post for a custom update time, if not found use the global setting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.