示例#1
0
 protected function _getFinalPrice($product, $price)
 {
     $discountedObj = new Varien_Object(array('price' => $price, 'discounted' => false));
     Mage::dispatchEvent('affiliateplus_product_get_final_price', array('product' => $product, 'discounted_obj' => $discountedObj));
     if ($discountedObj->getDiscounted()) {
         return $discountedObj->getPrice();
     }
     $price = $discountedObj->getPrice();
     $discountType = $this->_getConfigHelper()->getDiscountConfig('discount_type');
     $discountValue = $this->_getConfigHelper()->getDiscountConfig('discount');
     if (Mage::helper('affiliateplus/cookie')->getNumberOrdered()) {
         if ($this->_getConfigHelper()->getDiscountConfig('use_secondary')) {
             $discountType = $this->_getConfigHelper()->getDiscountConfig('secondary_type');
             $discountValue = $this->_getConfigHelper()->getDiscountConfig('secondary_discount');
         }
     }
     if ($discountType == 'fixed' || $discountType == 'cart_fixed') {
         $price -= floatval($discountValue);
     } elseif ($discountType == 'percentage') {
         $price -= floatval($discountValue) / 100 * $price;
     }
     if ($price < 0) {
         return 0;
     }
     return $price;
 }
 public function _getValue(Varien_Object $row)
 {
     $value = '<span id="price_label_' . $row->getId() . '" data-id="' . $row->getId() . '">' . $this->helper('core')->formatPrice($row->getPrice(), false) . '</span>';
     $value .= '<input type="text" id="price_value_' . $row->getId() . '" name="price_value[' . $row->getId() . ']" data-id="' . $row->getId() . '" value="' . number_format($row->getPrice(), 2) . '" style="width: 100px;margin-right: 2px;display:none">';
     $value .= '<button id="price_button_' . $row->getId() . '" data-id="' . $row->getId() . '" onclick="vcUpdateInfor(' . $row->getId() . ',\'price\')" style="display:none"><span><span>Update</span></span></button>';
     $value .= '<img id="price_waiting_' . $row->getId() . '" src="' . $this->getSkinUrl('vc_easyupdateproductinfor/images/ajax-loader.gif') . '" class="v-middle" style="display:none" />';
     return $value;
 }
示例#3
0
 /**
  * Render minimal price for downloadable products
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     if ($row->getTypeId() == 'downloadable') {
         $row->setPrice($row->getPrice());
     }
     return parent::render($row);
 }
示例#4
0
 /**
  * Render minimal price for downloadable products
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     if ($row->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
         $row->setPrice($row->getPrice());
     }
     return parent::render($row);
 }
示例#5
0
 protected function _getFinalPrice($product, $price)
 {
     $discountedObj = new Varien_Object(array('price' => $price, 'discounted' => false));
     Mage::dispatchEvent('affiliateplus_product_get_final_price', array('product' => $product, 'discounted_obj' => $discountedObj));
     if ($discountedObj->getDiscounted()) {
         return $discountedObj->getPrice();
     }
     $price = $discountedObj->getPrice();
     if ($this->_getConfigHelper()->getGeneralConfig('discount_type') == 'fixed') {
         $price -= floatval($this->_getConfigHelper()->getGeneralConfig('discount'));
     } elseif ($this->_getConfigHelper()->getGeneralConfig('discount_type') == 'percentage') {
         $price -= floatval($this->_getConfigHelper()->getGeneralConfig('discount')) / 100 * $price;
     }
     if ($price < 0) {
         return 0;
     }
     return $price;
 }
示例#6
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /** @var Mage_Catalog_Model_Product $product */
     $product = $object->getProduct();
     if (!$product instanceof Mage_Catalog_Model_Product) {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     return parent::validate($product);
 }
示例#7
0
文件: Price.php 项目: bevello/bevello
 /**
  * Properly render the price
  *
  * @param Varien_Object $row
  * @return string
  */
 public function render(Varien_Object $row)
 {
     $storeId = $this->getRequest()->getParam('store', 0);
     list($base, $currency, $options) = Mage::helper('bronto_product')->currencyAndOptions($storeId);
     $price = $row->getPrice();
     if ($base != $currency) {
         $price = $base->convert($price, $currency, $options);
     }
     return $currency->formatTxt($price, $options);
 }
示例#8
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product && $object->getData($this->getAttribute()) !== null) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     return parent::validate($product);
 }
