Skip to content

Instantly share code, notes, and snippets.

@6ui11em
6ui11em / save_attribute_storeid.php
Created January 24, 2018 09:27
Magento 2 save product attribute in specific store #magento2 #php
// get current store and product store to restore values after save
$currentStore = $this->storeManager->getStore();
$productStore = $product->getStoreId();
// save to desired storeId
$this->storeManager->setCurrentStore($storeId);
$product->setStoreId($storeId);
// you can use also $product->setName ...
$product->setData($attributeCode, $value);
$this->productResource->saveAttribute($product, $attributeCode);
@peterjaap
peterjaap / Observer.php
Created June 2, 2015 10:34
Fixed Orchid_CouponFix_Model_Observer for Magento 1.7+
<?php
class Orchid_CouponFix_Model_Observer
{
public function cancel($observer)
{
$resource = Mage::getModel('core/resource');
$db = $resource->getConnection('core_write');
$event = $observer->getEvent();
$order = $event->getPayment()->getOrder();
if ($order->canCancel()) {