pricemind/magento-connector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pricemind/magento-connector

Composer 安装命令:

composer require pricemind/magento-connector

包简介

Tracks Magento price changes and sends them asynchronously to an external API.

README 文档

README

A Magento 2 module that automatically tracks product price changes and synchronizes them with the Pricemind API for competitive price monitoring and analysis.

Features

  • Real-time Price Tracking: Automatically detects and sends product price changes to Pricemind
  • Special Price Support: Tracks special prices and their date ranges
  • Custom Fields Integration: Syncs special price start/end dates as custom fields
  • Multi-store Support: Website-level configuration for different stores
  • Error Handling: Failed API requests are logged and stored for retry
  • Non-blocking: Uses short timeouts to avoid disrupting store operations
  • Secure Configuration: API keys are encrypted in the database

Requirements

  • Magento 2.3+
  • PHP 7.4+
  • Active Pricemind account with API access

Installation

Via Composer (Recommended)

composer require pricemind/magento-connector
php bin/magento module:enable Stellion_Pricemind
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Manual Installation

  1. Download the module files
  2. Extract to app/code/Stellion/Pricemind/
  3. Run the following commands:
php bin/magento module:enable Stellion_Pricemind
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Configuration

Admin Configuration

  1. Navigate to Stores → Configuration → Pricemind → API
  2. Configure the following settings:

API Settings

  • Base URL: Pricemind API endpoint (default: https://api.pricemind.io/)
  • API Access Key: Your Pricemind API key in format <key_id>.<version>.<secret>
  • Channel: Select your Pricemind channel (populated after saving API key)

Source Detection

The module automatically detects and displays:

  • Detected Source is Magento: Shows if the channel source is identified as Magento
  • Source Type: The detected source type
  • Source Title: The source title from Pricemind

Multi-store Configuration

The module supports website-level configuration:

  1. Set Configuration Scope to your desired website
  2. Configure API settings for each website independently
  3. Each website can use different Pricemind channels

How It Works

Price Change Detection

The module listens for the catalog_product_save_commit_after event and detects changes in:

  • Regular Price (price)
  • Special Price (special_price)
  • Special Price From Date (special_from_date)
  • Special Price To Date (special_to_date)

API Integration

When a price change is detected, the module:

  1. Sends Price Data to POST /v1/channels/{channelId}/prices:

    {
      "product_sku": "V92516",
      "price": "100.00",
      "currency": "USD",
      "special_price": "90.00",
      "includes_tax": true
    }
  2. Sends Special Price Dates to PUT /v1/custom-fields:

    {
      "channel_id": 123,
      "machine_name": "special_price_start_date",
      "product_sku": "V92516",
      "value": "2024-01-01"
    }

Custom Fields Mapping

Special price date ranges are mapped to custom fields:

  • special_from_datespecial_price_start_date
  • special_to_datespecial_price_end_date

Error Handling

Failed API requests are stored in the stellion_pricemind_failed_request table with:

  • Request details (endpoint, method, headers, payload)
  • Error message and status
  • Retry count and next attempt timestamp
  • Created/updated timestamps

Database Schema

The module creates one table:

stellion_pricemind_failed_request

Stores failed API requests for potential retry processing:

Column Type Description
entity_id INT Primary key
endpoint VARCHAR(255) Target API endpoint
method VARCHAR(16) HTTP method
headers TEXT Request headers (JSON)
payload TEXT Request payload (JSON)
error TEXT Last error message
retry_count INT Number of retry attempts
status SMALLINT Status (0=pending, 1=retrying, 2=abandoned, 3=sent)
next_attempt_at TIMESTAMP Next retry timestamp
created_at TIMESTAMP Created timestamp
updated_at TIMESTAMP Updated timestamp

API Endpoints Used

The module integrates with these Pricemind API endpoints:

  • GET /v1/channels - Fetch available channels
  • GET /v1/channels/{id}/sources/active - Get active channel source
  • GET /v1/channels/{id}/product-domain?sku={sku} - Lookup product domain
  • POST /v1/channels/{id}/prices - Create/update price
  • PUT /v1/custom-fields - Update custom field values

Security

  • API Key Encryption: API keys are encrypted using Magento's encryption service
  • Masked Logging: API keys are masked in error logs as ***
  • Short Timeouts: 1-2 second timeouts prevent long-running requests
  • ACL Permissions: Admin configuration requires Stellion_Pricemind::config permission

Performance Considerations

  • Non-blocking: Short timeouts (1s connect, 2s total) prevent blocking store operations
  • Async Processing: Price updates are sent asynchronously during product saves
  • Error Tolerance: Failed requests don't disrupt normal store functionality
  • Selective Updates: Only sends data when prices actually change

Troubleshooting

Common Issues

  1. No price updates sent:

    • Verify API key is configured and valid
    • Check channel ID is selected
    • Ensure product prices are actually changing
  2. API connection errors:

    • Verify Base URL is correct
    • Check firewall/network connectivity
    • Review error logs in var/log/system.log
  3. Channel not loading:

    • Save API key configuration first
    • Check API key format: <key_id>.<version>.<secret>
    • Verify API key has channel access

Logging

The module logs events with the prefix [Stellion_Pricemind]:

  • Warnings: Non-2xx API responses, send failures
  • Errors: API key decryption failures, channel fetch errors

Check logs in:

  • var/log/system.log
  • var/log/exception.log

Failed Requests

Monitor failed requests in the database:

SELECT * FROM stellion_pricemind_failed_request 
WHERE status = 0 
ORDER BY created_at DESC;

Development

Module Structure

app/code/Stellion/Pricemind/
├── Block/Adminhtml/System/Config/Form/Field/
│   └── Channel.php              # Channel selection field
├── Model/
│   ├── Api/Client.php           # Pricemind API client
│   ├── Config/
│   │   ├── Backend/Channel.php  # Channel config backend
│   │   └── Source/Channels.php  # Channel options source
│   ├── FailedRequest.php        # Failed request model
│   ├── ResourceModel/           # Database resources
│   └── Sender.php               # HTTP request sender
├── Observer/
│   └── ProductPriceChangeObserver.php  # Main price change handler
├── etc/
│   ├── acl.xml                  # Admin permissions
│   ├── adminhtml/system.xml     # Admin configuration
│   ├── config.xml               # Default configuration
│   ├── db_schema.xml            # Database schema
│   ├── events.xml               # Event observers
│   └── module.xml               # Module declaration
└── registration.php             # Module registration

Extending the Module

To extend functionality:

  1. Add Custom Fields: Modify the observer to send additional product attributes
  2. Retry Logic: Implement cron job to retry failed requests
  3. Bulk Updates: Add CLI command for bulk price synchronization
  4. Webhooks: Add webhook endpoint for bidirectional sync

Support

For technical support or feature requests:

License

This module is released under the MIT License. See LICENSE file for details.

Changelog

Version 1.0.0

  • Initial release
  • Real-time price change tracking
  • Special price and date range support
  • Multi-store configuration
  • Error handling and logging
  • Failed request storage

pricemind/magento-connector 适用场景与选型建议

pricemind/magento-connector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 200 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「magento2」 「api-integration」 「pricemind」 「price-tracking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pricemind/magento-connector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pricemind/magento-connector 我们能提供哪些服务?
定制开发 / 二次开发

基于 pricemind/magento-connector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 200
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-29