示例#9
0
 /**
  * Render minimal price for downloadable products
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     if ($row->getTypeId() == 'downloadable') {
         $row->setPrice($row->getPrice());
     }
     $Product = Mage::getModel('catalog/product')->load($row->getData('entity_id'));
     if (Mage::helper('request4quote')->isRentalInstalled()) {
         if ($row->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE || $Product->getIsReservation() != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED) {
             $row->setPrice('');
         }
     }
     return parent::render($row);
 }
示例#10
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /** @var Mage_Catalog_Model_Product $product */
     $product = $object->getProduct();
     if (!$product instanceof Mage_Catalog_Model_Product) {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     $valid = parent::validate($product);
     if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
         $children = $object->getChildren();
         $valid = $children && $this->validate($children[0]);
     }
     return $valid;
 }
示例#11
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $op = $this->getOperator();
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     if (!$product->getData($this->getAttribute()) && ($op != '==' || $op != '!=') && $this->getAttribute() != 'category_ids') {
         return false;
     }
     return parent::validate($product);
 }
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  *
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     /** @var Mage_Catalog_Model_Product $product */
     $product = $object->getProduct();
     if (!$product instanceof Mage_Catalog_Model_Product) {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     // Allows attributes to take custom option SKU into consideration
     if ($this->getAttribute() === self::QUOTE_ITEM_SKU) {
         $product->setData($this->getAttribute(), $object->getSku());
         $valid = Mage_Rule_Model_Condition_Product_Abstract::validate($product);
     } else {
         $valid = parent::validate($object);
     }
     if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
         $children = $object->getChildren();
         $valid = $children && $this->validate($children[0]);
     }
     return $valid;
 }
示例#13
0
文件: Fedex.php 项目: sshegde123/wmp8
 /**
  * Form array with appropriate structure for shipment request
  *
  * @param Varien_Object $request
  * @return array
  */
 protected function _formShipmentRequest(Varien_Object $request)
 {
     if ($request->getReferenceData()) {
         $referenceData = $request->getReferenceData() . $request->getPackageId();
     } else {
         $referenceData = 'Order #' . $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId();
     }
     $packageParams = $request->getPackageParams();
     $customsValue = $packageParams->getCustomsValue();
     $height = $packageParams->getHeight();
     $width = $packageParams->getWidth();
     $length = $packageParams->getLength();
     $weightUnits = $packageParams->getWeightUnits() == Zend_Measure_Weight::POUND ? 'LB' : 'KG';
     $dimensionsUnits = $packageParams->getDimensionUnits() == Zend_Measure_Length::INCH ? 'IN' : 'CM';
     $unitPrice = 0;
     $itemsQty = 0;
     $itemsDesc = array();
     $countriesOfManufacture = array();
     $productIds = array();
     $packageItems = $request->getPackageItems();
     foreach ($packageItems as $itemShipment) {
         $item = new Varien_Object();
         $item->setData($itemShipment);
         $unitPrice += $item->getPrice();
         $itemsQty += $item->getQty();
         $itemsDesc[] = $item->getName();
         $productIds[] = $item->getProductId();
     }
     // get countries of manufacture
     $productCollection = Mage::getResourceModel('catalog/product_collection')->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', array('in' => $productIds))->addAttributeToSelect('country_of_manufacture');
     foreach ($productCollection as $product) {
         $countriesOfManufacture[] = $product->getCountryOfManufacture();
     }
     $paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
     $requestClient = array('RequestedShipment' => array('ShipTimestamp' => time(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), 'ServiceType' => $request->getShippingMethod(), 'Shipper' => array('Contact' => array('PersonName' => $request->getShipperContactPersonName(), 'CompanyName' => $request->getShipperContactCompanyName(), 'PhoneNumber' => $request->getShipperContactPhoneNumber()), 'Address' => array('StreetLines' => array($request->getShipperAddressStreet1(), $request->getShipperAddressStreet2()), 'City' => $request->getShipperAddressCity(), 'StateOrProvinceCode' => $request->getShipperAddressStateOrProvinceCode(), 'PostalCode' => $request->getShipperAddressPostalCode(), 'CountryCode' => $request->getShipperAddressCountryCode())), 'Recipient' => array('Contact' => array('PersonName' => $request->getRecipientContactPersonName(), 'CompanyName' => $request->getRecipientContactCompanyName(), 'PhoneNumber' => $request->getRecipientContactPhoneNumber()), 'Address' => array('StreetLines' => array($request->getRecipientAddressStreet1(), $request->getRecipientAddressStreet2()), 'City' => $request->getRecipientAddressCity(), 'StateOrProvinceCode' => $request->getRecipientAddressStateOrProvinceCode(), 'PostalCode' => $request->getRecipientAddressPostalCode(), 'CountryCode' => $request->getRecipientAddressCountryCode(), 'Residential' => (bool) $this->getConfigData('residence_delivery'))), 'ShippingChargesPayment' => array('PaymentType' => $paymentType, 'Payor' => array('AccountNumber' => $this->getConfigData('account'), 'CountryCode' => Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId()))), 'LabelSpecification' => array('LabelFormatType' => 'COMMON2D', 'ImageType' => 'PNG', 'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'), 'RateRequestTypes' => array('ACCOUNT'), 'PackageCount' => 1, 'RequestedPackageLineItems' => array('SequenceNumber' => '1', 'Weight' => array('Units' => $weightUnits, 'Value' => $request->getPackageWeight()), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $referenceData), 'SpecialServicesRequested' => array('SpecialServiceTypes' => 'SIGNATURE_OPTION', 'SignatureOptionDetail' => array('OptionType' => $packageParams->getDeliveryConfirmation())))));
     // for international shipping
     if ($request->getShipperAddressCountryCode() != $request->getRecipientAddressCountryCode()) {
         $requestClient['RequestedShipment']['CustomsClearanceDetail'] = array('CustomsValue' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue), 'DutiesPayment' => array('PaymentType' => $paymentType, 'Payor' => array('AccountNumber' => $this->getConfigData('account'), 'CountryCode' => Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId()))), 'Commodities' => array('Weight' => array('Units' => $weightUnits, 'Value' => $request->getPackageWeight()), 'NumberOfPieces' => 1, 'CountryOfManufacture' => implode(',', array_unique($countriesOfManufacture)), 'Description' => implode(', ', $itemsDesc), 'Quantity' => ceil($itemsQty), 'QuantityUnits' => 'pcs', 'UnitPrice' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $unitPrice), 'CustomsValue' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue)));
     }
     if ($request->getMasterTrackingId()) {
         $requestClient['RequestedShipment']['MasterTrackingId'] = $request->getMasterTrackingId();
     }
     // set dimensions
     if ($length || $width || $height) {
         $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = array();
         $dimenssions =& $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'];
         $dimenssions['Length'] = $length;
         $dimenssions['Width'] = $width;
         $dimenssions['Height'] = $height;
         $dimenssions['Units'] = $dimensionsUnits;
     }
     return $this->_getAuthDetails() + $requestClient;
 }
