Generate sitemap not working - codeigniter

I need to generate sitemap and display in my view.But am getting this error:-
error on line 1 at column 2: StartTag: invalid element name
Controller:-
class Sitemap extends CI_Controller {
public function index()
{
$this->load->view('sitemap/sitemap.html');
}
}
View:-
<?php header('Content-type: text/xml'); ?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.domain.com /</loc>
<lastmod>2008-01-01</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
<changefreq>weekly</changefreq>
</url>
</urlset>

Try like this : Sitemap generation with Codeigniter
contoroller:
Class Sitemap extends CI_Controller {
function index()
{
$data = "";//select urls from DB to Array
header("Content-Type: text/xml;charset=iso-8859-1");
$this->load->view("sitemap",$data);
}
}
view:
<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.domain.com /</loc>
<lastmod>2008-01-01</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
<changefreq>weekly</changefreq>
</url>
</urlset>
add line to config/routes.php :
$route['seo/sitemap\.xml'] = "seo/sitemap";
=> roev's answer

Related

How to extend galley.phtml in Magento2?

I want to add custom code in gallery.phtml in the PDP section on my custom module.
I tried this=>
called default the block in catalog_product_view.xml
<referenceBlock name="product.info.media.image">
<action method="setTemplate">
<argument name="template" xsi:type="string">Ajith_Mymodule::product/view/gallery.phtml</argument>
</action>
</referenceBlock>
loaded gallery.phtml with and without default code, nothing works well for me.
Am I'm trying the correct method or did anybody give me the idea to do this?
This method is working properly
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Product media data template
*
* #var $block \Magento\Catalog\Block\Product\View\Gallery
*/
?>
<?php
$images = $block->getGalleryImages()->getItems();
$mainImage = current(array_filter($images, function ($img) use ($block) {
return $block->isMainImage($img);
}));
if (!empty($images) && empty($mainImage)) {
$mainImage = $block->getGalleryImages()->getFirstItem();
}
$helper = $block->getData('imageHelper');
$mainImageData = $mainImage ?
$mainImage->getData('medium_image_url') :
$helper->getDefaultPlaceholderUrl('image');
?>
<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
<img
alt="main product photo"
class="gallery-placeholder__image"
src="<?= /* #noEscape */ $mainImageData ?>"
/>
</div>
<script type="text/x-magento-init">
{
"[data-gallery-role=gallery-placeholder]": {
"mage/gallery/gallery": {
"mixins":["magnifier/magnify"],
"magnifierOpts": <?= /* #noEscape */ $block->getMagnifier() ?>,
"data": <?= /* #noEscape */ $block->getGalleryImagesJson() ?>,
"options": <?= /* #noEscape */ $block->getGalleryOptions()->getOptionsJson() ?>,
"fullscreen": <?= /* #noEscape */ $block->getGalleryOptions()->getFSOptionsJson() ?>,
"breakpoints": <?= /* #noEscape */ $block->getBreakpoints() ?>
}
}
}
</script>
call this in our custom template
If we take a look:
vendor/magento/module-product-video/Observer/ChangeTemplateObserver.php
We can see that this template will be added via Observer event. So, we need to disable this observer event in our module. And then, try to add our custom template.
Vendor/Module/etc/events.xml
<event name=""catalog_product_gallery_prepare_layout"">
<observer name=""change_template"" disabled=""true""/>
<observer name=""custom_change_template"" instance=""Vendor\Module\Observer\ChangeTemplateObserver"" />
</event>
Vendor/Module/Observer/ChangeTemplateObserver.php
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class ChangeTemplateObserver implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');
}
}

PHPUNIT Test - Expected Status 200 But Received 500

