MarcinPaul.pl

Archiwum z miesiąca Czerwiec 2013

Kilka linijek kodu pozwalające na pobranie szczegółowych informacji o regule promocyjnej na podstawie wpisanego kodu rabatowego:

$code = Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode();
$oCoupon = Mage::getModel('salesrule/coupon')->load($code,'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
$rule_desc = $oRule->getData('description');
$couponId = Mage::getModel('salesrule/coupon')->load($code,'code')->getRuleId();
$couponObj = Mage::getModel('salesrule/rule')->load($couponId);
$ruleArr = Mage::getModel('salesrule/rule')->load($couponObj->getRuleId())->getStoreLabels();

·

Rozwiązanie błędu reindeksacji indeksu catalog_product_attribute. Wystarczy wyczyścić bazę danych z ‚pustych’ wpisów, np. Magento chce dodać do tabeli catalog_product_index_eav produkty, których już nie ma w sklepie.

delete from `catalog_category_product` WHERE product_id not in (select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE category_id not in (select entity_id from catalog_category_entity);
delete from `catalog_product_website` WHERE product_id not in (select entity_id from catalog_product_entity);
delete from `catalog_product_entity_media_gallery` WHERE entity_id not in (select entity_id from catalog_product_entity);
delete from `catalog_product_index_eav_idx` WHERE entity_id not in (select entity_id from catalog_product_entity);
delete from `catalog_product_index_eav` WHERE entity_id not in (select entity_id from catalog_product_entity);
delete from `catalog_product_link` WHERE product_id not in (select entity_id from catalog_product_entity);
delete from `catalog_product_relation` WHERE parent_id not in (select entity_id from catalog_product_entity);

·

Proste rozwiązanie zapisania się do newslettera do kilku sklepów na ten sam adres e-mail na jednej instalacji Magento.

Plik app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php kopiujemy do  app/code/local/Mage/Newsletter/Model/Mysql4/Subscriber.php, zmieniamy funkcję loadByEmail($subscriberEmail) na:

<?php
public function loadByEmail($subscriberEmail) {
 /** @var $customerSession Mage_Customer_Model_Session */
 $customerSession = Mage::getSingleton('customer/session');
 $ownerId = Mage::getModel('customer/customer')
 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
 ->loadByEmail($subscriberEmail)
 ->getId();
 $storeId = $customerSession->isLoggedIn() && $ownerId == $customerSession->getId()
 ? $customerSession->getCustomer()->getStoreId()
 : Mage::app()->getStore()->getId();
 $select = $this->_read->select()
 ->from($this->getMainTable())
 ->where('subscriber_email=:subscriber_email')
 ->where('store_id=:store_id'); // Add store ID for newsletters
 $result = $this->_read->fetchRow($select, array(
 'subscriber_email' => $subscriberEmail,
 'store_id' => $storeId
 ));
 if (!$result) {
 return array();
 }
 return $result;
}
?>

oraz funkcję loadByCustomer(Mage_Customer_Model_Customer $customer) na:

<?php
public function loadByCustomer(Mage_Customer_Model_Customer $customer) {
 $select = $this->_read->select()
 ->from($this->getMainTable())
 ->where('customer_id=:customer_id')
 ->where('store_id=:store_id');
 $result = $this->_read->fetchRow($select, array(
 'customer_id' => $customer->getId(),
 'store_id' => $customer->getStoreId()
 ));
 if ($result) {
 return $result;
 }
 $select = $this->_read->select()
 ->from($this->getMainTable())
 ->where('subscriber_email=:subscriber_email')
 ->where('store_id=:store_id');
 $result = $this->_read->fetchRow($select, array(
 'subscriber_email' => $customer->getEmail(),
 'store_id' => $customer->getStoreId()
 ));
 if ($result) {
 return $result;
 }
 return array();
}
?>

newsletter

Rozwiązanie sprawdzone na wersjach Magento >= 1.4.x.x.

·