示例#14
0
 /**
  * Create and return new order item based on profile item data and $itemInfo
  * for initial payment
  *
  * @param Varien_Object $itemInfo
  * @return Mage_Sales_Model_Order_Item
  */
 protected function _getInitialItem($itemInfo)
 {
     $price = $itemInfo->getPrice() ? $itemInfo->getPrice() : $this->getInitAmount();
     $shippingAmount = $itemInfo->getShippingAmount() ? $itemInfo->getShippingAmount() : 0;
     $taxAmount = $itemInfo->getTaxAmount() ? $itemInfo->getTaxAmount() : 0;
     $item = Mage::getModel('sales/order_item')->setStoreId($this->getStoreId())->setProductType(Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL)->setIsVirtual(1)->setSku('initial_fee')->setName(Mage::helper('sales')->__('Recurring Profile Initial Fee'))->setDescription('')->setWeight(0)->setQtyOrdered(1)->setPrice($price)->setOriginalPrice($price)->setBasePrice($price)->setBaseOriginalPrice($price)->setRowTotal($price)->setBaseRowTotal($price)->setTaxAmount($taxAmount)->setShippingAmount($shippingAmount);
     $option = array('label' => Mage::helper('sales')->__('Payment type'), 'value' => Mage::helper('sales')->__('Initial period payment'));
     $this->_addAdditionalOptionToItem($item, $option);
     return $item;
 }
示例#15
0
 /**
  * Retrieve include tax html formated content
  *
  * @param Varien_Object $item
  * @return string
  */
 public function displayPriceInclTax(Varien_Object $item)
 {
     $qty = $item->getQtyOrdered() ? $item->getQtyOrdered() : ($item->getQty() ? $item->getQty() : 1);
     $baseTax = $item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0);
     $tax = $item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0);
     $basePriceTax = 0;
     $priceTax = 0;
     if (floatval($qty)) {
         $basePriceTax = $item->getBasePrice() + $baseTax / $qty;
         $priceTax = $item->getPrice() + $tax / $qty;
     }
     return $this->displayPrices($this->getOrder()->getStore()->roundPrice($basePriceTax), $this->getOrder()->getStore()->roundPrice($priceTax));
 }
