Pregunta

He creado una declaración if que tengo en mi página de envío.Donde si el atributo "entrega directa" es verdadero, mostrará un mensaje de error y no mostrará la entrega gratuita.He puesto la declaración If a continuación.

<?php $quote = Mage::getSingleton('checkout/session')->getQuote();
        $cartItems = $quote->getAllVisibleItems();

        foreach ($cartItems as $item)
        {
            $productId = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($productId);
                   if($product->getData('direct_delivery_product')==1){?>

             <div class="direct_message">
             <?php echo 'You have direct delivery products in your shopping cart. This means it may take longer than the standard 2-5 working days to deliver.';?></div>

                <?php unset($_shippingRateGroups["freeshipping"]);
                 break;
             }

                }

?>

Sin embargo, en la página de mi cesta, donde muestra el total, todavía dice que la entrega es gratuita.Intenté agregar mi declaración IF al archivo de plantilla donde muestra el envío, pero no funcionó.¿Alguien podría decirme cómo puedo hacer que muestre la tarifa de envío estándar en lugar del envío gratuito?Si el atributo es verdadero.Este es mi archivo de plantilla que muestra la entrega en la página de la cesta.

<?php if ($this->displayBoth()):?>
<tr>
    <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
        <?php echo $this->getExcludeTaxLabel() ?>
    </td>
    <td style="<?php echo $this->getStyle() ?>" class="a-right">
        <?php echo $this->helper('checkout')->formatPrice($this->getShippingExcludeTax()) ?>
    </td>
</tr>

<tr>
    <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
        <?php echo $this->getIncludeTaxLabel() ?>
    </td>
    <td style="<?php echo $this->getStyle() ?>" class="a-right">
        <?php echo $this->helper('checkout')->formatPrice($this->getShippingIncludeTax()) ?>
    </td>
</tr>


<?php elseif($this->displayIncludeTax()) : ?>
<tr>
    <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
        <?php echo $this->getTotal()->getTitle() ?>
    </td>
    <td style="<?php echo $this->getStyle() ?>" class="a-right">
        <?php echo $this->helper('checkout')->formatPrice($this->getShippingIncludeTax()) ?>
    </td>
</tr>
<?php else:?>


<tr>

    <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
        <?php echo $this->escapeHtml($this->getTotal()->getTitle()) ?>
    </td>
    <td style="<?php echo $this->getStyle() ?>" class="a-right">
        <?php echo $this->helper('checkout')->formatPrice($this->getShippingExcludeTax()) ?>
    </td>
</tr>
<?php endif;?>
¿Fue útil?

Solución

Puedes reescribir el modelo de transportista de envío gratuito. Mage_Shipping_Model_Carrier_Freeshipping y agrega este método dentro de tu nueva clase

public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
{
    $items = $request->getAllVisibleItems();
    foreach ($items as $item) { 
        if ($items->getProduct()->getData('direct_delivery_product')) {
             return false;
        }
    }
}

esto debería desactivar el método de envío gratuito cuando un producto con direct_delivery_product configurado en sí está en su carrito.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top