Magento – M2 Enterprise: How to add Special Price for product from date to date programmatically

catalog-stagingmagento-2.1magento-enterpriseproductspecial-price

I want to add a Special Price for a product from date to date programmatically by code but don't know how.

I can set in admin but I want to use code to save multiple products.

I use Enterprise Edition and don't have the date fields. Instead the content staging feature is used to schedule price changes.

enter image description here

in EE using scheduled:
enter image description here

in Scheduled:
enter image description here

Best Answer

Try using Magento\Staging\Model\Entity\Update\Save to schedule a new update:

$this->stagingUpdateSave->execute(
    [
        'entityId' => 1234,           // <-- your product id
        'stagingData' => [
            'mode' => 'save',
            'name' => 'Test Special Price Update',
            'start_time' => 'Feb 25, 2017 12:00 AM'
            'end_time' => 'Feb 26, 2017 12:00 AM'
         ],
        'entityData' => [
            'product' => [
                'price' => '1.00',
            ],
        ],
    ]
);