示例#16
0
 /**
  * Get shipping rate code title and its price or error message
  *
  * @param Varien_Object $rate
  * @param string $format
  * @param string $inclTaxFormat
  * @return string
  */
 public function renderShippingRateOption($rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
 {
     $renderedInclTax = '';
     if ($rate->getErrorMessage()) {
         $price = $rate->getErrorMessage();
     } else {
         $price = $this->_getShippingPrice($rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax());
         $incl = $this->_getShippingPrice($rate->getPrice(), true);
         if ($incl != $price && $this->helper('tax')->displayShippingBothPrices()) {
             $renderedInclTax = sprintf($inclTaxFormat, Mage::helper('tax')->__('Incl. Tax'), $incl);
         }
     }
     return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax);
 }
示例#17
0
    /**
     * Retrieve quote items in XML format
     *
     * @return string
     */
    protected function _getItemsXml()
    {
        $xml = <<<EOT
        <items>

EOT;
        foreach ($this->getQuote()->getAllItems() as $item) {
            if ($item->getParentItem()) {
                continue;
            }
            $taxClass = $item->getTaxClassId() == 0 ? 'none' : $item->getTaxClassId();
            $weight = (double) $item->getWeight();
            $weightUnit = self::ITEM_WEIGHT_UNIT;
            $unitPrice = $item->getBaseCalculationPrice();
            if (Mage::helper('Mage_Weee_Helper_Data')->includeInSubtotal()) {
                $unitPrice += $item->getBaseWeeeTaxAppliedAmount();
            }
            $xml .= <<<EOT
            <item>
                <merchant-item-id><![CDATA[{$item->getSku()}]]></merchant-item-id>
                <item-name><![CDATA[{$item->getName()}]]></item-name>
                <item-description><![CDATA[{$item->getDescription()}]]></item-description>
                <unit-price currency="{$this->getCurrency()}">{$unitPrice}</unit-price>
                <quantity>{$item->getQty()}</quantity>
                <item-weight unit="{$weightUnit}" value="{$weight}" />
                <tax-table-selector>{$taxClass}</tax-table-selector>
                {$this->_getDigitalContentXml($item->getIsVirtual())}
                {$this->_getMerchantPrivateItemDataXml($item)}
            </item>

EOT;
        }
        $billingAddress = $this->getQuote()->getBillingAddress();
        $shippingAddress = $this->getQuote()->getShippingAddress();
        $shippingDiscount = (double) $shippingAddress->getBaseDiscountAmount();
        $billingDiscount = (double) $billingAddress->getBaseDiscountAmount();
        $discount = $billingDiscount + $shippingDiscount;
        // Exclude shipping discount
        // Discount is negative value
        $discount += $shippingAddress->getBaseShippingDiscountAmount();
        $discountItem = new Varien_Object(array('price' => $discount, 'name' => $this->__('Cart Discount'), 'description' => $this->__('A virtual item to reflect the discount total')));
        Mage::dispatchEvent('google_checkout_discount_item_price', array('quote' => $this->getQuote(), 'discount_item' => $discountItem));
        $discount = $discountItem->getPrice();
        if ($discount) {
            $xml .= <<<EOT
            <item>
                <merchant-item-id>_INTERNAL_DISCOUNT_</merchant-item-id>
                <item-name>{$discountItem->getName()}</item-name>
                <item-description>{$discountItem->getDescription()}</item-description>
                <unit-price currency="{$this->getCurrency()}">{$discount}</unit-price>
                <quantity>1</quantity>
                <item-weight unit="{$weightUnit}" value="0.00" />
                <tax-table-selector>none</tax-table-selector>
                {$this->_getDigitalContentXml($this->getQuote()->isVirtual())}
            </item>

EOT;
        }
        $hiddenTax = $shippingAddress->getBaseHiddenTaxAmount() + $billingAddress->getBaseHiddenTaxAmount();
        if ($hiddenTax) {
            $xml .= <<<EOT
            <item>
                <merchant-item-id>_INTERNAL_TAX_</merchant-item-id>
                <item-name>{$this->__('Discount Tax')}</item-name>
                <item-description>{$this->__('A virtual item to reflect the tax total')}</item-description>
                <unit-price currency="{$this->getCurrency()}">{$hiddenTax}</unit-price>
                <quantity>1</quantity>
                <item-weight unit="{$weightUnit}" value="0.00" />
                <tax-table-selector>none</tax-table-selector>
                {$this->_getDigitalContentXml($this->getQuote()->isVirtual())}
            </item>
EOT;
        }
        $xml .= <<<EOT
        </items>
EOT;
        return $xml;
    }
