Ejemplo n.º 1
0
 /**
  * CMS block cache, must use the block id from the database
  *
  * @param type $block
  */
 public function applyCmsBlock($block)
 {
     // The "messages" block is session-dependent, don't cache
     if (Mage::helper('cache')->responseHasMessages()) {
         $block->setData('cache_lifetime', null);
         return;
     }
     // Set cache tags
     $tags = array();
     $blockId = $block->getData('block_id');
     if ($blockId) {
         $cmsBlock = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load($blockId);
         if ($cmsBlock->getIsActive()) {
             $tags = $block->getCacheTags();
             $tags[] = Mage_Cms_Model_Block::CACHE_TAG . '_' . $cmsBlock->getId();
         }
     }
     $block->setData('cache_tags', $tags);
     // Set cache key
     $keys = $block->getCacheKeys();
     $blockId = $block->getData('block_id');
     if ($blockId) {
         $cmsBlock = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load($blockId);
         if ($cmsBlock->getIsActive()) {
             $keys = $block->getCacheKeyInfo();
             if (!is_array($keys)) {
                 $keys = array();
             }
             $keys[] = $blockId;
             $keys[] = $block->getLayout()->getUpdate()->getCacheId();
         }
     }
     $block->setData('cache_keys', $keys);
 }
Ejemplo n.º 2
0
 /**
  * Set tier price
  * 
  * @param type $product
  * 
  * @return Innoexts_StorePricing_Helper_Catalog_Product_Price
  */
 public function setTierPrice($product)
 {
     $attribute = $this->getTierPriceAttribute();
     if (!$attribute) {
         return $this;
     }
     $backend = $attribute->getBackend();
     if (!$backend) {
         return $this;
     }
     $helper = $this->getStorePricingHelper();
     $store = $helper->getCurrentStore();
     $isEditMode = $product->getData('_edit_mode');
     $websiteId = null;
     $storeId = null;
     if ($this->isGlobalScope()) {
         $websiteId = null;
         $storeId = null;
     } else {
         if ($this->isWebsiteScope() && $store->getId()) {
             $websiteId = $store->getWebsiteId();
             $storeId = null;
         } else {
             if ($this->isStoreScope() && $store->getId()) {
                 $websiteId = $store->getWebsiteId();
                 $storeId = $store->getId();
             }
         }
     }
     $typeId = $product->getTypeId();
     $tierPrices = $product->getTierPrices();
     if (!empty($tierPrices) && !$isEditMode) {
         $tierPrices = $backend->preparePriceData2($tierPrices, $typeId, $websiteId, $storeId);
     }
     $product->setFinalPrice(null);
     $product->setData('tier_price', $tierPrices);
     return $this;
 }
 /**
  * Confirm an adjust stock
  * 
  * @param type $model
  * @param type $data
  * @param type $admin
  */
 public function confirmAdjuststock($model, $data, $admin)
 {
     $model->setData('reason', $data['reason'])->setData('confirmed_by', $admin)->setData('confirmed_at', now())->setStatus(1);
     $model->save();
 }