I keep getting status 500 when 200 is expected. These are the files:
ExampleTest.php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* #return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
</phpunit>
This is the result returned
PHPUnit 7.4.0 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 1.86 seconds, Memory: 20.00MB
There was 1 failure:
1) Tests\Feature\ExampleTest::testBasicTest
Expected status code 200 but received 500.
Failed asserting that false is true.
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:133
/var/www/html/tests/Feature/ExampleTest.php:19
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
This is the Laravel log file
[2018-10-15 20:56:09] testing.ERROR: Call to a member function load() on null (View: /var/www/html/resources/views/app.blade.php) {"exception":"[object] (ErrorException(code: 0): Call to a member function load() on null (View: /var/www/html/resources/views/app.blade.php) at /var/www/html/app/Ezybyz/Configuration/ProvidesScriptVariables.php:46, Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function load() on null at /var/www/html/app/Ezybyz/Configuration/ProvidesScriptVariables.php:46)
app.blade.php
#php
$config = array_merge(
Ezybyz::scriptVariables(), [
// Add key and value here if you want to added to initial state
]
)
#endphp
#extends('layouts.main')
#push('meta')
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<meta name="csrf-token" content="{{ csrf_token() }}">
{{-- Fix for chunk error in Webpack and Vue-Router --}}
<base href="/" />
#endpush
#push('favicon')
<link rel="shortcut icon" href="{{ asset('favicon.ico?v=2') }}" type="image/x-icon" />
#endpush
#push('css')
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
#endpush
#push('header_js')
{{-- EzyByz initial state provider --}}
<script>
window.App = #json($config)
</script>
{{-- Add whitelisted routes for making API calls --}}
#routes
#endpush
#push('title')
<title>{{ config('app.name') }} </title>
#endpush
#section('content')
<div id="app" v-cloak>
<app />
</div>
#endsection
#push('footer_js')
#if(config('echo.realtime'))
{{-- Load socket.io --}}
<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js" defer></script>
#endif
<script src="{{ mix('js/manifest.js') }}" defer></script>
<script src="{{ mix('js/vendor.js') }}" defer></script>
<script src="{{ mix('js/app.js') }}" defer></script>
#endpush
ProvidesScriptVariables.php
<?php
namespace App\Ezybyz\Configuration;
use App\Ezybyz\Ezybyz;
use Illuminate\Support\Facades\Auth;
use App\Ezybyz\Contracts\InitialFrontendState;
trait ProvidesScriptVariables
{
/**
* Get the default JavaScript variables for Spark.
*
* #return array
*/
public static function scriptVariables()
{
return [
'csrfToken' => csrf_token(),
'env' => config('app.env'),
'api_endpoint' => config('ezybyz.app.api'),
'sponsor' => self::getSponsor(),
];
}
protected static function getState()
{
return Ezybyz::call(InitialFrontendState::class . '#forUser', [Auth::user()]);
}
protected static function getSponsor()
{
if ($link = request()->referrallink) {
$user = Ezybyz::user()->find($link->user_id);
return [
'user_id' => $user->id,
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email,
'profile' => $user->profile,
];
}
// We Will Return a Default Sponsor
else {
$user = Ezybyz::user()->first()->load('profile');
return [
'user_id' => $user->id,
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email,
'profile' => $user->profile,
];
}
}
}
Any help is greatly appreciated.
Try to use RefreshDatabase trait in the test class:
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
add $this->withoutExceptionHandling(); before $response = $this->get('/'); to get more information about the error.
One possible cause of this error message is, you don't have the openssl
php
extension enabled.
just edit your class to return true
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* #return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}
then run test in your command
vendor/bin/phpunit
Do check with your routes. Check if you have provided 'name' to your base route.
eg:
In routes/web.php, Do the following:
Route::get('home','BlogController#home')->name('home');
Now go to the test case and do replace the following code:
$response = $this->get('home');
Let me know if it works for you.

error in codeigniter Message: Call to a member function row() on a non-object

I have been working on a CodeIgniter project and when I send the data to the view called - merchant_registration as an array
controller
function Merchant_Registration($para1 = '', $para2 = '') {
if (!$this->crud_model->admin_permission('report')) {
redirect(base_url() . 'index.php/admin');
}
if ($para1 == 'edit') {
$page_data['vendor_data'] = $this->db->get_where('vendor', array(
'vendor_id' => $para2
))->result_array();
$this->load->view('back/admin/merchant_edit', $page_data);
} elseif ($para1 == 'update') {
$page_data['status'] = $this->input->post('status');
$this->db->where('vendor_id', $para2);
$this->db->update('vendor', $page_data);
redirect(base_url() . 'index.php/admin/Merchant_Registration/', 'refresh');
recache();
} else {
$this->db->order_by('vendor_id', 'ased');
$create_timestamp = $this->input->post("create_timestamp");
$status = $this->input->post("status");
//search query
//change the dates to the proper column
//and find the package column and
//$date = DateTime::createFromFormat('Y-m-d"', $create_timestamp);
$page_data['query'] = $this->db->query("select * from vendor where create_timestamp >= UNIX_TIMESTAMP($create_timestamp) and create_timestamp <= UNIX_TIMESTAMP($create_timestamp) or status like '%$status%'")->result_array();
$page_data['page_name'] = "Merchant_Registration";
$this->load->view('back/index', $page_data);
}
}
It shows this error:
Severity: Error
Message: Call to a member function row() on a non-object
Filename: back/index.php
Line Number: 5
Backtrace:
index file
<?php
$system_name = $this->db->get_where('general_settings',array('type' => 'system_name'))->row()->value;
$system_title = $this->db->get_where('general_settings',array('type' => 'system_title'))->row()->value;
?>
<?php include 'includes_top.php'; ?>
<body onbeforeunload="HandleBackFunctionality()">
<div id="container" class="effect mainnav-lg">
<!--NAVBAR-->
<?php include 'header.php'; ?>
<!--END NAVBAR-->
<div class="boxed" id="fol">
<!--CONTENT CONTAINER-->
<div>
<?php
include $this->session->userdata('title').'/'.$page_name.'.php' ?>
</div>
<!--END CONTENT CONTAINER-->
<!--MAIN NAVIGATION-->
<?php include $this->session->userdata('title').'/navigation.php' ?>
<!--END MAIN NAVIGATION-->
</div>
<!-- FOOTER -->
<?php include 'footer.php'; ?>
<?php include 'script_texts.php'; ?>
<!-- END FOOTER -->
<!-- SCROLL TOP BUTTON -->
<button id="scroll-top" class="btn"><i class="fa fa-chevron-up">
</i></button>
</div>
<!-- END OF CONTAINER -->
<!-- SETTINGS - DEMO PURPOSE ONLY -->
<?php include 'includes_bottom.php'; ?>
i figured it out i was using query builder and active record at the same time

Magento - Payment Method for each Product

There is the possibility to choose the form of payment for each product?
For example: In my store one product is selling for "cash in game", so by the time the customer is buying this product magento enable only the payment option "in game".
As for the other products that are bought for real money, it disables the payment option "in game" and enable payment for card credit (for exemplo).
I found some modules, but tested and did not work.
Thank's
yes you can do it by this module. for example we want to cash on delivery for some products ->
First create a product attribute (name : 'magepal_payment_filter_by_product', type : yes/no) to identify these products.
E.g base of Magento v1.7 you could
Auto enable payment module programmatically [see][1]
Enable all applicable payment module and filter which module to show where
In /app/code/local/MagePal/PaymentFilterByProduct/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MagePal_PaymentFilterByProduct>
<version>1.0.1</version>
</MagePal_PaymentFilterByProduct>
</modules>
<global>
<helpers>
<paymentfilterbyproduct>
<class>MagePal_PaymentFilterByProduct_Helper</class>
</paymentfilterbyproduct>
<payment>
<rewrite>
<data>MagePal_PaymentFilterByProduct_Helper_Payment_Data</data>
</rewrite>
</payment>
</helpers>
</global>
</config>
In /app/code/local/MagePal/PaymentFilterByProduct/Helper/Payment/Data.php
<?php
class MagePal_PaymentFilterByProduct_Helper_Payment_Data extends Mage_Payment_Helper_Data
{
public function getStoreMethods($store = null, $quote = null)
{
$methods = parent::getStoreMethods($store, $quote);
if(!Mage::getStoreConfig('paymentfilterbyproduct/general_option/paymentfilterbyproduct_enable', Mage::app()->getStore()) || !$quote){
return $methods;
}
//get a list of product in cart
$cart = Mage::getSingleton('checkout/session');
$specialProductInCart = array();
foreach ($cart->getQuote()->getAllItems() as $item) {
$specialProductInCart[] = $item->getMagepalPaymentFilterByProduct();
}
// if special product in cart
// need to if check $item->getMagepalPaymentFilterByProduct() return 'yes/no' or '0/1)
if(in_array('yes', $specialProductInCart)){
$filter_csv = Mage::getStoreConfig('paymentfilterbyproduct/filter_option/paymentfilter_special_products', Mage::app()->getStore());
}
else{
$filter_csv = Mage::getStoreConfig('paymentfilterbyproduct/filter_option/paymentfilter_all_product', Mage::app()->getStore());
}
$filter_array = explode(",", $filter_csv);
foreach ($methods as $k => $method){
if(!in_array($method->getCode(), $filter_array))
unset($methods[$k]);
}//methods
return $methods;
}
}
In /app/code/local/MagePal/PaymentFilterByProduct/etc/system.xml
<?xml version="1.0"?>
<config>
<tabs>
<magepal translate="label" module="paymentfilterbyproduct">
<label>MagePal</label>
<sort_order>900</sort_order>
</magepal>
</tabs>
<sections>
<paymentfilterbyproduct translate="label" module="paymentfilterbyproduct">
<label>Payment Method Filter by Product</label>
<tab>magepal</tab>
<sort_order>1000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<general_option translate="label">
<label>General Options</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<paymentfilter_enable translate="label">
<label>Enable Payment Filter</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>50</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentfilter_enable>
</fields>
</general_option>
<filter_option translate="label">
<label>Payment Method Filter Configuration</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Please enable all applicable payment methods in system payment config</comment>
<fields>
<paymentfilter_all_products translate="label">
<label>Select Default Payment option for All Products</label>
<frontend_type>multiselect</frontend_type>
<source_model>MagePal_PaymentFilterByProduct_ActivePaymentMethod</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentfilter_admin>
<paymentfilter_special_products translate="label">
<label>Select Payments for Cart with Special Products</label>
<frontend_type>multiselect</frontend_type>
<source_model>MagePal_PaymentFilterByProduct_ActivePaymentMethod</source_model>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentfilter_store>
</fields>
</filter_option>
</groups>
</paymentfilterbyproduct>
</sections>
</config>
In /app/code/local/MagePal/PaymentFilterByProduct/Helper/Data.php
<?php
class MagePal_PaymentFilterByProduct_Helper_Data extends Mage_Core_Block_Template
{
}
In /app/code/local/MagePal/PaymentFilterByProduct/ActivePaymentMethod.php
<?php
class MagePal_PaymentFilterByProduct_ActivePaymentMethod
{
//get all active (enable) payment method
public function toOptionArray()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
foreach ($payments as $paymentCode=>$paymentModel) {
if($paymentModel->canUseCheckout() == 1){
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = array(
'label' => $paymentTitle,
'value' => $paymentCode,
);
}
}
return $methods;
}
}
In /app/etc/modules/MagePal_PaymentFilterByProduct.xml
<?xml version="1.0"?>
<config>
<modules>
<MagePal_PaymentFilterByProduct>
<active>true</active>
<codePool>local</codePool>
</MagePal_PaymentFilterByProduct>
</modules>
</config>