示例#18
0
 /**
  * calculate earning for quote/order item
  * 
  * @param Varien_Object $item
  * @param int $customerGroupId
  * @param int $websiteId
  * @param string $date
  * @return int
  */
 public function getCatalogItemEarningPoints($item, $customerGroupId = null, $websiteId = null, $date = null)
 {
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     //webpos
     $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
     if ($customerId) {
         $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
     } else {
         $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
     }
     if (is_null($websiteId)) {
         $websiteId = Mage::app()->getStore($item->getStoreId())->getWebsiteId();
     }
     if (is_null($date)) {
         $date = date('Y-m-d', strtotime($item->getCreatedAt()));
     }
     $cacheKey = "catalog_item_earning:{$item->getId()}:{$customerGroupId}:{$websiteId}";
     if ($this->hasCache($cacheKey)) {
         return $this->getCache($cacheKey);
     }
     $points = 0;
     $collectionKey = "catalog_earning_collection:{$customerGroupId}:{$websiteId}";
     if (!$this->hasCache($collectionKey)) {
         $rules = Mage::getResourceModel('rewardpointsrule/earning_catalog_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
         foreach ($rules as $rule) {
             $rule->afterLoad();
         }
         $this->saveCache($collectionKey, $rules);
     } else {
         $rules = $this->getCache($collectionKey);
     }
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         $price = 0;
         $profit = 0;
         foreach ($item->getChildren() as $child) {
             $price += $child->getQty() * $child->getBasePrice();
             $profit += $child->getQty() * ($child->getBasePrice() - $child->getBaseCost());
         }
     } else {
         $price = $item->getBasePrice();
         if (!$price && $item->getPrice()) {
             $price = $item->getPrice() / Mage::app()->getStore($item->getStoreId())->convertPrice(1);
         }
         $profit = $price - $item->getBaseCost();
     }
     foreach ($rules as $rule) {
         if ($rule->validate($product)) {
             $points += $this->calcCatalogPoint($rule->getSimpleAction(), $rule->getPointsEarned(), $price, $profit, $rule->getMoneyStep(), $rule->getMaxPointsEarned());
             if ($rule->getStopRulesProcessing()) {
                 break;
             }
         }
     }
     $this->saveCache($cacheKey, $points * $item->getQty());
     return $this->getCache($cacheKey);
 }
示例#19
0
 /**
  * Gets the final price of the freight
  * Follows the rules of free shipping
  *
  * @param Varien_Object $method
  * @return boolean|int|float
  */
 protected function _getFinalPrice(Varien_Object $method, Mage_Shipping_Model_Rate_Request $request)
 {
     $freeMethod = $this->getConfigData('free_shipping_method');
     if ($method->hasError() && !$method->getShowMessage() || $method->getPrice() <= 0) {
         return false;
     }
     if ($request->getFreeShipping() === true) {
         if ($freeMethod == 'lower-price') {
             if ($bestMethod = $this->getLowerPriceMethod($this->_getClientRequest())) {
                 if ($bestMethod->getCode() == $method->getCode()) {
                     return 0;
                 }
             }
         }
         if ($freeMethod == $method->getCode()) {
             return 0;
         }
     }
     $finalPrice = $method->getPrice();
     if ($handlingFee = $this->getConfigData('handling_fee')) {
         switch ($this->getConfigData('handling_type')) {
             case 'F':
                 $finalPrice += $handlingFee;
                 break;
             case 'P':
                 $finalPrice = $handlingFee * $finalPrice / 100 + $finalPrice;
                 break;
         }
     }
     return $finalPrice;
 }