Ejemplo n.º 4
0
 /**
  * Builds request for DeliverInvoice for Invoice and PaymentPlan payment.
  * Calls from Magento Capture
  *
  * @param type $invoice
  * @param type $auth
  * @param type $sveaOrderId
  * @return type
  */
 public function getDeliverInvoiceRequest($invoice, $auth, $sveaOrderId)
 {
     $conf = new SveaMageConfigProvider($auth);
     $sveaObject = WebPay::deliverOrder($conf);
     $order = $invoice->getOrder();
     $countryCode = $order->getBillingAddress()->getCountryId();
     $storeId = $order->getStoreId();
     $store = Mage::app()->getStore($storeId);
     $taxCalculationModel = Mage::getSingleton('tax/calculation');
     $taxConfig = Mage::getSingleton('tax/config');
     // Add invoiced items
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         if ($orderItem->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
             continue;
         }
         // Default to the item price
         $name = $item->getName();
         $price = $orderItem->getPrice();
         $priceInclTax = $orderItem->getPriceInclTax();
         $taxPercent = $orderItem->getTaxPercent();
         if (!(int) $taxPercent) {
             $taxPercent = false;
         }
         $parentItem = $orderItem->getParentItem();
         if ($parentItem) {
             switch ($parentItem->getProductType()) {
                 case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE:
                     $price = $parentItem->getPrice();
                     $priceInclTax = $parentItem->getPriceInclTax();
                     $taxPercent = $parentItem->getTaxPercent();
                     break;
                 case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
                     $taxPercent = $priceInclTax = $price = 0;
                     $name = '- ' . $name;
                     break;
             }
         }
         if ($taxPercent === false) {
             // If it's a bundle item we have to calculate the tax from
             // the including/excluding tax values
             $taxPercent = round(100 * ($priceInclTax / $price - 1));
         }
         switch (get_class($item)) {
             case 'Mage_Sales_Model_Quote_Item':
             case 'Mage_Sales_Model_Order_Invoice_Item':
             case 'Mage_Sales_Model_Order_Creditmemo_Item':
                 $qty = $item->getQty();
                 break;
             default:
                 $qty = $item->getQtyOrdered();
                 break;
         }
         $orderRow = WebPayItem::orderRow()->setArticleNumber($item->getSku())->setQuantity((int) $qty)->setName($name)->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent((int) $taxPercent);
         if ($taxConfig->priceIncludesTax($storeId)) {
             $orderRow->setAmountIncVat((double) $priceInclTax);
         } else {
             $orderRow->setAmountExVat((double) $price);
         }
         $sveaObject->addOrderRow($orderRow);
     }
     $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), null, $store);
     // Add shipping fee
     if ($invoice->getShippingAmount() > 0) {
         $shippingFee = WebPayItem::shippingFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName($order->getShippingDescription());
         // We require shipping tax to be set
         $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $storeId);
         $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass));
         $shippingFee->setVatPercent((int) $rate);
         if ($taxConfig->shippingPriceIncludesTax($storeId)) {
             $shippingFee->setAmountIncVat($invoice->getShippingInclTax());
         } else {
             $shippingFee->setAmountExVat($invoice->getShippingAmount());
         }
         $sveaObject->addFee($shippingFee);
     }
     // Possible discount
     $discount = abs($invoice->getDiscountAmount());
     if ($discount) {
         $discountRow = WebPayItem::fixedDiscount()->setAmountIncVat($discount)->setName(Mage::helper('svea_webpay')->__('discount'))->setUnit(Mage::helper('svea_webpay')->__('unit'));
         $sveaObject->addDiscount($discountRow);
     }
     // Gift card(s)
     if (abs($order->getGiftCardsAmount())) {
         $giftCardRow = WebPayItem::fixedDiscount()->setAmountIncVat(abs($order->getGiftCardsAmount()))->setUnit(Mage::helper('svea_webpay')->__('unit'));
         $sveaObject->addDiscount($giftCardRow);
     }
     // Invoice fee
     $paymentFee = $invoice->getSveaPaymentFeeAmount();
     $paymentFeeInclTax = $invoice->getSveaPaymentFeeInclTax();
     $invoiced = $invoice->getOrder()->getSveaPaymentFeeInvoiced();
     if ($paymentFee > 0 && $invoiced == 0) {
         $invoiceFee = WebPayItem::invoiceFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName(Mage::helper('svea_webpay')->__('invoice_fee'))->setAmountExVat($paymentFee)->setAmountIncVat($paymentFeeInclTax);
         $sveaObject->addFee($invoiceFee);
         $invoice->getOrder()->setSveaPaymentFeeInvoiced($paymentFeeInclTax);
     }
     $sveaObject = $sveaObject->setCountryCode($countryCode)->setOrderId($sveaOrderId)->setInvoiceDistributionType(Mage::getStoreConfig("payment/svea_invoice/deliver_method"));
     $invoice->setData('svea_deliver_request', $sveaObject);
     return $invoice->getData('svea_deliver_request');
 }