Magento My custom module block not show

I'm using Magento 1.9.2.2 and I'm trying to create a module which show a product list. Bellow my current code which doesn't render the block. I hope someone can put me in the right direction how to fix this.
app/etc/modules/Envato_All.xml
<?xml version="1.0"?>
<config>
<modules>
<Envato_Recentproducts>
<active>true</active>
<codePool>local</codePool>
</Envato_Recentproducts>
</modules>
</config>
app/code/local/Envato/Recentproducts/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Envato_Recentproducts>
<version>1.0</version>
</Envato_Recentproducts>
</modules>
<global>
<blocks>
<recentproducts>
<class>Envato_Recentproducts_Block</class>
</recentproducts>
</blocks>
<models>
<recentproducts>
<class>Envato_Recentproducts_Model</class>
</recentproducts>
</models>
</global>
</config>
app/code/local/Envato/Recentproducts/Model/Recentproducts.php
<?php
class Envato_Recentproducts_Model_Recentproducts extends Mage_Core_Model_Abstract
{
public function getRecentProduct()
{
$products = Mage::getModel("catalog/product")
->getCollection()
->addAttributeToSelect('*')
->setOrder('entity_id', 'DESC')
->setPageSize(5);
return $products;
}
}
app/code/local/Envato/Recentproducts/Block/Recentproducts.php
<?php
class Envato_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template
{
public function getRecentProducts()
{
// call model to fetch data
$arr_products = array();
$products = Mage::getModel("recentproducts/recentproducts")­->getRecentProducts();
foreach ($products as $product) {
$arr_products[] = array(
'id' => $product-­>getId(),
'name' => $product­->getName(),
'url' => $product­->getProductUrl(),
);
}
return $arr_products;
}
}
app/design/frontend/default/default/template/recentproducts/recentproducts.phtml
<?php
$products = $this­->getRecentProducts();
?>
<div id="product_list">
<h1>Recent Products</h1>
<?php if (is_array($products) && count($products)) { ?>
<?php foreach($products as $product) { ?>
<div>
<?php echo $product['name'] ?>
</div>
<?php } ?>
<?php } ?>
</div>
Used block
{{block type="recentproducts/recentproducts" name="recentproducts_recentproducts" template="recentproducts/recentproducts.phtml"}}
Have you tried to add "recentproducts/recentproducts" and set to allow under configuration->permission->Blocks?
don't forget to flush your cache after adding this..
Let me know

Resources