示例#20
0
 /**
  * Add a usual line item with amount and qty
  *
  * @param Varien_Object $salesItem
  * @return Varien_Object
  */
 protected function _addRegularItem(Varien_Object $salesItem)
 {
     if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
         $qty = (int) $salesItem->getQtyOrdered();
         $amount = (double) $salesItem->getPrice();
         // TODO: nominal item for order
     } else {
         $qty = (int) $salesItem->getTotalQty();
         $amount = $salesItem->isNominal() ? 0 : (double) $salesItem->getCalculationPrice();
     }
     // workaround in case if item subtotal precision is not compatible with PayPal (.2)
     $subAggregatedLabel = '';
     if ($amount - round($amount, 2)) {
         $amount = $amount * $qty;
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     // aggregate item price if item qty * price does not match row total
     if ($amount * $qty != $salesItem->getRowTotal()) {
         $amount = (double) $salesItem->getRowTotal();
         $subAggregatedLabel = ' x' . $qty;
         $qty = 1;
     }
     return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
 }
示例#21
0
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $op = $this->getOperator();
     $product = false;
     if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
         $product = $object->getProduct();
     } else {
         $product = Mage::getModel('catalog/product')->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     //Validate with attribute is is_new
     if ($this->getAttribute() == 'is_new') {
         $result = true;
         if (!$product->getNewsFromDate() && !$product->getNewsToDate()) {
             $result = false;
         } else {
             $today = new DateTime(date('Y-m-d 00:00:00'));
             if ($from = $product->getNewsFromDate()) {
                 $fromNewDate = new DateTime($from);
                 if ($today < $fromNewDate) {
                     $result = false;
                 }
             }
             if ($to = $product->getNewsToDate()) {
                 $toNewDate = new DateTime($to);
                 if ($today > $toNewDate) {
                     $result = false;
                 }
             }
         }
         $value = $this->getValueParsed();
         if ($value == 0) {
             $result = !$result;
         }
         return $result;
     }
     //validate with attribute is is_special
     if ($this->getAttribute() == 'is_special') {
         $result = true;
         if (!$product->getSpecialPrice()) {
             $result = false;
         } else {
             $today = new DateTime(date('Y-m-d 00:00:00'));
             if (!($from = $product->getSpecialFromDate())) {
                 $fromNewDate = $today;
             } else {
                 $fromNewDate = new DateTime($from);
             }
             if (!($to = $product->getSpecialToDate())) {
                 $toNewDate = $today;
             } else {
                 $toNewDate = new DateTime($to);
             }
             if ($today < $fromNewDate || $toNewDate < $today) {
                 $result = false;
             }
             $value = $this->getValueParsed();
             if ($value == 0) {
                 $result = !$result;
             }
             return $result;
         }
     }
     //validate with attribute is qty
     if ($this->getAttribute() == 'qty') {
         $result = true;
         $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
         $value = $this->getValueParsed();
         switch ($op) {
             case '==':
             case '!=':
                 $result = $qty == $value;
                 break;
             case '>=':
             case '<':
                 $result = $qty >= $value;
                 break;
             case '<=':
             case '>':
                 $result = $qty <= $value;
                 break;
         }
         if ($op == '!=' || $op == '<' || $op == '>') {
             $result = !$result;
         }
         return $result;
     }
     //validate with attribute is qty
     if ($this->getAttribute() == 'out_of_stock') {
         $result = true;
         if ($product->isSaleable()) {
             $result = false;
         }
         if ($this->getValueParsed() == 0) {
             $result = !$result;
         }
         return $result;
     }
     //validate best seller
     if ($this->getAttribute() == 'best_seller') {
         $result = true;
         $value = $this->getValueParsed();
         // Get Best Seller product
         $storeId = Mage::app()->getStore()->getId();
         if (Mage::registry('bestSelletListId')) {
             $bestSellerId = Mage::registry('bestSelletListId');
         } else {
             $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc')->setPageSize($value);
             Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
             //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
             $bestSellerId = array();
             foreach ($products as $p) {
                 $bestSellerId[] = $p->getId();
             }
             if (!empty($bestSellerId)) {
                 Mage::register('bestSelletListId', $bestSellerId);
             }
         }
         if (!count($bestSellerId)) {
             $result = false;
         } else {
             $childProducts = null;
             if ($product->getTypeId() == 'configurable') {
                 $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
             } elseif ($product->getTypeId() == 'grouped') {
                 $childProducts = Mage::getModel('catalog/product_type_grouped')->getAssociatedProducts($product);
             } elseif ($product->getTypeId() == 'bundle') {
                 $childProducts = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
             } else {
                 if (!in_array($product->getId(), $bestSellerId)) {
                     return false;
                 }
             }
             $flag = 0;
             if (isset($childProducts)) {
                 foreach ($childProducts as $c) {
                     if (in_array($c->getId(), $bestSellerId)) {
                         $flag = 1;
                         break;
                     }
                 }
             }
             if ($flag == 0) {
                 $result = false;
             }
         }
         return $result;
     }
     if (!$product->getData($this->getAttribute()) && ('!=' == $op || '>' == $op || '<' == $op || '!{}' == $op || '!()' == $op)) {
         return false;
     }
     return parent::validate($product);
 }
    /**
     * Validate Product Rule Condition
     *
     * @param Varien_Object $object
     *
     * @return bool
     */
    public function validate(Varien_Object $object)
    {
        $product = false;
        if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
            $product = $object->getProduct();
        } else {
            $product = Mage::getModel('catalog/product')
                ->load($object->getProductId());
        }

        $product
            ->setQuoteItemQty($object->getQty())
            ->setQuoteItemPrice($object->getPrice()) // possible bug: need to use $object->getBasePrice()
            ->setQuoteItemRowTotal($object->getBaseRowTotal());

        return parent::validate($product);
    }
 /**
  * Validate Product Rule Condition
  *
  * @param Varien_Object $object
  * @return bool
  */
 public function validate(Varien_Object $object)
 {
     $product = Mage::getModel('catalog/product')->load($object->getProductId())->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getRowTotal());
     return parent::validate($product);
 }
示例#24
0
 public function getOptionValues()
 {
     $data = array();
     $optionsArr = '';
     $session = Mage::getSingleton('adminhtml/session');
     if ($data = $session->getData('customoptions_data')) {
         if (isset($data['general']['hash_options'])) {
             $optionsArr = $data['general']['hash_options'];
         }
     } elseif (Mage::registry('customoptions_data')) {
         $data = Mage::registry('customoptions_data')->getData();
         if (isset($data['hash_options'])) {
             $optionsArr = $data['hash_options'];
         }
     }
     $groupId = (int) $this->getRequest()->getParam('group_id');
     if ($optionsArr) {
         $optionsArr = unserialize($optionsArr);
     }
     $storeOptionsArr = array();
     $groupStore = Mage::getSingleton('customoptions/group_store')->loadByGroupAndStore($groupId, $this->getStoreId());
     if ($groupStore->getHashOptions()) {
         $storeOptionsArr = unserialize($groupStore->getHashOptions());
     }
     $product = Mage::getSingleton('catalog/product_option');
     if (!$this->_values && $optionsArr) {
         $values = array();
         $sortOrder = array();
         $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
         $optionItemCount = count($optionsArr);
         foreach ($optionsArr as $optionId => $option) {
             $option = new Varien_Object($option);
             $value = array();
             if ($option->getIsDelete() != '1') {
                 $value['id'] = $option->getOptionId();
                 $value['item_count'] = $optionItemCount;
                 $value['option_id'] = $option->getOptionId();
                 $value['title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['title']) ? $storeOptionsArr[$optionId]['title'] : $option->getTitle());
                 $value['type'] = $option->getType();
                 $value['is_require'] = $option->getIsRequire();
                 $value['is_enabled'] = $option->getIsEnabled();
                 $value['is_dependent'] = $option->getIsDependent();
                 $value['code'] = $this->htmlEscape($option->getCode());
                 $value['option_code'] = $option->getOptionCode();
                 $value['customoptions_is_onetime'] = $option->getCustomoptionsIsOnetime();
                 $value['qnty_input'] = $option->getQntyInput() ? 'checked' : '';
                 $value['qnty_input_disabled'] = $option->getType() == 'drop_down' || $option->getType() == 'radio' || $option->getType() == 'checkbox' ? '' : 'disabled';
                 $value['description'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['description']) ? $storeOptionsArr[$optionId]['description'] : $option->getDescription());
                 $value['block_title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['block_title']) ? $storeOptionsArr[$optionId]['block_title'] : $option->getBlockTitle());
                 if (Mage::helper('customoptions')->isCustomerGroupsEnabled() && $option->getCustomerGroups() != null) {
                     $value['customer_groups'] = implode(',', $option->getCustomerGroups());
                 }
                 $value['in_group_id'] = $option->getInGroupId();
                 $value['in_group_id_view'] = $option->getInGroupId();
                 $value['sort_order'] = $this->_getSortOrder($option);
                 if ($this->getStoreId() != '0') {
                     $value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['title']));
                     $value['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['title']) ? 'disabled' : null;
                     $value['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['description']));
                     $value['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['description']) ? 'disabled' : null;
                     $value['checkboxScopeBlockTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'block_title', !isset($storeOptionsArr[$optionId]['block_title']));
                     $value['scopeBlockTitleDisabled'] = !isset($storeOptionsArr[$optionId]['block_title']) ? 'disabled' : null;
                 }
                 if ($product->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $countValues = count($option->getValues());
                     if ($countValues > 0) {
                         foreach ($option->getValues() as $key => $_value) {
                             $_value = new Varien_Object($_value);
                             $_value->setOptionTypeId($key);
                             if ($_value->getIsDelete() != '1') {
                                 $defaultArray = $option->getDefault() !== null ? $option->getDefault() : array();
                                 $value['optionValues'][$key] = array('item_count' => $countValues, 'option_id' => $option->getOptionId(), 'option_type_id' => $_value->getOptionTypeId(), 'title' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title'] : $_value->getTitle()), 'price' => $this->getPriceValue(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'] : $_value->getPrice(), $_value->getPriceType()), 'price_type' => isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type'] : $_value->getPriceType(), 'sku' => $this->htmlEscape($_value->getSku()), 'code' => $this->htmlEscape($_value->getCode()), 'tier' => $_value->getTier(), 'sort_order' => $this->_getSortOrder($_value), 'customoptions_qty' => $_value->getCustomoptionsQty(), 'checked' => array_search($_value->getOptionTypeId(), $defaultArray) !== false ? 'checked' : '', 'default_type' => $option->getType() == 'checkbox' || $option->getType() == 'multiple' ? 'checkbox' : 'radio', 'in_group_id' => $_value->getInGroupId(), 'in_group_id_view' => $_value->getInGroupId(), 'dependent_ids' => $_value->getDependentIds());
                                 $value['optionValues'][$key]['image_button_label'] = Mage::helper('customoptions')->__('Add Image');
                                 $imgHtml = Mage::helper('customoptions')->getImgHtml($_value->getImagePath(), $option->getId(), $_value->getOptionTypeId());
                                 if ($imgHtml) {
                                     $value['optionValues'][$key]['image'] = $imgHtml;
                                     $value['optionValues'][$key]['image_button_label'] = Mage::helper('customoptions')->__('Change Image');
                                 }
                                 if ($this->getStoreId() != '0') {
                                     $value['optionValues'][$key]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']), $_value->getOptionTypeId());
                                     $value['optionValues'][$key]['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? 'disabled' : null;
                                     if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
                                         $value['optionValues'][$key]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($_value->getstorePrice()), $_value->getOptionTypeId());
                                         $value['optionValues'][$key]['scopePriceDisabled'] = is_null($_value->getStorePrice()) ? 'disabled' : null;
                                     }
                                 }
                             }
                         }
                         $value['optionValues'] = array_values($value['optionValues']);
                     }
                 } else {
                     $value['price'] = $this->getPriceValue(isset($storeOptionsArr[$optionId]['price']) ? $storeOptionsArr[$optionId]['price'] : $option->getPrice(), $option->getPriceType());
                     $value['price_type'] = isset($storeOptionsArr[$optionId]['price_type']) ? $storeOptionsArr[$optionId]['price_type'] : $option->getPriceType();
                     $value['sku'] = $this->htmlEscape($option->getSku());
                     $value['code'] = $this->htmlEscape($option->getCode());
                     $value['max_characters'] = $option->getMaxCharacters();
                     $value['file_extension'] = $option->getFileExtension();
                     $value['image_size_x'] = $option->getImageSizeX();
                     $value['image_size_y'] = $option->getImageSizeY();
                     $value['image_button_label'] = Mage::helper('customoptions')->__('Add Image');
                     $imgHtml = Mage::helper('customoptions')->getImgHtml($option->getImagePath(), $option->getId());
                     if ($imgHtml) {
                         $value['image'] = $imgHtml;
                         $value['image_button_label'] = Mage::helper('customoptions')->__('Change Image');
                     }
                     if ($this->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
                         $value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($option->getStorePrice()));
                         $value['scopePriceDisabled'] = is_null($option->getStorePrice()) ? 'disabled' : null;
                     }
                 }
                 $values[] = new Varien_Object($value);
             }
         }
         $this->_values = $values;
     }
     return $this->_values ? $this->_values : array();
 }